|
|
@ -18,34 +18,6 @@ defmodule Explorer.ExchangeRates.Source.CoinGeckoTest do |
|
|
|
} |
|
|
|
} |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
@json_mkt_data """ |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"id": "poa-network", |
|
|
|
|
|
|
|
"symbol": "poa", |
|
|
|
|
|
|
|
"name": "POA Network", |
|
|
|
|
|
|
|
"image": "https://assets.coingecko.com/coins/images/3157/large/poa.jpg?1520829019", |
|
|
|
|
|
|
|
"current_price": 0.114782883773693, |
|
|
|
|
|
|
|
"market_cap": 25248999.6735956, |
|
|
|
|
|
|
|
"market_cap_rank": 185, |
|
|
|
|
|
|
|
"total_volume": 2344442.13578437, |
|
|
|
|
|
|
|
"high_24h": 0.115215129840519, |
|
|
|
|
|
|
|
"low_24h": 0.101039753612939, |
|
|
|
|
|
|
|
"price_change_24h": 0.0135970966607094, |
|
|
|
|
|
|
|
"price_change_percentage_24h": 13.437753511298, |
|
|
|
|
|
|
|
"market_cap_change_24h": 3058195.58191147, |
|
|
|
|
|
|
|
"market_cap_change_percentage_24h": 13.7813644304017, |
|
|
|
|
|
|
|
"circulating_supply": "219935174.0", |
|
|
|
|
|
|
|
"total_supply": 252193195, |
|
|
|
|
|
|
|
"ath": 0.935923393359191, |
|
|
|
|
|
|
|
"ath_change_percentage": -87.731057963078, |
|
|
|
|
|
|
|
"ath_date": "2018-05-10T09:45:31.809Z", |
|
|
|
|
|
|
|
"roi": null, |
|
|
|
|
|
|
|
"last_updated": "2018-10-23T01:25:31.764Z" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "format_data/1" do |
|
|
|
describe "format_data/1" do |
|
|
|
setup do |
|
|
|
setup do |
|
|
|
bypass = Bypass.open() |
|
|
|
bypass = Bypass.open() |
|
|
@ -59,31 +31,30 @@ defmodule Explorer.ExchangeRates.Source.CoinGeckoTest do |
|
|
|
Conn.resp(conn, 200, @json_btc_price) |
|
|
|
Conn.resp(conn, 200, @json_btc_price) |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
{:ok, expected_date, 0} = "2018-10-23T01:25:31.764Z" |> DateTime.from_iso8601() |
|
|
|
json_data = |
|
|
|
|
|
|
|
"#{File.cwd!()}/test/support/fixture/exchange_rates/coin_gecko.json" |
|
|
|
|
|
|
|
|> File.read!() |
|
|
|
|
|
|
|
|> Jason.decode!() |
|
|
|
|
|
|
|
|
|
|
|
expected = [ |
|
|
|
expected = [ |
|
|
|
%Token{ |
|
|
|
%Token{ |
|
|
|
available_supply: Decimal.new("252193195"), |
|
|
|
available_supply: Decimal.new("220167621.0"), |
|
|
|
total_supply: Decimal.new("252193195"), |
|
|
|
total_supply: Decimal.new("252193195.0"), |
|
|
|
btc_value: Decimal.new("0.00001753101509231471092879666458"), |
|
|
|
btc_value: Decimal.new("0.000002055310963802830367634997491"), |
|
|
|
id: "poa-network", |
|
|
|
id: "poa-network", |
|
|
|
last_updated: expected_date, |
|
|
|
last_updated: ~U[2019-08-21 08:36:49.371Z], |
|
|
|
market_cap_usd: Decimal.new("25248999.6735956"), |
|
|
|
market_cap_usd: Decimal.new("2962791"), |
|
|
|
name: "POA Network", |
|
|
|
name: "POA Network", |
|
|
|
symbol: "poa", |
|
|
|
symbol: "POA", |
|
|
|
usd_value: Decimal.new("0.114782883773693"), |
|
|
|
usd_value: Decimal.new("0.01345698"), |
|
|
|
volume_24h_usd: Decimal.new("2344442.13578437") |
|
|
|
volume_24h_usd: Decimal.new("119946") |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
assert expected == CoinGecko.format_data(@json_mkt_data) |
|
|
|
assert expected == CoinGecko.format_data(json_data) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "returns nothing when given bad data", %{bypass: bypass} do |
|
|
|
test "returns nothing when given bad data" do |
|
|
|
Bypass.expect(bypass, "GET", "/exchange_rates", fn conn -> |
|
|
|
|
|
|
|
Conn.resp(conn, 200, @json_btc_price) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bad_data = """ |
|
|
|
bad_data = """ |
|
|
|
[{"id": "poa-network"}] |
|
|
|
[{"id": "poa-network"}] |
|
|
|
""" |
|
|
|
""" |
|
|
|