Skip to content

Commit 470f38d

Browse files
committed
Implement test_queue_orders_breached_then_due_soon_then_priority_then_age() function
1 parent 7fb20b0 commit 470f38d

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

tests/test_queue_api.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# path: policylens/tests/test_queue_api.py
2+
"""
3+
Integration tests for queue API ordering and filters.
4+
"""
5+
6+
from __future__ import annotations
7+
8+
from datetime import timedelta
9+
10+
import pytest
11+
from django.contrib.auth import get_user_model
12+
from django.utils import timezone
13+
from django.urls import reverse
14+
15+
from policylens.apps.claims.models import Claim, SlaClock
16+
from tests.factories import PolicyFactory
17+
18+
User = get_user_model()
19+
20+
21+
@pytest.mark.django_db
22+
def test_queue_orders_breached_then_due_soon_then_priority_then_age(api_client):
23+
"""Queue ordering should be deterministic and operationally meaningful."""
24+
user = User.objects.create_user(username="queue_user", password="password123")
25+
api_client.force_authenticate(user=user)
26+
27+
policy = PolicyFactory()
28+
29+
# Old low priority but breached
30+
breached_claim = Claim.objects.create(
31+
policy=policy,
32+
claim_type=Claim.Type.CLAIM,
33+
priority=Claim.Priority.LOW,
34+
summary="Breached",
35+
created_by="seed",
36+
status=Claim.Status.NEW,
37+
)
38+
SlaClock.objects.create(
39+
claim=breached_claim,
40+
started_at=breached_claim.created_at,
41+
due_at=timezone.now() - timedelta(hours=1),
42+
)
43+
44+
# Due soon high priority
45+
due_soon_claim = Claim.objects.create(
46+
policy=policy,
47+
claim_type=Claim.Type.CLAIM,
48+
priority=Claim.Priority.HIGH,
49+
summary="Due soon",
50+
created_by="seed",
51+
status=Claim.Status.NEW,
52+
)
53+
SlaClock.objects.create(
54+
claim=due_soon_claim,
55+
started_at=due_soon_claim.created_at,
56+
due_at=timezone.now() + timedelta(hours=2),
57+
)
58+
59+
# Not due soon, high priority, older
60+
normal_old_high = Claim.objects.create(
61+
policy=policy,
62+
claim_type=Claim.Type.CLAIM,
63+
priority=Claim.Priority.HIGH,
64+
summary="Normal older high",
65+
created_by="seed",
66+
status=Claim.Status.NEW,
67+
)
68+
SlaClock.objects.create(
69+
claim=normal_old_high,
70+
started_at=normal_old_high.created_at,
71+
due_at=timezone.now() + timedelta(days=2),
72+
)
73+
74+
# Not due soon, normal priority, oldest
75+
normal_old_normal = Claim.objects.create(
76+
policy=policy,
77+
claim_type=Claim.Type.CLAIM,
78+
priority=Claim.Priority.NORMAL,
79+
summary="Normal older normal",
80+
created_by="seed",
81+
status=Claim.Status.NEW,
82+
)
83+
SlaClock.objects.create(
84+
claim=normal_old_normal,
85+
started_at=normal_old_normal.created_at,
86+
due_at=timezone.now() + timedelta(days=2),
87+
)
88+
89+
url = reverse("queue-claims")
90+
resp = api_client.get(url)
91+
assert resp.status_code == 200
92+
ids = [item["id"] for item in resp.json()]
93+
94+
assert ids[0] == breached_claim.id
95+
assert ids[1] == due_soon_claim.id
96+
assert ids.index(normal_old_high.id) < ids.index(normal_old_normal.id)

0 commit comments

Comments
 (0)