use crate::{helpers::spawn_http_server, support::TestWorkspace};

#[test]
fn run_outputs_verbose_text_with_timing_breakdown() {
    let server_url = spawn_http_server(
        200,
        "OK",
        "application/json",
        r#"{"ok":true,"service":"hen"}"#,
    )
    .replacen("127.0.0.1", "localhost", 1);
    let workspace = TestWorkspace::new();
    workspace.write_file(
        "collection.hen",
        &format!(
            r#"Verbose Timing Fixture

Exercises verbose timing output.

---

Fetch fixture

GET {server_url}

^ & body.ok == true
"#
        ),
    );

    let output = workspace.run_hen(["run", "collection.hen", "--verbose"]);

    assert_eq!(output.status_code, 0, "stderr: {}", output.stderr);
    assert!(output.stderr.is_empty(), "stderr: {}", output.stderr);
    assert!(output.stdout.contains("timing: dns "));
    assert!(output.stdout.contains("responseStart "));
    assert!(output.stdout.contains("bodyRead "));
    assert!(output.stdout.contains("Body:"));
}