//! Integration tests for `mcptest badge`.

use std::io::Write;

use assert_cmd::Command;
use predicates::prelude::*;

fn mcptest() -> Command {
    Command::cargo_bin("mcptest").expect("binary builds")
}

#[test]
fn badge_from_score_emits_shields_json() {
    mcptest()
        .arg("badge")
        .arg("--score")
        .arg("92")
        .arg("--label")
        .arg("mcptest")
        .assert()
        .success()
        .stdout(predicate::str::contains("\"schemaVersion\": 1"))
        .stdout(predicate::str::contains("\"message\": \"92/100\""))
        .stdout(predicate::str::contains("\"color\": \"brightgreen\""));
}

#[test]
fn badge_svg_is_self_contained() {
    mcptest()
        .arg("badge")
        .arg("--score")
        .arg("55")
        .arg("--format")
        .arg("svg")
        .assert()
        .success()
        .stdout(predicate::str::starts_with("<svg"))
        .stdout(predicate::str::contains("55/100"));
}

#[test]
fn badge_reads_numeric_score_from_a_report() {
    let mut f = tempfile::Builder::new()
        .suffix(".json")
        .tempfile()
        .expect("temp file");
    f.write_all(br#"{"numeric_score": 84.0, "grade": "B"}"#)
        .expect("write");
    mcptest()
        .arg("badge")
        .arg(f.path())
        .assert()
        .success()
        .stdout(predicate::str::contains("\"message\": \"84/100\""))
        .stdout(predicate::str::contains("\"color\": \"green\""));
}
