Skip to content

Commit

Permalink
small test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen committed Nov 5, 2024
1 parent e00996a commit db0878a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
3 changes: 3 additions & 0 deletions test/dotcom_web/controllers/alert_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ defmodule DotcomWeb.AlertControllerTest do
setup :verify_on_exit!

setup do
cache = Application.get_env(:dotcom, :cache)
cache.flush()

stub(Routes.Repo.Mock, :by_type, fn route_type ->
build_list(2, :route, %{type: route_type})
end)
Expand Down
19 changes: 13 additions & 6 deletions test/dotcom_web/controllers/schedule/predictions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ defmodule DotcomWeb.ScheduleController.PredictionsTest do
import Test.Support.Factories.Predictions.Prediction

setup %{conn: conn} do
cache = Application.get_env(:dotcom, :cache)
cache.flush()

conn =
conn
|> assign(:date, ~D[2017-01-01])
Expand Down Expand Up @@ -243,8 +246,12 @@ defmodule DotcomWeb.ScheduleController.PredictionsTest do
trip_id_match = Enum.join(Enum.sort([trip_id_1, trip_id_2]), ",")

Predictions.Repo.Mock
|> expect(:all, fn [route: ^route_id] -> [] end)
|> expect(:all, fn [trip: ^trip_id_match] ->
|> expect(:all, fn arg ->
assert arg[:route] == route_id
[]
end)
|> expect(:all, fn arg ->
assert arg[:trip] == trip_id_match
# we transform the data into this form so that we only need to make one repo call
[prediction_1, prediction_2]
end)
Expand Down Expand Up @@ -286,12 +293,12 @@ defmodule DotcomWeb.ScheduleController.PredictionsTest do
prediction = build(:prediction, %{stop: %Stops.Stop{id: stop_id_1}})

Predictions.Repo.Mock
|> expect(:all, fn [route: id] ->
assert id == route_id
|> expect(:all, fn arg ->
assert arg[:route] == route_id
[]
end)
|> expect(:all, fn [trip: trip_id] ->
assert trip_id == Enum.join(Enum.sort([trip_id_1, trip_id_2]), ",")
|> expect(:all, fn arg ->
assert arg[:trip] == Enum.join(Enum.sort([trip_id_1, trip_id_2]), ",")
# we transform the data into this form so that we only need to make one repo call
[
prediction
Expand Down
12 changes: 6 additions & 6 deletions test/dotcom_web/live/trip_planner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ defmodule DotcomWeb.Live.TripPlannerTest do
%{html: html, view: view}
end

test "toggles the date input when changing from 'now'", %{html: html, view: view} do
end
# test "toggles the date input when changing from 'now'", %{html: html, view: view} do
# end

test "summarizes the selected modes", %{view: view, html: html} do
assert html =~ "All modes"
Expand Down Expand Up @@ -61,10 +61,10 @@ defmodule DotcomWeb.Live.TripPlannerTest do
assert html =~ "Subway and Bus"
end

test "shows errors on form submit", %{view: view} do
end
# test "shows errors on form submit", %{view: view} do
# end

test "pushes updated location to the map", %{view: view} do
end
# test "pushes updated location to the map", %{view: view} do
# end
end
end
8 changes: 6 additions & 2 deletions test/predictions/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ defmodule Predictions.RepoTest do
"arrival_time" => before_time
},
relationships: %{
"route" => [route_item]
"route" => [route_item],
"trip" => [],
"vehicle" => []
}
}) ++
build_list(2, :prediction_item, %{
attributes: %{
"arrival_time" => after_time
},
relationships: %{
"route" => [route_item]
"route" => [route_item],
"trip" => [],
"vehicle" => []
}
})
}
Expand Down

0 comments on commit db0878a

Please sign in to comment.