nils-api-testing-core 1.21.9

Library crate for nils-api-testing-core in the nils-cli workspace.
Documentation
use crate::report::{ReportBuilder, ReportHeader};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WebsocketReportAssertion {
    pub label: String,
    pub state: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WebsocketReport {
    pub report_date: String,
    pub case_name: String,
    pub generated_at: String,
    pub endpoint_note: String,
    pub result_note: String,
    pub command_snippet: Option<String>,
    pub assertions: Vec<WebsocketReportAssertion>,
    pub request_json: String,
    pub transcript_json: String,
    pub stderr_note: Option<String>,
}

pub fn render_websocket_report_markdown(report: &WebsocketReport) -> String {
    let header = ReportHeader {
        report_date: &report.report_date,
        case_name: &report.case_name,
        generated_at: &report.generated_at,
        endpoint_note: &report.endpoint_note,
        result_note: &report.result_note,
        command_snippet: report.command_snippet.as_deref(),
    };

    let mut builder = ReportBuilder::new(header);

    if !report.assertions.is_empty() {
        builder.push_section_heading("Assertions");
        for a in &report.assertions {
            builder.push_list_item(&format!("{} ({})", a.label, a.state));
        }
        builder.push_blank_line();
    }

    builder.push_code_section(
        "WebSocket Request",
        "json",
        &report.request_json,
        None,
        true,
    );
    builder.push_code_section("Transcript", "json", &report.transcript_json, None, true);

    if let Some(stderr_note) = &report.stderr_note
        && !stderr_note.is_empty()
    {
        builder.push_code_section("stderr", "text", stderr_note, None, false);
    }

    builder.finish()
}