Repair tests for exchange rates/know tokens sorce by addind mock for headers function

pull/5613/head
Viktor Baranov 3 years ago
parent 207e4185cd
commit 93f202d437
  1. 2
      apps/explorer/lib/explorer/exchange_rates/source.ex
  2. 2
      apps/explorer/lib/explorer/known_tokens/source.ex
  3. 5
      apps/explorer/lib/explorer/known_tokens/source/my_ether_wallet.ex
  4. 2
      apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs
  5. 2
      apps/explorer/test/explorer/known_tokens/known_tokens_test.exs

@ -61,7 +61,7 @@ defmodule Explorer.ExchangeRates.Source do
@callback source_url(String.t()) :: String.t() | :ignore
@callback headers() :: [any]
@callback headers :: [any]
def headers do
[{"Content-Type", "application/json"}]

@ -19,6 +19,8 @@ defmodule Explorer.KnownTokens.Source do
"""
@callback source_url() :: String.t()
@callback headers() :: [any()]
@spec known_tokens_source() :: module()
defp known_tokens_source do
config(:source) || Explorer.KnownTokens.Source.MyEtherWallet

@ -11,4 +11,9 @@ defmodule Explorer.KnownTokens.Source.MyEtherWallet do
def source_url do
"https://raw.githubusercontent.com/kvhnuke/etherwallet/mercury/app/scripts/tokens/ethTokens.json"
end
@impl Source
def headers do
[]
end
end

@ -54,6 +54,7 @@ defmodule Explorer.ExchangeRatesTest do
state = %{}
expect(TestSource, :format_data, fn _ -> [Token.null()] end)
expect(TestSource, :headers, fn -> [] end)
set_mox_global()
assert {:noreply, ^state} = ExchangeRates.handle_info(:update, state)
@ -102,6 +103,7 @@ defmodule Explorer.ExchangeRatesTest do
state = %{}
expect(TestSource, :format_data, fn _ -> [Token.null()] end)
expect(TestSource, :headers, fn -> [] end)
set_mox_global()
assert {:noreply, ^state} = ExchangeRates.handle_info({nil, {:error, "some error"}}, state)

@ -51,6 +51,7 @@ defmodule Explorer.KnownTokensTest do
end)
stub(TestSource, :source_url, fn -> "http://localhost:#{bypass.port}" end)
stub(TestSource, :headers, fn -> [] end)
KnownTokens.init([])
state = %{}
@ -89,6 +90,7 @@ defmodule Explorer.KnownTokensTest do
end)
stub(TestSource, :source_url, fn -> "http://localhost:#{bypass.port}" end)
stub(TestSource, :headers, fn -> [] end)
state = %{}

Loading…
Cancel
Save