Skip to content

Commit

Permalink
Added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
kotva006 committed May 3, 2024
1 parent d46c3fa commit 74bae7d
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/predictions/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Predictions.RepoTest do
use ExUnit.Case, async: false
@moduletag :external

import Mock
import Mox

alias Predictions.Repo
Expand Down Expand Up @@ -58,6 +59,67 @@ defmodule Predictions.RepoTest do
end
end

test "filtes out predictions with no departure" do
five_minutes_in_future = DateTime.add(Timex.now(), 5, :minute)

{:ok, five_minutes_in_future_string} =
Timex.format(five_minutes_in_future, "{ISO:Extended:Z}")

expect(MBTA.Api.Mock, :get_json, fn _, _ ->
%JsonApi{
data: [
%JsonApi.Item{
attributes: %{
"departure_time" => nil,
"arrival_time" => five_minutes_in_future_string,
"direction_id" => 1
},
relationships: %{
"route" => [
%{
id: "Red"
}
],
"trip" => [],
"vehicle" => [],
"stop" => [
%{id: "StopID"}
]
}
},
%JsonApi.Item{
attributes: %{
"departure_time" => five_minutes_in_future_string,
"arrival_time" => five_minutes_in_future_string,
"direction_id" => 1
},
relationships: %{
"route" => [
%{
id: "Red"
}
],
"trip" => [],
"vehicle" => [],
"stop" => [
%{id: "StopID"}
]
}
}
]
}
end)

with_mocks([
{Stops.Repo, [:passthrough], get_parent: fn _ -> %Stops.Stop{id: "Parent"} end},
{Routes.Repo, [:passthrough], get: fn _ -> Routes.MockRepoApi.get("Red") end}
]) do
predictions = Repo.all(route: "39")

assert Kernel.length(predictions) == 1
end
end

test "returns a list even if the server is down" do
expect(MBTA.Api.Mock, :get_json, fn _, _ ->
{:error, %HTTPoison.Error{reason: :econnrefused}}
Expand Down

0 comments on commit 74bae7d

Please sign in to comment.