diff --git a/lib/screens/application.ex b/lib/screens/application.ex index 37c9b3c54..a09ce781d 100644 --- a/lib/screens/application.ex +++ b/lib/screens/application.ex @@ -23,7 +23,6 @@ defmodule Screens.Application do :hackney_pool.child_spec(:ex_aws_pool, []), :hackney_pool.child_spec(:blue_bikes_pool, []), :hackney_pool.child_spec(:api_v3_pool, max_connections: 100), - {Screens.Stops.StationsWithRoutesAgent, %{}}, # Turning this off because it's not in use, and the process is failing # {Screens.BlueBikes.State, name: Screens.BlueBikes.State}, # Task supervisor for ScreensByAlert async updates diff --git a/lib/screens/routes/route.ex b/lib/screens/routes/route.ex index 545ba433e..c366bfa6b 100644 --- a/lib/screens/routes/route.ex +++ b/lib/screens/routes/route.ex @@ -1,6 +1,9 @@ defmodule Screens.Routes.Route do @moduledoc false + require Logger + + alias Screens.Routes.Parser alias Screens.RouteType alias Screens.Stops.Stop alias Screens.V3Api @@ -39,7 +42,7 @@ defmodule Screens.Routes.Route do @spec by_id(id()) :: {:ok, t()} | :error def by_id(route_id) do case V3Api.get_json("routes/" <> route_id) do - {:ok, %{"data" => data}} -> {:ok, Screens.Routes.Parser.parse_route(data)} + {:ok, %{"data" => data}} -> {:ok, Parser.parse_route(data)} _ -> :error end end @@ -53,18 +56,46 @@ defmodule Screens.Routes.Route do |> Enum.into(%{}) case get_json_fn.("routes/", params) do - {:ok, %{"data" => data}} -> {:ok, Enum.map(data, &Screens.Routes.Parser.parse_route/1)} + {:ok, %{"data" => data}} -> {:ok, Enum.map(data, &Parser.parse_route/1)} _ -> :error end end + @doc "Fetches routes that serve the given stop." + @spec serving_stop(Stop.id()) :: {:ok, t()} | :error + def serving_stop( + stop_id, + get_json_fn \\ &V3Api.get_json/2, + attempts_left \\ 3 + ) + + def serving_stop(_stop_id, _get_json_fn, 0), do: :error + + def serving_stop( + stop_id, + get_json_fn, + attempts_left + ) do + case get_json_fn.("routes", %{"filter[stop]" => stop_id}) do + {:ok, %{"data" => []}, _} -> + Logger.warning("Route.serving_stop empty_retry attempts_left=#{attempts_left - 1}") + serving_stop(stop_id, get_json_fn, attempts_left - 1) + + {:ok, %{"data" => data}} -> + {:ok, Enum.map(data, fn route -> Parser.parse_route(route) end)} + + _ -> + :error + end + end + @doc """ - Fetches routes that serve the given stop. `now` is used to determine whether - each route is actively running on the current day. + Similar to `serving_stop` but also determines whether each route has any scheduled service at + the given stop on the current day. Only route IDs and the `active?` flag are returned. """ - @spec fetch_routes_by_stop(String.t()) :: + @spec serving_stop_with_active(Stop.id()) :: {:ok, list(%{route_id: id(), active?: boolean()})} | :error - def fetch_routes_by_stop( + def serving_stop_with_active( stop_id, now \\ DateTime.utc_now(), type_filters \\ [], @@ -72,7 +103,7 @@ defmodule Screens.Routes.Route do fetch_routes_fn \\ &fetch_routes/3 ) do Screens.Telemetry.span( - ~w[screens routes route fetch_routes_by_stop]a, + ~w[screens routes route serving_stop_with_active]a, %{stop_id: stop_id, type_filters: type_filters}, fn -> with {:ok, routes} <- fetch_routes_fn.(stop_id, get_json_fn, type_filters), @@ -80,14 +111,7 @@ defmodule Screens.Routes.Route do active_set = MapSet.new(active_route_ids) routes_at_stop = - Enum.map( - routes, - &(&1 - |> Map.from_struct() - |> Map.put(:active?, MapSet.member?(active_set, &1.id)) - |> Map.put(:route_id, &1.id) - |> Map.delete(:id)) - ) + Enum.map(routes, &%{route_id: &1.id, active?: MapSet.member?(active_set, &1.id)}) {:ok, routes_at_stop} else diff --git a/lib/screens/stops/stations_with_routes_agent.ex b/lib/screens/stops/stations_with_routes_agent.ex deleted file mode 100644 index 0d18654a2..000000000 --- a/lib/screens/stops/stations_with_routes_agent.ex +++ /dev/null @@ -1,16 +0,0 @@ -defmodule Screens.Stops.StationsWithRoutesAgent do - @moduledoc false - use Agent - - def start_link(initial_value) do - Agent.start_link(fn -> initial_value end, name: __MODULE__) - end - - def get(station_id) do - Agent.get(__MODULE__, &Map.get(&1, station_id)) - end - - def put(station_id, routes) do - Agent.update(__MODULE__, &Map.put(&1, station_id, routes)) - end -end diff --git a/lib/screens/stops/stop.ex b/lib/screens/stops/stop.ex index 75bb2faea..e8d258d43 100644 --- a/lib/screens/stops/stop.ex +++ b/lib/screens/stops/stop.ex @@ -12,10 +12,9 @@ defmodule Screens.Stops.Stop do alias Screens.LocationContext alias Screens.RoutePatterns.RoutePattern - alias Screens.{Routes, Stops} alias Screens.Routes.Route alias Screens.RouteType - alias Screens.Stops.StationsWithRoutesAgent + alias Screens.Stops alias Screens.Util alias Screens.V3Api alias ScreensConfig.V2.{BusEink, BusShelter, Dup, GlEink, PreFare, Triptych} @@ -271,74 +270,6 @@ defmodule Screens.Stops.Stop do end end - def fetch_routes_serving_stop( - station_id, - get_json_fn \\ &V3Api.get_json/2, - attempts_left \\ 3 - ) - - def fetch_routes_serving_stop(_station_id, _get_json_fn, 0), do: :bad_response - - def fetch_routes_serving_stop( - station_id, - get_json_fn, - attempts_left - ) do - case get_json_fn.("routes", %{"filter[stop]" => station_id}) do - {:ok, %{"data" => []}, _} -> - fetch_routes_serving_stop(station_id, get_json_fn, attempts_left - 1) - - {:ok, %{"data" => data}} -> - {:ok, Enum.map(data, fn route -> Routes.Parser.parse_route(route) end)} - - _ -> - :error - end - end - - # Returns a list of Route structs that serve the provided ID - @spec create_station_with_routes_map(String.t()) :: list(Routes.Route.t()) - def create_station_with_routes_map(station_id) do - case StationsWithRoutesAgent.get(station_id) do - nil -> - get_routes_serving_stop(station_id) - - routes -> - get_routes_serving_stop(station_id, routes) - end - end - - defp get_routes_serving_stop(station_id, default_routes \\ []) do - case fetch_routes_serving_stop(station_id) do - {:ok, new_routes} -> - new_routes - - :bad_response -> - Logger.error( - "[create_station_with_routes_map no routes] Received an empty list from API: stop_id=#{station_id}" - ) - - default_routes - - :error -> - Logger.error( - "[create_station_with_routes_map fetch error] Received an error from API: stop_id=#{station_id}" - ) - - default_routes - end - end - - def get_routes_serving_stop_ids(stop_ids) do - stop_ids - |> Enum.flat_map(fn stop_id -> - stop_id - |> create_station_with_routes_map() - |> Enum.map(& &1.id) - end) - |> Enum.uniq() - end - def fetch_stop_name(stop_id) do Screens.Telemetry.span(~w[screens stops stop fetch_stop_name]a, %{stop_id: stop_id}, fn -> case Screens.V3Api.get_json("stops", %{"filter[id]" => stop_id}) do @@ -479,7 +410,8 @@ defmodule Screens.Stops.Stop do %{app: app, stop_id: stop_id}, fn -> with alert_route_types <- get_route_type_filter(app, stop_id), - {:ok, routes_at_stop} <- Route.fetch_routes_by_stop(stop_id, now, alert_route_types), + {:ok, routes_at_stop} <- + Route.serving_stop_with_active(stop_id, now, alert_route_types), {:ok, tagged_stop_sequences} <- fetch_tagged_stop_sequences_by_app(app, stop_id, routes_at_stop) do stop_name = fetch_stop_name(stop_id) diff --git a/lib/screens/v2/candidate_generator/dup/departures.ex b/lib/screens/v2/candidate_generator/dup/departures.ex index 9ad5cff8e..0c8f8584c 100644 --- a/lib/screens/v2/candidate_generator/dup/departures.ex +++ b/lib/screens/v2/candidate_generator/dup/departures.ex @@ -28,7 +28,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do fetch_departures_fn \\ &Departure.fetch/2, fetch_alerts_fn \\ &Alert.fetch_or_empty_list/1, fetch_schedules_fn \\ &Screens.Schedules.Schedule.fetch/2, - create_station_with_routes_map_fn \\ &Screens.Stops.Stop.create_station_with_routes_map/1, + fetch_routes_serving_stop_fn \\ &Screens.Routes.Route.serving_stop/1, fetch_vehicles_fn \\ &Screens.Vehicles.Vehicle.by_route_and_direction/2 ) do primary_departures_instances = @@ -36,7 +36,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do |> get_sections_data( fetch_departures_fn, fetch_alerts_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, now ) |> sections_data_to_departure_instances( @@ -64,7 +64,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do |> get_sections_data( fetch_departures_fn, fetch_alerts_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, now ) |> sections_data_to_departure_instances( @@ -208,7 +208,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do sections, fetch_departures_fn, fetch_alerts_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, now ) do Screens.Telemetry.span( @@ -222,7 +222,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do &1, fetch_departures_fn, fetch_alerts_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, now, ctx ), @@ -249,7 +249,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do section, fetch_departures_fn, fetch_alerts_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, now, ctx ) do @@ -257,7 +257,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do [:screens, :v2, :candidate_generator, :dup, :departures, :get_section_data], ctx, fn -> - routes = get_routes_serving_section(params, create_station_with_routes_map_fn) + routes = get_routes_serving_section(params, fetch_routes_serving_stop_fn) # DUP sections will always show no more than one mode. # For subway, each route will have its own section. # If the stop is served by two different subway/light rail routes, route_ids must be populated for each section @@ -634,11 +634,11 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do defp get_routes_serving_section( %{route_ids: route_ids, stop_ids: stop_ids}, - create_station_with_routes_map_fn + fetch_routes_serving_stop_fn ) do routes = stop_ids - |> Enum.flat_map(&create_station_with_routes_map_fn.(&1)) + |> Enum.flat_map(&fetch_routes_serving_stop_fn.(&1)) |> Enum.uniq() if route_ids == [] do diff --git a/lib/screens/v2/candidate_generator/pre_fare.ex b/lib/screens/v2/candidate_generator/pre_fare.ex index c7e8d000d..99ea09435 100644 --- a/lib/screens/v2/candidate_generator/pre_fare.ex +++ b/lib/screens/v2/candidate_generator/pre_fare.ex @@ -93,10 +93,10 @@ defmodule Screens.V2.CandidateGenerator.PreFare do def audio_only_instances( widgets, config, - fetch_routes_by_stop_fn \\ &Route.fetch_routes_by_stop/1 + routes_serving_stop_fn \\ &Route.serving_stop/1 ) do [ - fn -> content_summary_instances(widgets, config, fetch_routes_by_stop_fn) end, + fn -> content_summary_instances(widgets, config, routes_serving_stop_fn) end, fn -> alerts_intro_instances(widgets, config) end, fn -> alerts_outro_instances(widgets, config) end ] @@ -133,14 +133,14 @@ defmodule Screens.V2.CandidateGenerator.PreFare do [%ShuttleBusInfoWidget{screen: config, now: now}] end - defp content_summary_instances(widgets, config, fetch_routes_by_stop_fn) do + defp content_summary_instances(widgets, config, routes_serving_stop_fn) do config.app_params.content_summary.parent_station_id - |> fetch_routes_by_stop_fn.() + |> routes_serving_stop_fn.() |> case do {:ok, routes_at_station} -> subway_lines_at_station = routes_at_station - |> Enum.map(& &1.route_id) + |> Enum.map(& &1.id) |> Enum.map(fn "Red" -> :red "Orange" -> :orange diff --git a/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex b/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex index fa1f66855..b7a53b2c3 100644 --- a/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex +++ b/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex @@ -2,6 +2,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ElevatorClosures do @moduledoc false alias Screens.Alerts.Alert + alias Screens.Routes.Route alias Screens.Stops.Stop alias Screens.V2.WidgetInstance.ElevatorStatus, as: ElevatorStatusWidget alias ScreensConfig.Screen @@ -51,7 +52,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ElevatorClosures do |> MapSet.new() |> MapSet.put(home_parent_station_id) |> Enum.map(fn station_id -> - {station_id, station_id |> Stop.create_station_with_routes_map() |> routes_to_icons()} + {station_id, station_id |> Route.serving_stop() |> routes_to_icons()} end) |> Enum.into(%{}) end diff --git a/test/screens/routes/route_test.exs b/test/screens/routes/route_test.exs index 191bed69b..f6870a809 100644 --- a/test/screens/routes/route_test.exs +++ b/test/screens/routes/route_test.exs @@ -29,10 +29,9 @@ defmodule Screens.Routes.RouteTest do end end - describe "fetch_routes_by_stop/3" do + describe "serving_stop_with_active/3" do setup do active_routes = [route_json("22"), route_json("44")] - all_routes = [route_json("22"), route_json("29"), route_json("44")] stop_id = "1265" @@ -79,33 +78,12 @@ defmodule Screens.Routes.RouteTest do } = context expected_routes = [ - %{ - active?: true, - route_id: "22", - direction_destinations: nil, - long_name: nil, - short_name: nil, - type: :subway - }, - %{ - active?: false, - route_id: "29", - direction_destinations: nil, - long_name: nil, - short_name: nil, - type: :subway - }, - %{ - active?: true, - route_id: "44", - direction_destinations: nil, - long_name: nil, - short_name: nil, - type: :subway - } + %{active?: true, route_id: "22"}, + %{active?: false, route_id: "29"}, + %{active?: true, route_id: "44"} ] - assert {:ok, expected_routes} == fetch_routes_by_stop(stop_id, now, [], get_json_fn) + assert {:ok, expected_routes} == serving_stop_with_active(stop_id, now, [], get_json_fn) end test "returns :error if either fetch function returns :error", context do @@ -118,12 +96,9 @@ defmodule Screens.Routes.RouteTest do x_fetch_routes_fn: x_fetch_routes_fn } = context - assert :error == fetch_routes_by_stop(stop_id, now, [], x_get_json_fn1) - - assert :error == fetch_routes_by_stop(stop_id, now, [], x_get_json_fn2) - - assert :error == - fetch_routes_by_stop(stop_id, now, [], get_json_fn, x_fetch_routes_fn) + assert :error == serving_stop_with_active(stop_id, now, [], x_get_json_fn1) + assert :error == serving_stop_with_active(stop_id, now, [], x_get_json_fn2) + assert :error == serving_stop_with_active(stop_id, now, [], get_json_fn, x_fetch_routes_fn) end test "filters routes by type if provided", context do @@ -135,7 +110,7 @@ defmodule Screens.Routes.RouteTest do } = context assert {:ok, []} == - fetch_routes_by_stop(stop_id, now, :subway, get_json_fn, fetch_routes_fn) + serving_stop_with_active(stop_id, now, :subway, get_json_fn, fetch_routes_fn) end end end diff --git a/test/screens/v2/candidate_generator/dup/departures_test.exs b/test/screens/v2/candidate_generator/dup/departures_test.exs index 42ba4b53d..8ed1f3832 100644 --- a/test/screens/v2/candidate_generator/dup/departures_test.exs +++ b/test/screens/v2/candidate_generator/dup/departures_test.exs @@ -250,7 +250,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_vehicles_fn = fn _, _ -> [struct(Vehicle)] end - create_station_with_routes_map_fn = fn + fetch_routes_serving_stop_fn = fn "Boat" -> [%{id: "Ferry", type: :ferry}] "place-A" -> [%{id: "Orange", type: :subway}, %{id: "Green", type: :light_rail}] "bus-A" -> [%{id: "Bus A", type: :bus}] @@ -264,7 +264,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } end @@ -275,7 +275,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -441,7 +441,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -453,7 +453,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -624,7 +624,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -636,7 +636,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -810,7 +810,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -822,7 +822,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -914,7 +914,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -926,7 +926,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -1108,7 +1108,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -1119,7 +1119,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -1196,7 +1196,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -1207,7 +1207,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -1408,7 +1408,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -1419,7 +1419,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -1571,7 +1571,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -1582,7 +1582,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -1687,7 +1687,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -1698,7 +1698,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_schedules_fn: fetch_schedules_fn, fetch_vehicles_fn: fetch_vehicles_fn } do @@ -1815,7 +1815,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -1827,7 +1827,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, fetch_schedules_fn: fetch_schedules_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -1858,7 +1858,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -1872,7 +1872,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -2000,7 +2000,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -2012,7 +2012,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -2133,7 +2133,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -2146,7 +2146,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -2212,7 +2212,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -2224,7 +2224,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -2283,7 +2283,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -2295,7 +2295,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -2392,7 +2392,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -2404,7 +2404,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do config: config, fetch_departures_fn: fetch_departures_fn, fetch_alerts_fn: fetch_alerts_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn, fetch_vehicles_fn: fetch_vehicles_fn } do config = @@ -2452,7 +2452,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) @@ -2463,7 +2463,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do %{ config: config, fetch_departures_fn: fetch_departures_fn, - create_station_with_routes_map_fn: create_station_with_routes_map_fn + fetch_routes_serving_stop_fn: fetch_routes_serving_stop_fn } do config = config @@ -2534,7 +2534,7 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_departures_fn, fetch_alerts_fn, fetch_schedules_fn, - create_station_with_routes_map_fn, + fetch_routes_serving_stop_fn, fetch_vehicles_fn ) diff --git a/test/screens/v2/candidate_generator/pre_fare_test.exs b/test/screens/v2/candidate_generator/pre_fare_test.exs index 19a9260ea..9d1b7e91a 100644 --- a/test/screens/v2/candidate_generator/pre_fare_test.exs +++ b/test/screens/v2/candidate_generator/pre_fare_test.exs @@ -119,9 +119,8 @@ defmodule Screens.V2.CandidateGenerator.PreFareTest do %{config: config} do widgets = [] - fetch_routes_by_stop_fn = fn "place-foo" -> - {:ok, - [%{route_id: "Red"}, %{route_id: "Green-B"}, %{route_id: "Green-C"}, %{route_id: "Blue"}]} + routes_serving_stop_fn = fn "place-foo" -> + {:ok, [%{id: "Red"}, %{id: "Green-B"}, %{id: "Green-C"}, %{id: "Blue"}]} end expected_content_summary = %ContentSummary{ @@ -133,7 +132,7 @@ defmodule Screens.V2.CandidateGenerator.PreFareTest do assert expected_content_summary in PreFare.audio_only_instances( widgets, config, - fetch_routes_by_stop_fn + routes_serving_stop_fn ) end @@ -143,10 +142,10 @@ defmodule Screens.V2.CandidateGenerator.PreFareTest do } do widgets = [] - fetch_routes_by_stop_fn = fn "place-foo" -> :error end + routes_serving_stop_fn = fn "place-foo" -> :error end refute Enum.any?( - PreFare.audio_only_instances(widgets, config, fetch_routes_by_stop_fn), + PreFare.audio_only_instances(widgets, config, routes_serving_stop_fn), &match?(%ContentSummary{}, &1) ) end @@ -154,10 +153,10 @@ defmodule Screens.V2.CandidateGenerator.PreFareTest do test "always returns list containing alerts intro", %{config: config} do widgets = [] - fetch_routes_by_stop_fn = fn "place-foo" -> {:ok, []} end + routes_serving_stop_fn = fn "place-foo" -> {:ok, []} end assert Enum.any?( - PreFare.audio_only_instances(widgets, config, fetch_routes_by_stop_fn), + PreFare.audio_only_instances(widgets, config, routes_serving_stop_fn), &match?(%AlertsIntro{}, &1) ) end @@ -165,10 +164,10 @@ defmodule Screens.V2.CandidateGenerator.PreFareTest do test "always returns list containing alerts outro", %{config: config} do widgets = [] - fetch_routes_by_stop_fn = fn "place-foo" -> {:ok, []} end + routes_serving_stop_fn = fn "place-foo" -> {:ok, []} end assert Enum.any?( - PreFare.audio_only_instances(widgets, config, fetch_routes_by_stop_fn), + PreFare.audio_only_instances(widgets, config, routes_serving_stop_fn), &match?(%AlertsOutro{}, &1) ) end