| from fastapi.testclient import TestClient | |
| from app import app | |
| client = TestClient(app) | |
| def test_health() -> None: | |
| response = client.get("/health") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["ok"] is True | |
| assert "generator_model" in data | |
| def test_chat_general() -> None: | |
| response = client.post("/chat", json={"message": "What can you do in this game?"}) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "reply" in data | |
| assert "meta" in data | |
| def test_logging_roundtrip() -> None: | |
| start = client.post("/log/session/start", json={"participant_id": "test_user"}) | |
| assert start.status_code == 200 | |
| session_id = start.json()["session_id"] | |
| event = client.post( | |
| "/log/event", | |
| json={ | |
| "participant_id": "test_user", | |
| "session_id": session_id, | |
| "event_type": "AIAppOpened", | |
| "payload": {"questionIndex": 1}, | |
| }, | |
| ) | |
| assert event.status_code == 200 | |
| research = client.get(f"/research/session/{session_id}") | |
| assert research.status_code == 200 | |
| data = research.json() | |
| assert data["ok"] is True | |
| assert data["session"]["session_id"] == session_id | |
| assert len(data["events"]) >= 1 | |