"""The fallback JSON in the frontend IS the contract. If an endpoint stops
matching it, a page silently changes shape. Assert on keys, not values."""
import json
import pathlib

from fastapi.testclient import TestClient

from app.main import app

client = TestClient(app)
FIXTURES = pathlib.Path(__file__).resolve().parents[2] / "frontend" / "src" / "lib" / "content"


def test_care_services_shape_matches_frontend_fallback():
    expected_keys = set(json.loads((FIXTURES / "services.json").read_text())[0])
    actual = client.get("/api/care-services").json()
    assert actual, "expected at least one published care service"
    assert expected_keys.issubset(actual[0].keys())


def test_contact_submission_rejects_bad_email():
    r = client.post("/api/contact-submissions", json={
        "firstName": "Test", "lastName": "User",
        "email": "not-an-email", "message": "hello",
    })
    assert r.status_code == 422


def test_healthz():
    r = client.get("/api/healthz")
    assert r.status_code == 200
    assert r.json()["status"] in ("ok", "degraded")
