Skip to content

Commit

Permalink
Add test for redundancy logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Dec 6, 2024
1 parent 53e79fb commit 2344e9b
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 3 deletions.
4 changes: 3 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ config :screens,
headway_headsign: "Test"
}
]
}
},
elevator_redundancy_data_path:
Path.join(~w[#{File.cwd!()} test fixtures elevator_redundancy_data.json])

config :screens, ScreensWeb.AuthManager, secret_key: "test key"

Expand Down
8 changes: 6 additions & 2 deletions lib/screens/v2/candidate_generator/elevator/closures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ defmodule Screens.V2.CandidateGenerator.Elevator.Closures do
@stop injected(Stop)

@elevator_redundancy_data :screens
|> :code.priv_dir()
|> Path.join("elevators/elevator_redundancy_data.json")
|> Application.compile_env(
:elevator_redundancy_data_path,
:screens
|> :code.priv_dir()
|> Path.join("elevators/elevator_redundancy_data.json")
)
|> File.read!()
|> Jason.decode!()

Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/elevator_redundancy_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"112": {
"nearby_redundancy?": true
},
"222": {
"nearby_redundancy?": true
},
"333": {
"nearby_redundancy?": false
}
}
117 changes: 117 additions & 0 deletions test/screens/v2/candidate_generator/elevator/closures_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,123 @@ defmodule Screens.V2.CandidateGenerator.Elevator.ClosuresTest do
)
end

test "Filters out alerts at other stations with nearby redundancy", %{
config: config,
header_instance: header_instance,
footer_instance: footer_instance
} do
expect(@facility, :fetch_stop_for_facility, fn
"111" -> {:ok, %Stop{id: "place-test"}}
"112" -> {:ok, %Stop{id: "place-test"}}
"222" -> {:ok, %Stop{id: "place-test-redundancy"}}
"333" -> {:ok, %Stop{id: "place-test-no-redundancy"}}
end)

expect(@stop, :fetch_parent_station_name_map, fn ->
{:ok,
%{
"place-haecl" => "Haymarket",
"place-test-redundancy" => "Other With Redundancy",
"place-test-no-redundancy" => "Other No Redundancy"
}}
end)

expect(@route, :fetch, 3, fn _ -> {:ok, [%Route{id: "Red", type: :subway}]} end)

expect(@alert, :fetch_elevator_alerts_with_facilities, fn ->
alerts = [
struct(Alert,
id: "1",
effect: :elevator_closure,
informed_entities: [
%{stop: "place-test", facility: %{name: "In Station Elevator", id: "112"}}
]
),
struct(Alert,
id: "2",
effect: :elevator_closure,
informed_entities: [
%{
stop: "place-test-redundancy",
facility: %{name: "Other With Redundancy", id: "222"}
}
]
),
struct(Alert,
id: "3",
effect: :elevator_closure,
informed_entities: [
%{
stop: "place-test-no-redundancy",
facility: %{name: "Other Without Redundancy", id: "333"}
}
]
)
]

{:ok, alerts}
end)

[
^header_instance,
%Screens.V2.WidgetInstance.OutsideElevatorClosures{
app_params: %ScreensConfig.V2.Elevator{
elevator_id: "111",
alternate_direction_text: "Test",
accessible_path_direction_arrow: :n,
evergreen_content: [],
accessible_path_image_url: nil,
accessible_path_image_here_coordinates: %{y: 0, x: 0}
},
in_station_closures: [
%Screens.V2.WidgetInstance.Elevator.Closure{
id: "1",
elevator_name: "In Station Elevator",
elevator_id: "112",
description: nil,
header_text: nil
}
],
other_stations_with_closures: [
%Screens.V2.WidgetInstance.OutsideElevatorClosures.Station{
id: "place-test-no-redundancy",
name: "Other No Redundancy",
route_icons: [%{type: :text, text: "RL", color: :red}],
closures: [
%Screens.V2.WidgetInstance.Elevator.Closure{
id: "3",
elevator_name: "Other Without Redundancy",
elevator_id: "333",
description: nil,
header_text: nil
}
]
},
%Screens.V2.WidgetInstance.OutsideElevatorClosures.Station{
id: "place-test-redundancy",
name: "Other With Redundancy",
route_icons: [%{type: :text, text: "RL", color: :red}],
closures: [
%Screens.V2.WidgetInstance.Elevator.Closure{
id: "2",
elevator_name: "Other With Redundancy",
elevator_id: "222",
description: nil,
header_text: nil
}
]
}
]
},
^footer_instance
] =
ElevatorClosures.elevator_status_instances(
struct(Screen, app_id: :elevator_v2, app_params: config),
header_instance,
footer_instance
)
end

test "Returns CurrentElevatorClosed if configured elevator is closed", %{
config: config,
header_instance: header_instance,
Expand Down

0 comments on commit 2344e9b

Please sign in to comment.