From bf11bb650bed6f7643cd746d3d66f61646401106 Mon Sep 17 00:00:00 2001 From: Cristen Jones Date: Tue, 14 May 2024 10:29:43 -0400 Subject: [PATCH] more feedback changes --- lib/stops/repo.ex | 15 ++----------- lib/stops/repo/behaviour.ex | 31 ++++++++++++++++++--------- test/alerts/historical_alert_test.exs | 6 ++++-- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/stops/repo.ex b/lib/stops/repo.ex index 92b0d88599..17b1eacad4 100644 --- a/lib/stops/repo.ex +++ b/lib/stops/repo.ex @@ -7,6 +7,7 @@ defmodule Stops.Repo do alias Dotcom.Cache.KeyGenerator alias Stops.{Api, Stop} + alias Stops.Repo.Behaviour alias Routes.Route @behaviour Stops.Repo.Behaviour @@ -14,18 +15,6 @@ defmodule Stops.Repo do @cache Application.compile_env!(:dotcom, :cache) @ttl :timer.hours(1) - @type stop_feature :: - Route.route_type() - | Route.subway_lines_type() - | :access - | :parking_lot - | :"Green-B" - | :"Green-C" - | :"Green-D" - | :"Green-E" - @type stops_response :: [Stop.t()] | {:error, any} - @type stop_by_route :: (Route.id_t(), 0 | 1, Keyword.t() -> stops_response) - for {old_id, gtfs_id} <- "priv/stops/stop_id_to_gtfs.csv" |> File.stream!() @@ -147,7 +136,7 @@ defmodule Stops.Repo do defp parking_features([]), do: [] defp parking_features(_parking_lots), do: [:parking_lot] - @spec route_features(String.t(), Keyword.t()) :: [stop_feature] + @spec route_features(String.t(), Keyword.t()) :: [Behaviour.stop_feature()] defp route_features(stop_id, opts) do icon_fn = if Keyword.get(opts, :expand_branches?) do diff --git a/lib/stops/repo/behaviour.ex b/lib/stops/repo/behaviour.ex index c0cc6bb936..d44a5b181d 100644 --- a/lib/stops/repo/behaviour.ex +++ b/lib/stops/repo/behaviour.ex @@ -4,7 +4,18 @@ defmodule Stops.Repo.Behaviour do """ alias Routes.Route alias Schedules.Trip - alias Stops.{Repo, Stop} + alias Stops.Stop + + @type stop_feature :: + Route.route_type() + | Route.subway_lines_type() + | :access + | :parking_lot + | :"Green-B" + | :"Green-C" + | :"Green-D" + | :"Green-E" + @type stops_response :: [Stop.t()] | {:error, any} @callback old_id_to_gtfs_id(Stop.id_t()) :: Stop.id_t() | nil @@ -15,17 +26,17 @@ defmodule Stops.Repo.Behaviour do @callback get_parent(Stop.t() | Stop.id_t() | nil) :: Stop.t() | nil - @callback by_route(Route.id_t(), 0 | 1) :: Repo.stops_response() - @callback by_route(Route.id_t(), 0 | 1, Keyword.t()) :: Repo.stops_response() + @callback by_route(Route.id_t(), 0 | 1) :: stops_response() + @callback by_route(Route.id_t(), 0 | 1, Keyword.t()) :: stops_response() - @callback by_routes([Route.id_t()], 0 | 1) :: Repo.stops_response() - @callback by_routes([Route.id_t()], 0 | 1, Keyword.t()) :: Repo.stops_response() + @callback by_routes([Route.id_t()], 0 | 1) :: stops_response() + @callback by_routes([Route.id_t()], 0 | 1, Keyword.t()) :: stops_response() - @callback by_route_type(Route.type_int()) :: Repo.stops_response() - @callback by_route_type(Route.type_int(), Keyword.t()) :: Repo.stops_response() + @callback by_route_type(Route.type_int()) :: stops_response() + @callback by_route_type(Route.type_int(), Keyword.t()) :: stops_response() - @callback by_trip(Trip.id_t()) :: Repo.stops_response() + @callback by_trip(Trip.id_t()) :: stops_response() - @callback stop_features(Stop.t()) :: [Repo.stop_feature()] - @callback stop_features(Stop.t(), Keyword.t()) :: [Repo.stop_feature()] + @callback stop_features(Stop.t()) :: [stop_feature()] + @callback stop_features(Stop.t(), Keyword.t()) :: [stop_feature()] end diff --git a/test/alerts/historical_alert_test.exs b/test/alerts/historical_alert_test.exs index fe7d57dedf..d8a40a91e0 100644 --- a/test/alerts/historical_alert_test.exs +++ b/test/alerts/historical_alert_test.exs @@ -7,6 +7,7 @@ defmodule Alerts.HistoricalAlertTest do alias Alerts.{Alert, HistoricalAlert, InformedEntity} @basic_alert %Alert{header: "An alert header", effect: :delay, severity: 5} + @municipality Faker.Address.city() @stop_entity %InformedEntity{stop: "1"} @route_entity %InformedEntity{route: "627"} @@ -28,8 +29,9 @@ defmodule Alerts.HistoricalAlertTest do test "can include municipality from related stop" do alert_for_stop = Alert.new(informed_entity: [@stop_entity]) - expect(Stops.Repo.Mock, :get, 2, fn _ -> %Stops.Stop{municipality: "Atlantis"} end) - assert %HistoricalAlert{municipality: "Atlantis"} = from_alert(alert_for_stop) + expect(Stops.Repo.Mock, :get, 2, fn _ -> %Stops.Stop{municipality: @municipality} end) + assert %HistoricalAlert{municipality: muni} = from_alert(alert_for_stop) + assert muni == @municipality expect(Stops.Repo.Mock, :get, 2, fn _ -> %Stops.Stop{municipality: nil} end) assert %HistoricalAlert{municipality: nil} = from_alert(alert_for_stop) end