-
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
f27de4f
commit 8042c3f
Showing
6 changed files
with
116 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
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,57 @@ | ||
defmodule Screens.Alerts.Cache.FilterTest do | ||
use ExUnit.Case, async: true | ||
|
||
import Mox | ||
|
||
alias Screens.Alerts.Cache.Filter | ||
alias Screens.Routes.Route | ||
|
||
describe "build_matchers/1" do | ||
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(Route.Mock, :serving_stop, 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(Route.Mock, :serving_stop, 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(Route.Mock, :serving_stop, 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.Routes.Route.Mock, for: Screens.Routes.Route) |