Skip to content

Commit

Permalink
Updated the prediction schedule and corresponding test
Browse files Browse the repository at this point in the history
  • Loading branch information
kotva006 committed May 8, 2024
1 parent 9ca4253 commit 4a64af7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/predicted_schedule.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ defmodule PredictedSchedule do
prediction: Prediction.t() | nil
}

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

def get(route_id, stop_id, opts \\ []) do
schedules_fn = Keyword.get(opts, :schedules_fn, &Schedules.Repo.by_route_ids/2)
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.get(opts, :now, Util.now())
direction_id = Keyword.get(opts, :direction_id)
sort_fn = Keyword.get(opts, :sort_fn, &sort_predicted_schedules/1)
Expand Down
8 changes: 4 additions & 4 deletions test/predicted_schedule_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule PredictedScheduleTest do
alias Predictions.Prediction
import PredictedSchedule
import Mock
import Mox

# set to the end of a month to uncover issues with sorting times as
# structs, rather than as integers
Expand Down Expand Up @@ -174,9 +175,9 @@ defmodule PredictedScheduleTest do
end

test "attempts to return a list of predicted schedules for tomorrow, after no valid ones are left for today" do
predictions_fn = fn _opts ->
expect(Predictions.Repo.Mock, :all, fn _ ->
@trip_predictions
end
end)

schedules_fn = fn ["Teal"], _opts ->
@trip_schedules
Expand All @@ -186,8 +187,7 @@ defmodule PredictedScheduleTest do
group: fn _predictions, _schedules, _opts -> [] end do
get("Teal", "stop1",
now: Timex.shift(@base_time, minutes: 30),
schedules_fn: schedules_fn,
predictions_fn: predictions_fn
schedules_fn: schedules_fn
)

assert :meck.num_calls(PredictedSchedule, :group, :_) == 2
Expand Down

0 comments on commit 4a64af7

Please sign in to comment.