@@ -1340,13 +1340,31 @@ def test_inactive_appeal_does_not_trigger_emergency_appeal_stage(self):
13401340 AppealFactory .create (
13411341 event = event ,
13421342 dtype = self .disaster_type ,
1343- status = AppealStatus .CLOSED ,
1343+ status = AppealStatus .ARCHIVED ,
13441344 atype = AppealType .APPEAL ,
13451345 )
13461346
13471347 data = self ._get (event ).data
13481348 self .assertNotEqual (data ["stage" ], EventStage .EMERGENCY_APPEAL )
13491349
1350+ # CLOSED one also considered but ACTIVE takes over
1351+ AppealFactory .create (
1352+ event = event ,
1353+ dtype = self .disaster_type ,
1354+ status = AppealStatus .CLOSED ,
1355+ atype = AppealType .APPEAL ,
1356+ )
1357+ data = self ._get (event ).data
1358+ self .assertEqual (data ["stage" ], EventStage .EMERGENCY_APPEAL )
1359+ self .assertEqual (data ["appeal" ]["status" ], AppealStatus .CLOSED )
1360+
1361+ self ._active_emergency_appeal (event )
1362+ data = self ._get (event ).data
1363+ self .assertEqual (data ["stage" ], EventStage .EMERGENCY_APPEAL )
1364+
1365+ # Active should take priority over closed and archived
1366+ self .assertEqual (data ["appeal" ]["status" ], AppealStatus .ACTIVE )
1367+
13501368 def test_emergency_appeal_takes_priority_over_entire_dref_chain (self ):
13511369 event = EventFactory .create (dtype = self .disaster_type )
13521370 dref = self ._approved_dref (event )
@@ -1466,3 +1484,47 @@ def fallback_to_dref_appeal_for_no_approved_dref(self):
14661484
14671485 self .assertEqual (parse_datetime (data ["first_field_report_created_at" ]), first_fr .created_at )
14681486 self .assertEqual (parse_datetime (data ["latest_field_report_created_at" ]), latest_fr .created_at )
1487+
1488+ def test_field_report_with_timeline_field_reports (self ):
1489+ event = EventFactory .create (dtype = self .disaster_type )
1490+ FieldReportFactory .create_batch (
1491+ 3 ,
1492+ event = event ,
1493+ dtype = self .disaster_type ,
1494+ )
1495+ data = self ._get (event ).data
1496+ self .assertEqual (data ["stage" ], EventStage .FIELD_REPORT , data )
1497+ self .assertIsNotNone (data ["field_report" ], data )
1498+ self .assertEqual (len (data ["timeline_field_reports" ]), 3 )
1499+
1500+ def test_dref_operational_update_with_timeline_ops_updates (self ):
1501+ event = EventFactory .create (dtype = self .disaster_type )
1502+ dref = self ._approved_dref (event )
1503+ DrefOperationalUpdateFactory .create_batch (
1504+ 3 ,
1505+ dref = dref ,
1506+ status = Dref .Status .APPROVED ,
1507+ disaster_type = self .disaster_type ,
1508+ country = self .country ,
1509+ )
1510+ data = self ._get (event ).data
1511+ self .assertEqual (data ["stage" ], EventStage .DREF_OPERATIONAL_UPDATE , data )
1512+
1513+ dref_data = data .get ("dref" )
1514+ self .assertIsNotNone (dref_data , data )
1515+
1516+ self .assertEqual (len (dref_data ["timeline_operational_updates" ]), 3 )
1517+
1518+ # NOTE: if Final report is created, stage should be DREF_FINAL_REPORT and previous operational updates should also show
1519+ DrefFinalReportFactory .create (
1520+ dref = dref ,
1521+ status = Dref .Status .APPROVED ,
1522+ disaster_type = self .disaster_type ,
1523+ country = self .country ,
1524+ )
1525+ data = self ._get (event ).data
1526+ self .assertEqual (data ["stage" ], EventStage .DREF_FINAL_REPORT )
1527+ dref_data = data .get ("dref" )
1528+ self .assertIsNotNone (dref_data )
1529+ self .assertIsNotNone (dref_data ["final_report_details" ])
1530+ self .assertEqual (len (dref_data ["timeline_operational_updates" ]), 3 )
0 commit comments