Skip to main content

api_testing_core/websocket/
report.rs

1use crate::report::{ReportBuilder, ReportHeader};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct WebsocketReportAssertion {
5    pub label: String,
6    pub state: String,
7}
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct WebsocketReport {
11    pub report_date: String,
12    pub case_name: String,
13    pub generated_at: String,
14    pub endpoint_note: String,
15    pub result_note: String,
16    pub command_snippet: Option<String>,
17    pub assertions: Vec<WebsocketReportAssertion>,
18    pub request_json: String,
19    pub transcript_json: String,
20    pub stderr_note: Option<String>,
21}
22
23pub fn render_websocket_report_markdown(report: &WebsocketReport) -> String {
24    let header = ReportHeader {
25        report_date: &report.report_date,
26        case_name: &report.case_name,
27        generated_at: &report.generated_at,
28        endpoint_note: &report.endpoint_note,
29        result_note: &report.result_note,
30        command_snippet: report.command_snippet.as_deref(),
31    };
32
33    let mut builder = ReportBuilder::new(header);
34
35    if !report.assertions.is_empty() {
36        builder.push_section_heading("Assertions");
37        for a in &report.assertions {
38            builder.push_list_item(&format!("{} ({})", a.label, a.state));
39        }
40        builder.push_blank_line();
41    }
42
43    builder.push_code_section(
44        "WebSocket Request",
45        "json",
46        &report.request_json,
47        None,
48        true,
49    );
50    builder.push_code_section("Transcript", "json", &report.transcript_json, None, true);
51
52    if let Some(stderr_note) = &report.stderr_note
53        && !stderr_note.is_empty()
54    {
55        builder.push_code_section("stderr", "text", stderr_note, None, false);
56    }
57
58    builder.finish()
59}