"""API endpoint tests.""" class TestCrowdAPI: """Test crowd data endpoints.""" def test_crowd_summary(self, auth_client): resp = auth_client.get("/api/crowd/summary") assert resp.status_code == 200 data = resp.get_json() assert "total_current" in data assert "overall_occupancy" in data assert "zones" in data def test_crowd_heatmap(self, auth_client): resp = auth_client.get("/api/crowd/heatmap") assert resp.status_code == 200 data = resp.get_json() assert "heatmap_points" in data def test_crowd_zone(self, auth_client): resp = auth_client.get("/api/crowd/zone/north_stand") assert resp.status_code == 200 data = resp.get_json() assert "zone" in data def test_crowd_zone_not_found(self, auth_client): resp = auth_client.get("/api/crowd/zone/nonexistent") assert resp.status_code == 404 def test_crowd_recommend(self, auth_client): resp = auth_client.get("/api/crowd/recommend") assert resp.status_code == 200 class TestQueueAPI: """Test queue endpoints.""" def test_queue_summary(self, auth_client): resp = auth_client.get("/api/queue/summary") assert resp.status_code == 200 data = resp.get_json() assert "total_stations" in data def test_queue_stations(self, auth_client): resp = auth_client.get("/api/queue/stations") assert resp.status_code == 200 data = resp.get_json() assert isinstance(data, list) def test_queue_stations_by_category(self, auth_client): resp = auth_client.get("/api/queue/stations?category=food") assert resp.status_code == 200 data = resp.get_json() assert all(s["category"] == "food" for s in data) def test_queue_shortest(self, auth_client): resp = auth_client.get("/api/queue/shortest") assert resp.status_code == 200 def test_queue_join(self, auth_client): resp = auth_client.post( "/api/queue/join", json={"station_id": "f_n1"}, ) assert resp.status_code == 200 data = resp.get_json() assert "id" in data def test_queue_join_no_auth(self, client): resp = client.post("/api/queue/join", json={"station_id": "f_n1"}) assert resp.status_code == 401 def test_queue_tickets(self, auth_client): auth_client.post("/api/queue/join", json={"station_id": "f_n1"}) resp = auth_client.get("/api/queue/tickets") assert resp.status_code == 200 data = resp.get_json() assert isinstance(data, list) class TestNavigationAPI: """Test navigation endpoints.""" def test_navigate_route(self, auth_client): resp = auth_client.get("/api/navigate/route?from=gate_1&to=food_north") assert resp.status_code == 200 data = resp.get_json() assert "from" in data assert "to" in data assert "estimated_time_display" in data def test_navigate_nearest(self, auth_client): resp = auth_client.get("/api/navigate/nearest?from=gate_1&type=food_court") assert resp.status_code == 200 data = resp.get_json() assert "target_zone" in data def test_navigate_pois(self, auth_client): resp = auth_client.get("/api/navigate/pois") assert resp.status_code == 200 data = resp.get_json() assert isinstance(data, list) assert len(data) > 0 def test_navigate_missing_params(self, auth_client): resp = auth_client.get("/api/navigate/route") assert resp.status_code == 400 class TestChatAPI: """Test chatbot endpoints.""" def test_chat_message(self, auth_client): resp = auth_client.post( "/api/chat", json={"message": "Where is the food?"}, ) assert resp.status_code == 200 data = resp.get_json() assert "response" in data assert len(data["response"]) > 0 def test_chat_suggestions(self, auth_client): resp = auth_client.get("/api/chat/suggestions") assert resp.status_code == 200 data = resp.get_json() assert isinstance(data, list) def test_chat_no_auth(self, client): resp = client.post("/api/chat", json={"message": "Hello"}) assert resp.status_code == 401 def test_chat_empty_message(self, auth_client): resp = auth_client.post("/api/chat", json={"message": ""}) assert resp.status_code == 400 def test_chat_long_message(self, auth_client): resp = auth_client.post("/api/chat", json={"message": "x" * 501}) assert resp.status_code == 400 class TestNotificationAPI: """Test notification endpoints.""" def test_get_notifications(self, auth_client): resp = auth_client.get("/api/notifications") assert resp.status_code == 200 def test_unread_count(self, auth_client): resp = auth_client.get("/api/notifications/unread") assert resp.status_code == 200 data = resp.get_json() assert "count" in data class TestSimulatorAPI: """Test simulator control endpoints.""" def test_simulator_status(self, auth_client): resp = auth_client.get("/api/simulator/status") assert resp.status_code == 200 data = resp.get_json() assert "running" in data assert "phase" in data def test_simulator_start_requires_operator(self, auth_client): resp = auth_client.post("/api/simulator/start") assert resp.status_code == 403 def test_simulator_start_as_operator(self, operator_client): resp = operator_client.post("/api/simulator/start") assert resp.status_code == 200 def test_simulator_stop_as_operator(self, operator_client): resp = operator_client.post("/api/simulator/stop") assert resp.status_code == 200 def test_simulator_set_phase(self, operator_client): resp = operator_client.post( "/api/simulator/phase", json={"phase": "halftime"}, ) assert resp.status_code == 200 def test_simulator_set_speed(self, operator_client): resp = operator_client.post( "/api/simulator/speed", json={"speed": 2.0}, ) assert resp.status_code == 200 class TestEventVenueAPI: """Test event and venue info endpoints.""" def test_event_info(self, auth_client): resp = auth_client.get("/api/event") assert resp.status_code == 200 data = resp.get_json() assert "name" in data assert "sport" in data def test_venue_info(self, auth_client): resp = auth_client.get("/api/venue") assert resp.status_code == 200 data = resp.get_json() assert "name" in data assert "zones" in data class TestTranslationAPI: """Test translation endpoints.""" def test_languages_list(self, auth_client): resp = auth_client.get("/api/languages") assert resp.status_code == 200 data = resp.get_json() assert "en" in data def test_translate_text(self, auth_client): resp = auth_client.post( "/api/translate", json={"text": "Hello", "target_lang": "hi"}, ) assert resp.status_code == 200 data = resp.get_json() assert "translated" in data