Skip to content

Commit a12f2bd

Browse files
committed
Only show later-today delays if they are single tracking
1 parent 58f1640 commit a12f2bd

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/dotcom/system_status.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Dotcom.SystemStatus do
55
or whether there are alerts that impact service.
66
"""
77

8-
import Dotcom.Alerts, only: [service_impacting_alert?: 1]
8+
import Dotcom.Alerts, only: [in_effect_now?: 1, service_impacting_alert?: 1]
99

1010
alias Dotcom.SystemStatus
1111

@@ -19,13 +19,18 @@ defmodule Dotcom.SystemStatus do
1919
def subway_status() do
2020
@alerts_repo.by_route_types([0, 1], @date_time_module.now())
2121
|> Enum.filter(&status_alert?(&1, @date_time_module.now()))
22+
|> Enum.filter(&active_now_or_single_tracking?(&1))
2223
|> SystemStatus.Subway.subway_status(@date_time_module.now())
2324
end
2425

2526
def status_alert?(alert, datetime) do
2627
service_impacting_alert?(alert) and active_now_or_later_on_day?(alert, datetime)
2728
end
2829

30+
defp active_now_or_single_tracking?(alert) do
31+
alert.cause == :single_tracking or in_effect_now?(alert)
32+
end
33+
2934
@doc """
3035
Returns `true` if the alert is active at some point during the day
3136
given, unless the alert's end time is before the time given.

test/dotcom/system_status_test.exs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
204239
end

0 commit comments

Comments
 (0)