@@ -51,6 +51,29 @@ defmodule Dotcom.SystemStatusTest do
5151
5252 assert non_normal_status == currently_active_alert . effect
5353 end
54+
55+ test "returns status without alerts beginning later that day unless they are single-tracking" do
56+ route_id_with_alerts = Dotcom.Routes . subway_route_ids ( ) |> Faker.Util . pick ( )
57+ line = Dotcom.Routes . line_name_for_subway_route ( route_id_with_alerts )
58+ { day_start , day_end } = service_range_day ( )
59+ later_start = Timex . shift ( day_start , hours: 5 )
60+ currently_active_alert = disruption_alert ( { day_start , day_end } , route_id_with_alerts )
61+ later_alert = disruption_alert ( { later_start , day_end } , route_id_with_alerts )
62+ single_tracking_alert = disruption_alert ( { later_start , day_end } , route_id_with_alerts , :single_tracking )
63+
64+ expect ( Alerts.Repo.Mock , :by_route_types , fn [ 0 , 1 ] , _date ->
65+ [ currently_active_alert , later_alert , single_tracking_alert ]
66+ end )
67+
68+ assert % { ^ line => statuses } = subway_status ( )
69+
70+ assert % { alerts: [ ^ currently_active_alert , ^ single_tracking_alert ] , status: non_normal_status } =
71+ Enum . find_value ( statuses , fn % { status_entries: status_entries } ->
72+ Enum . find ( status_entries , & ( & 1 . status != :normal ) )
73+ end )
74+
75+ assert non_normal_status == currently_active_alert . effect
76+ end
5477 end
5578
5679 describe "active_now_or_later_on_day?/2" do
@@ -201,4 +224,16 @@ defmodule Dotcom.SystemStatusTest do
201224 severity: random_severity
202225 )
203226 end
227+
228+ defp disruption_alert ( active_period , route_id , cause ) do
229+ { random_effect , random_severity } = service_impacting_effects ( ) |> Faker.Util . pick ( )
230+
231+ build ( :alert_for_route ,
232+ route_id: route_id ,
233+ active_period: [ active_period ] ,
234+ effect: random_effect ,
235+ severity: random_severity ,
236+ cause: cause
237+ )
238+ end
204239end
0 commit comments