Coverage for backend/tests/routers/test_dashboard.py: 100%
22 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-22 15:38 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-22 15:38 +0000
1"""
2Test module for API router endpoints covering CRUD operations for JAM entities.
4This module contains comprehensive test classes for the dashboard endpoint"""
6import datetime
7from tests.utils.table_data import DATE_FORMAT
10class TestDashboardRouter:
11 """Test class for the dashboard router endpoints"""
13 def test_success(self, authorised_clients, test_jobs, test_interviews, test_job_application_updates) -> None:
14 """Test get_all_updates endpoint returns unified updates"""
16 response = authorised_clients[0].get("/dashboard")
17 assert response.status_code == 200
19 data = response.json()
20 statistics, needs_chase, all_updates, upcoming_interviews, upcoming_deadlines = (
21 data["statistics"], data["needs_chase"], data["all_updates"], data["upcoming_interviews"], data["upcoming_deadlines"])
22 assert statistics == {"jobs": 17, "job_applications": 13, "job_application_pending": 11, "interviews": 12}
23 assert len(needs_chase) == 5
24 assert len(all_updates) == 10
25 assert len(upcoming_interviews) == 5
26 assert len(upcoming_deadlines) == 1
28 # Update a job
29 job_id = needs_chase[0]["id"]
30 update_json = {"date": datetime.datetime.now().strftime(DATE_FORMAT), "type": "received", "job_id": job_id}
31 response = authorised_clients[0].post("jobapplicationupdates", json=update_json)
32 assert response.status_code == 201
33 needs_chase = authorised_clients[0].get("/dashboard").json()["needs_chase"]
34 assert len(needs_chase) == 4
36 def test_unauthorized(self, client) -> None:
37 """Test that unauthorised requests are rejected"""
39 response = client.get("/dashboard")
40 assert response.status_code == 401