Skip to content

Commit

Permalink
more feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen committed May 14, 2024
1 parent a3c4442 commit bf11bb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
15 changes: 2 additions & 13 deletions lib/stops/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,14 @@ defmodule Stops.Repo do

alias Dotcom.Cache.KeyGenerator
alias Stops.{Api, Stop}
alias Stops.Repo.Behaviour
alias Routes.Route

@behaviour Stops.Repo.Behaviour

@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!()
Expand Down Expand Up @@ -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
Expand Down
31 changes: 21 additions & 10 deletions lib/stops/repo/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
6 changes: 4 additions & 2 deletions test/alerts/historical_alert_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand All @@ -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
Expand Down

0 comments on commit bf11bb6

Please sign in to comment.