"""HTTP-level tests for `/api/day-assertions` — restructure step 3b. Replaces `TestPlannedDayExclusionRouter` (deleted along with the router it tested). The create/list round trip and the foreign-workspace/foreign-child rejections carry over; the delete shape changes from "by id" to "by natural key" (see `app.routers.day_assertion.clear_day_assertion`'s docstring for why), so this file's round-trip test clears by key instead of by id. """ from datetime import date from uuid import uuid4 from httpx import AsyncClient from tests.conftest import SeededIds _DAY = date(2027, 2, 3) class TestDayAssertionRouter: async def test_create_list_clear_round_trip( self, authed_client: AsyncClient, seeded_ids: SeededIds ) -> None: payload = { "workspace_id": str(seeded_ids.workspace_id), "child_id": str(seeded_ids.child_id), "parent_personal_data_uuid": str(seeded_ids.personal_data_uuid), "date": _DAY.isoformat(), "day_type": "vacation", } created = await authed_client.post("/api/day-assertions", json=payload) assert created.status_code == 201, created.text body = created.json() assert body["date"] == _DAY.isoformat() assert body["day_type"] == "vacation" listed = await authed_client.get(f"/api/day-assertions/workspace/{seeded_ids.workspace_id}") assert listed.status_code == 200 assert [r["id"] for r in listed.json()] == [body["id"]] clear_params = { "workspace_id": str(seeded_ids.workspace_id), "child_id": str(seeded_ids.child_id), "parent_personal_data_uuid": str(seeded_ids.personal_data_uuid), "date": _DAY.isoformat(), } cleared = await authed_client.request("DELETE", "/api/day-assertions", params=clear_params) assert cleared.status_code == 204 after = await authed_client.get(f"/api/day-assertions/workspace/{seeded_ids.workspace_id}") assert after.json() == [] # Idempotent — clearing an already-empty slot is a no-op, never 404. again = await authed_client.request("DELETE", "/api/day-assertions", params=clear_params) assert again.status_code == 204 async def test_exclusion_shaped_assertion_is_accepted( self, authed_client: AsyncClient, seeded_ids: SeededIds ) -> None: response = await authed_client.post( "/api/day-assertions", json={ "workspace_id": str(seeded_ids.workspace_id), "child_id": str(seeded_ids.child_id), "parent_personal_data_uuid": str(seeded_ids.personal_data_uuid), "date": _DAY.isoformat(), "day_type": "none", }, ) assert response.status_code == 201, response.text assert response.json()["day_type"] == "none" async def test_invalid_day_type_is_rejected( self, authed_client: AsyncClient, seeded_ids: SeededIds ) -> None: response = await authed_client.post( "/api/day-assertions", json={ "workspace_id": str(seeded_ids.workspace_id), "child_id": str(seeded_ids.child_id), "parent_personal_data_uuid": str(seeded_ids.personal_data_uuid), "date": _DAY.isoformat(), "day_type": "not-a-real-type", }, ) assert response.status_code == 422 async def test_a_foreign_workspace_create_is_rejected( self, authed_client: AsyncClient, seeded_ids: SeededIds ) -> None: response = await authed_client.post( "/api/day-assertions", json={ "workspace_id": str(uuid4()), "child_id": str(seeded_ids.child_id), "parent_personal_data_uuid": str(seeded_ids.personal_data_uuid), "date": _DAY.isoformat(), "day_type": "vacation", }, ) assert response.status_code == 404 async def test_a_foreign_child_create_is_rejected( self, authed_client: AsyncClient, seeded_ids: SeededIds ) -> None: response = await authed_client.post( "/api/day-assertions", json={ "workspace_id": str(seeded_ids.workspace_id), "child_id": str(uuid4()), "parent_personal_data_uuid": str(seeded_ids.personal_data_uuid), "date": _DAY.isoformat(), "day_type": "vacation", }, ) assert response.status_code == 404 async def test_a_foreign_list_is_rejected(self, authed_client: AsyncClient) -> None: response = await authed_client.get(f"/api/day-assertions/workspace/{uuid4()}") assert response.status_code == 404 async def test_a_foreign_workspace_clear_is_rejected( self, authed_client: AsyncClient, seeded_ids: SeededIds ) -> None: response = await authed_client.request( "DELETE", "/api/day-assertions", params={ "workspace_id": str(uuid4()), "child_id": str(seeded_ids.child_id), "parent_personal_data_uuid": str(seeded_ids.personal_data_uuid), "date": _DAY.isoformat(), }, ) assert response.status_code == 404