fix: suppress critical complaint alert once restored_at is set

This commit is contained in:
Atharv1705
2026-11-13 14:42:42 +05:30
parent 594407d404
commit cd9eb27a98
2 changed files with 38 additions and 2 deletions
+32
View File
@@ -553,6 +553,38 @@ def test_sla_breach_alert_emitted_and_suppressed_when_restored(client, db):
.all()
)
assert crit_unrestored == []
# When open > 24h, unrestored complaint triggers critical_complaint alert,
# but restored complaint does NOT trigger it even if not closed yet
past_26h = now - timedelta(hours=26)
c_unrestored.registered_at = past_26h
c_restored.registered_at = past_26h
db.commit()
run_alert_check(db)
db.commit()
crit_unrestored_26h = (
db.query(Notification)
.filter(
Notification.type == "critical_complaint",
Notification.entity_type == "complaint",
Notification.entity_id == cid_unrestored,
)
.all()
)
assert len(crit_unrestored_26h) == 1
assert "Critical Complaint Open > 24h" in crit_unrestored_26h[0].title
crit_restored_26h = (
db.query(Notification)
.filter(
Notification.type == "critical_complaint",
Notification.entity_type == "complaint",
Notification.entity_id == cid_restored,
)
.all()
)
assert crit_restored_26h == []
finally:
db.query(Notification).filter(
Notification.entity_type == "complaint",