import json
import os
from pathlib import Path


def test_generate_report_with_care_report_preset(client):
    response = client.post(
        "/api/reports/generate-report",
        json={"layout_config": json.dumps(["care_report"])},
    )
    assert response.status_code == 200
    body = response.json()
    assert "public_url" in body
    assert body["public_url"].endswith(".html")

    report_id = body["public_url"].rsplit("/", 1)[-1]
    output_dir = Path(os.environ["REPORTS_OUTPUT_DIR"])
    assert (output_dir / report_id).exists()
    content = (output_dir / report_id).read_text()
    assert "Care Report" in content
    assert "Customer Overview" in content
    assert "Claim Review Summary" in content
    assert "<table" in content
