From 2344e9b1cea47b0af5fb6fcc874536be6a780fb7 Mon Sep 17 00:00:00 2001 From: cmaddox5 Date: Fri, 6 Dec 2024 14:19:44 -0500 Subject: [PATCH] Add test for redundancy logic. --- config/test.exs | 4 +- .../candidate_generator/elevator/closures.ex | 8 +- test/fixtures/elevator_redundancy_data.json | 11 ++ .../elevator/closures_test.exs | 117 ++++++++++++++++++ 4 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/elevator_redundancy_data.json diff --git a/config/test.exs b/config/test.exs index 5c00e0dd2..4eb4cb2f6 100644 --- a/config/test.exs +++ b/config/test.exs @@ -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" diff --git a/lib/screens/v2/candidate_generator/elevator/closures.ex b/lib/screens/v2/candidate_generator/elevator/closures.ex index a7f53412d..20c02e85e 100644 --- a/lib/screens/v2/candidate_generator/elevator/closures.ex +++ b/lib/screens/v2/candidate_generator/elevator/closures.ex @@ -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!() diff --git a/test/fixtures/elevator_redundancy_data.json b/test/fixtures/elevator_redundancy_data.json new file mode 100644 index 000000000..469d07afb --- /dev/null +++ b/test/fixtures/elevator_redundancy_data.json @@ -0,0 +1,11 @@ +{ + "112": { + "nearby_redundancy?": true + }, + "222": { + "nearby_redundancy?": true + }, + "333": { + "nearby_redundancy?": false + } +} diff --git a/test/screens/v2/candidate_generator/elevator/closures_test.exs b/test/screens/v2/candidate_generator/elevator/closures_test.exs index 31aa6f5dc..e1d9006ac 100644 --- a/test/screens/v2/candidate_generator/elevator/closures_test.exs +++ b/test/screens/v2/candidate_generator/elevator/closures_test.exs @@ -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,