-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4c1cf8
commit 36b5b3d
Showing
2 changed files
with
77 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
defmodule Transport.DataCheckerTest do | ||
use ExUnit.Case, async: true | ||
import Mox | ||
|
||
import Transport.DataChecker, only: [compute_gbfs_feed_meta: 1] | ||
|
||
@gbfs_url "https://example.com/gbfs.json" | ||
|
||
setup :verify_on_exit! | ||
|
||
describe "Compute GBFS metadata for a feed" do | ||
test "on invalid jcdecaux response" do | ||
setup_gbfs_response() | ||
setup_system_information_response() | ||
setup_station_information_response() | ||
|
||
expected = %{ | ||
languages: ["fr"], | ||
system_details: %{name: "velhop", timezone: "Europe/Paris"}, | ||
ttl: 3600, | ||
types: ["stations"], | ||
versions: ["1.1"] | ||
} | ||
|
||
assert expected == compute_gbfs_feed_meta(%DB.Resource{url: @gbfs_url}) | ||
end | ||
end | ||
|
||
defp setup_response(expected_url, body) do | ||
Transport.HTTPoison.Mock | ||
|> expect(:get, fn url -> | ||
assert url == expected_url | ||
|
||
{:ok, | ||
%HTTPoison.Response{ | ||
status_code: 200, | ||
body: body, | ||
headers: [{"Content-Type", "application/json"}] | ||
}} | ||
end) | ||
end | ||
|
||
defp setup_gbfs_response do | ||
body = """ | ||
{"data":{"fr":{"feeds":[{"name":"system_information","url":"https://example.com/system_information.json"},{"name":"station_information","url":"https://example.com/station_information.json"},{"name":"station_status","url":"https://example.com/station_status.json"}]}},"last_updated":1636116464,"ttl":3600,"version":"1.1"} | ||
""" | ||
|
||
setup_response(@gbfs_url, body) | ||
end | ||
|
||
defp setup_system_information_response do | ||
body = """ | ||
{"data":{"language":"fr","name":"velhop","system_id":"strasbourg","timezone":"Europe/Paris"},"last_updated":1636116522,"ttl":3600,"version":"1.1"} | ||
""" | ||
|
||
setup_response("https://example.com/system_information.json", body) | ||
end | ||
|
||
defp setup_station_information_response do | ||
body = """ | ||
{"data":{"stations":[{"capacity":16,"lat":48.568644,"lon":7.795621,"name":"124 Auberge de jeunesse","rental_method":"CREDIT_CARD","station_id":"124"}]},"last_updated":1636116909,"ttl":3600,"version":"1.1"} | ||
""" | ||
|
||
setup_response("https://example.com/station_information.json", body) | ||
end | ||
end |