from httpx import AsyncClient


async def test_app_error_is_problem_details(client: AsyncClient) -> None:
    resp = await client.get("/_test/boom")
    assert resp.status_code == 418
    assert resp.headers["content-type"].startswith("application/problem+json")
    body = resp.json()
    assert body["status"] == 418
    assert body["title"] == "Teapot"
    assert body["detail"] == "Je suis une théière"


async def test_validation_error_is_problem_details(client: AsyncClient) -> None:
    resp = await client.get("/_test/echo", params={"n": "abc"})
    assert resp.status_code == 422
    assert resp.headers["content-type"].startswith("application/problem+json")
    assert resp.json()["title"] == "Validation error"


async def test_unknown_route_is_problem_details(client: AsyncClient) -> None:
    resp = await client.get("/nope")
    assert resp.status_code == 404
    assert resp.headers["content-type"].startswith("application/problem+json")
