-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
100% test coverage for mbta api module
- Loading branch information
1 parent
fd70948
commit 19719fc
Showing
20 changed files
with
546 additions
and
61 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
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,25 @@ | ||
defmodule MBTA.Api.AlertsTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mox | ||
|
||
alias MBTA.Api.{Alerts, Mock} | ||
|
||
setup :set_mox_global | ||
setup :verify_on_exit! | ||
|
||
test "all/0 returns a list of alerts" do | ||
# Setup | ||
expect(Mock, :get_json, fn url, _ -> | ||
assert url == "/alerts/" | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
alerts = Alerts.all() | ||
|
||
# Verify | ||
assert alerts == [] | ||
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule MBTA.Api.FacilitiesTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mox | ||
|
||
alias MBTA.Api.{Facilities, Mock} | ||
|
||
setup :set_mox_global | ||
setup :verify_on_exit! | ||
|
||
test "all/0 returns a list of facilities" do | ||
# Setup | ||
expect(Mock, :get_json, fn url, _ -> | ||
assert url == "/facilities/" | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
facilities = Facilities.all() | ||
|
||
# Verify | ||
assert facilities == [] | ||
end | ||
|
||
test "filter_by/1 sends filters as query parameters" do | ||
# Setup | ||
expect(Mock, :get_json, fn url, params -> | ||
assert url == "/facilities/" | ||
|
||
assert Enum.sort(params) == | ||
Enum.sort([{"filter[stop_id]", "place-sstat"}, {"filter[route_type]", "0"}]) | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
facilities = Facilities.filter_by(%{stop_id: "place-sstat", route_type: "0"}) | ||
|
||
# Verify | ||
assert facilities == [] | ||
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule MBTA.Api.PredictionsTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mox | ||
|
||
alias MBTA.Api.{Predictions, Mock} | ||
|
||
setup :set_mox_global | ||
setup :verify_on_exit! | ||
|
||
test "all/1 returns a list of predictions" do | ||
# Setup | ||
expect(Mock, :get_json, fn url, params -> | ||
assert url == "/predictions/" | ||
assert Enum.sort(params) == Enum.sort(foo: 1, bar: 2) | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
predictions = Predictions.all(foo: 1, bar: 2) | ||
|
||
# Verify | ||
assert predictions == [] | ||
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Mbta.Api.RoutePatternsTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mox | ||
|
||
alias MBTA.Api.{Mock, RoutePatterns} | ||
|
||
setup :set_mox_global | ||
setup :verify_on_exit! | ||
|
||
test "all/0 returns a list of route patterns" do | ||
# Setup | ||
expect(Mock, :get_json, fn url, _ -> | ||
assert url == "/route_patterns/" | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
route_patterns = RoutePatterns.all() | ||
|
||
# Verify | ||
assert route_patterns == [] | ||
end | ||
|
||
test "get/1 returns a route pattern" do | ||
# Setup | ||
id = 1 | ||
|
||
expect(Mock, :get_json, fn url, _ -> | ||
assert url == "/route_patterns/#{id}" | ||
|
||
%{} | ||
end) | ||
|
||
# Exercise | ||
route_pattern = RoutePatterns.get(1) | ||
|
||
# Verify | ||
assert route_pattern == %{} | ||
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
defmodule MBTA.Api.RoutesTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mox | ||
|
||
alias MBTA.Api.{Mock, Routes} | ||
|
||
setup :set_mox_global | ||
setup :verify_on_exit! | ||
|
||
test "all/0 returns a list of routes" do | ||
# Setup | ||
expect(Mock, :get_json, fn url, _ -> | ||
assert url == "/routes/" | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
routes = Routes.all() | ||
|
||
# Verify | ||
assert routes == [] | ||
end | ||
|
||
test "get/1 returns a route" do | ||
# Setup | ||
id = :rand.uniform(100) | ||
|
||
expect(Mock, :get_json, fn url, _ -> | ||
assert url == "/routes/#{id}" | ||
|
||
%{} | ||
end) | ||
|
||
# Exercise | ||
route = Routes.get(id) | ||
|
||
# Verify | ||
assert route == %{} | ||
end | ||
|
||
test "by_type/1 sends type as query parameter" do | ||
# Setup | ||
type = :rand.uniform(100) | ||
|
||
expect(Mock, :get_json, fn url, params -> | ||
assert url == "/routes/" | ||
assert Enum.sort(params) == Enum.sort(type: type) | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
routes = Routes.by_type(type) | ||
|
||
# Verify | ||
assert routes == [] | ||
end | ||
|
||
test "by_stop/1 sends stop as query parameter" do | ||
# Setup | ||
stop = Faker.Team.creature() |> String.downcase() | ||
|
||
expect(Mock, :get_json, fn url, params -> | ||
assert url == "/routes/" | ||
assert Enum.sort(params) == Enum.sort(stop: stop) | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
routes = Routes.by_stop(stop) | ||
|
||
# Verify | ||
assert routes == [] | ||
end | ||
|
||
test "by_stop_and_direction/2 sends stop and direction_id as query parameters" do | ||
# Setup | ||
stop = Faker.Team.creature() |> String.downcase() | ||
direction_id = :rand.uniform(1) | ||
|
||
expect(Mock, :get_json, fn url, params -> | ||
assert url == "/routes/" | ||
assert Enum.sort(params) == Enum.sort(stop: stop, direction_id: direction_id) | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
routes = Routes.by_stop_and_direction(stop, direction_id) | ||
|
||
# Verify | ||
assert routes == [] | ||
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule MBTA.Api.SchedulesTest do | ||
use ExUnit.Case, async: false | ||
|
||
import Mox | ||
|
||
alias MBTA.Api.{Mock, Schedules} | ||
|
||
setup :set_mox_global | ||
setup :verify_on_exit! | ||
|
||
test "all/0 returns a list of schedules" do | ||
# Setup | ||
expect(Mock, :get_json, fn url, _ -> | ||
assert url == "/schedules/" | ||
|
||
[] | ||
end) | ||
|
||
# Exercise | ||
schedules = Schedules.all() | ||
|
||
# Verify | ||
assert schedules == [] | ||
end | ||
end |
Oops, something went wrong.