fix CoinGecko tests

pull/2610/head
Ayrat Badykov 5 years ago
parent 8bae16459a
commit c563ee3638
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 5
      apps/explorer/lib/explorer/exchange_rates/source/coin_gecko.ex
  2. 57
      apps/explorer/test/explorer/exchange_rates/source/coin_gecko_test.exs

@ -11,7 +11,7 @@ defmodule Explorer.ExchangeRates.Source.CoinGecko do
@behaviour Source
@impl Source
def format_data(data) do
def format_data(%{"market_data" => _} = data) do
{:ok, price} = get_btc_price()
btc_price = to_decimal(price)
@ -41,6 +41,9 @@ defmodule Explorer.ExchangeRates.Source.CoinGecko do
]
end
@impl Source
def format_data(_), do: []
@impl Source
def source_url do
"#{base_url()}/coins/#{coin_id()}"

@ -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
setup do
bypass = Bypass.open()
@ -59,31 +31,30 @@ defmodule Explorer.ExchangeRates.Source.CoinGeckoTest do
Conn.resp(conn, 200, @json_btc_price)
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 = [
%Token{
available_supply: Decimal.new("252193195"),
total_supply: Decimal.new("252193195"),
btc_value: Decimal.new("0.00001753101509231471092879666458"),
available_supply: Decimal.new("220167621.0"),
total_supply: Decimal.new("252193195.0"),
btc_value: Decimal.new("0.000002055310963802830367634997491"),
id: "poa-network",
last_updated: expected_date,
market_cap_usd: Decimal.new("25248999.6735956"),
last_updated: ~U[2019-08-21 08:36:49.371Z],
market_cap_usd: Decimal.new("2962791"),
name: "POA Network",
symbol: "poa",
usd_value: Decimal.new("0.114782883773693"),
volume_24h_usd: Decimal.new("2344442.13578437")
symbol: "POA",
usd_value: Decimal.new("0.01345698"),
volume_24h_usd: Decimal.new("119946")
}
]
assert expected == CoinGecko.format_data(@json_mkt_data)
assert expected == CoinGecko.format_data(json_data)
end
test "returns nothing when given bad data", %{bypass: bypass} do
Bypass.expect(bypass, "GET", "/exchange_rates", fn conn ->
Conn.resp(conn, 200, @json_btc_price)
end)
test "returns nothing when given bad data" do
bad_data = """
[{"id": "poa-network"}]
"""

Loading…
Cancel
Save