Skip to content

Commit

Permalink
Added updated the tests for transit near me
Browse files Browse the repository at this point in the history
  • Loading branch information
kotva006 committed May 8, 2024
1 parent 480a754 commit 29083ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/dotcom/transit_near_me.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ defmodule Dotcom.TransitNearMe do
"place-hsmnl"
]

@predictions_repo Application.compile_env!(:dotcom, :repo_modules)[:predictions]

@spec build(Address.t(), Keyword.t()) :: stops_with_distances
def build(%Address{} = location, opts) do
opts = Keyword.merge(@default_opts, opts)
Expand Down Expand Up @@ -382,7 +384,9 @@ defmodule Dotcom.TransitNearMe do
PredictedSchedule.t()
]
defp get_predicted_schedules(schedules, params, opts) do
predictions_fn = Keyword.get(opts, :predictions_fn, &Predictions.Repo.all/1)
predictions_fn =
Keyword.get(opts, :predictions_fn, Function.capture(@predictions_repo, :all, 1))

now = Keyword.fetch!(opts, :now)

predictions = predictions_fn.(params)
Expand Down
13 changes: 7 additions & 6 deletions test/dotcom/transit_near_me_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Dotcom.TransitNearMeTest do
use ExUnit.Case

import Mox

alias LocationService.Address
alias Predictions.Prediction
alias Routes.Route
Expand Down Expand Up @@ -725,7 +727,9 @@ defmodule Dotcom.TransitNearMeTest do
}

test "returns time data for the next 2 predictions" do
predictions_fn = fn _ -> [@prediction1, @prediction2, @prediction3] end
expect(Predictions.Repo.Mock, :all, fn _ ->
[@prediction1, @prediction2, @prediction3]
end)

schedules_fn = fn _, _ ->
[@schedule1, @schedule2, @schedule3]
Expand Down Expand Up @@ -787,15 +791,14 @@ defmodule Dotcom.TransitNearMeTest do
actual =
TransitNearMe.time_data_for_route_by_stop(@route.id, 1,
schedules_fn: schedules_fn,
predictions_fn: predictions_fn,
now: @now
)

assert actual == expected
end

test "returns no data when schedules is empty" do
predictions_fn = fn _ -> [@prediction1] end
expect(Predictions.Repo.Mock, :all, fn _ -> [@prediction1] end)

schedules_fn = fn _, _ ->
[]
Expand All @@ -804,15 +807,14 @@ defmodule Dotcom.TransitNearMeTest do
actual =
TransitNearMe.time_data_for_route_by_stop(@route.id, 1,
schedules_fn: schedules_fn,
predictions_fn: predictions_fn,
now: @now
)

assert %{"95" => [%{}]} = actual
end

test "return neither schedules nor predictions if date is outside rating" do
predictions_fn = fn _ -> [@prediction1] end
expect(Predictions.Repo.Mock, :all, fn _ -> [@prediction1] end)

schedules_fn = fn _, _ ->
{:error,
Expand All @@ -833,7 +835,6 @@ defmodule Dotcom.TransitNearMeTest do
actual =
TransitNearMe.time_data_for_route_by_stop(@route.id, 1,
schedules_fn: schedules_fn,
predictions_fn: predictions_fn,
now: @now
)

Expand Down

0 comments on commit 29083ce

Please sign in to comment.