Add better quality test coverage for formatter functions

Remove redundant function declaration since nil is already handled
pull/202/head
Tim Mecklem 7 years ago
parent 180f84e266
commit d83c69c004
  1. 2
      apps/explorer_web/lib/explorer_web/views/chain_view.ex
  2. 30
      apps/explorer_web/test/explorer_web/views/chain_view_test.exs

@ -14,8 +14,6 @@ defmodule ExplorerWeb.ChainView do
end
end
def format_exchange_rate(%Token{usd_value: nil}), do: nil
def format_exchange_rate(%Token{usd_value: usd_value}) do
usd_value
|> USD.from()

@ -1,3 +1,33 @@
defmodule ExplorerWeb.ChainViewTest do
use ExplorerWeb.ConnCase, async: true
alias Explorer.ExchangeRates.Token
alias ExplorerWeb.ChainView
describe "format_exchange_rate/1" do
test "returns a formatted usd value from a `Token`'s usd_value" do
token = %Token{usd_value: Decimal.new(5.45)}
assert "$5.45 USD" == ChainView.format_exchange_rate(token)
assert nil == ChainView.format_exchange_rate(%Token{usd_value: nil})
end
end
describe "format_volume_24h/1" do
test "returns a formatted usd value from a `Token`'s volume_24h_usd" do
token = %Token{volume_24h_usd: Decimal.new(5.456)}
assert "$5.456 USD" == ChainView.format_volume_24h(token)
assert nil == ChainView.format_volume_24h(%Token{volume_24h_usd: nil})
end
end
describe "format_market_cap/1" do
test "returns a formatted usd value from a `Token`'s market_cap_usd" do
token = %Token{market_cap_usd: Decimal.new(5.4)}
assert "$5.40 USD" == ChainView.format_market_cap(token)
assert nil == ChainView.format_market_cap(%Token{market_cap_usd: nil})
end
end
end

Loading…
Cancel
Save