-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expand stops filters to include routes at stops
Adds `fetch_routes_for_stops/1` and uses that to expand a `stops:` filter similar to the V3 API.
- Loading branch information
1 parent
63777f9
commit d47fbd3
Showing
5 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
defmodule Screens.Alerts.Cache.FilterTest do | ||
use ExUnit.Case, async: true | ||
|
||
import Mox | ||
|
||
alias Screens.Routes.Route | ||
alias Screens.Stops.Stop | ||
alias Screens.Alerts.Cache.Filter | ||
|
||
describe "build_matchers/1" do | ||
setup do | ||
default_stops_mod = Application.get_env(:screens, :alerts_cache_filter_stops_mod) | ||
Application.put_env(:screens, :alerts_cache_filter_stops_mod, Stop.Mock) | ||
|
||
on_exit(fn -> | ||
Application.put_env(:screens, :alerts_cache_filter_stops_mod, default_stops_mod) | ||
end) | ||
end | ||
|
||
test "passes through empty filters" do | ||
assert [] == Filter.build_matchers(%{}) | ||
end | ||
|
||
test "adds matchers for direction_id" do | ||
assert [%{direction_id: 0}] == Filter.build_matchers(%{direction_id: 0}) | ||
assert [%{direction_id: 1}] == Filter.build_matchers(%{direction_id: 1}) | ||
end | ||
|
||
test "adds matchers for route_types" do | ||
assert [%{route_type: 1}, %{route_type: 2}] == Filter.build_matchers(%{route_types: [1, 2]}) | ||
end | ||
|
||
test "adds matchers for stops" do | ||
stub(Stop.Mock, :fetch_routes_for_stops, fn _ -> {:ok, []} end) | ||
|
||
assert [ | ||
%{stop: "place-pktrm"}, | ||
%{stop: "place-aport"} | ||
] = Filter.build_matchers(%{stops: ["place-pktrm", "place-aport"]}) | ||
end | ||
|
||
test "merges stop matchers into other matchers" do | ||
stub(Stop.Mock, :fetch_routes_for_stops, fn _ -> {:ok, []} end) | ||
|
||
assert [ | ||
%{stop: nil, direction_id: 0}, | ||
%{stop: "place-pktrm", direction_id: 0}, | ||
%{stop: "place-aport", direction_id: 0} | ||
] == Filter.build_matchers(%{direction_id: 0, stops: ["place-pktrm", "place-aport"]}) | ||
end | ||
|
||
test "adds matchers for routes at the stops" do | ||
stub(Stop.Mock, :fetch_routes_for_stops, fn | ||
["place-aport"] -> | ||
{:ok, [%Route{id: "Blue"}, %Route{id: "743"}]} | ||
end) | ||
|
||
assert [ | ||
%{stop: nil, route: "Blue"}, | ||
%{stop: "place-aport", route: "Blue"}, | ||
%{stop: nil, route: "743"}, | ||
%{stop: "place-aport", route: "743"}, | ||
%{stop: "place-aport"} | ||
] == Filter.build_matchers(%{stops: ["place-aport"]}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
ExUnit.start() | ||
|
||
Mox.defmock(Screens.Stops.Stop.Mock, for: Screens.Stops.Stop) |