Fix controller tests

pull/1137/head
Felipe Renan 6 years ago
parent c3eec565d0
commit 87579dfd63
  1. 43
      apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs

@ -1,7 +1,7 @@
defmodule BlockScoutWeb.AddressTransactionControllerTest do defmodule BlockScoutWeb.AddressTransactionControllerTest do
use BlockScoutWeb.ConnCase use BlockScoutWeb.ConnCase
import BlockScoutWeb.Router.Helpers, only: [address_transaction_path: 3] import BlockScoutWeb.Router.Helpers, only: [address_transaction_path: 3, address_transaction_path: 4]
alias Explorer.Chain.{Block, Transaction} alias Explorer.Chain.{Block, Transaction}
alias Explorer.ExchangeRates.Token alias Explorer.ExchangeRates.Token
@ -34,11 +34,14 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(to_address: address) |> insert(to_address: address)
|> with_block(block) |> with_block(block)
conn = get(conn, address_transaction_path(conn, :index, address)) conn = get(conn, address_transaction_path(conn, :index, address, %{"type" => "JSON"}))
transactions_hashes = Enum.map(conn.assigns.transactions, &Map.get(&1, :hash)) transaction_tiles = json_response(conn, 200)["items"]
transaction_hashes = Enum.map([to_transaction.hash, from_transaction.hash], &to_string(&1))
assert transactions_hashes == [to_transaction.hash, from_transaction.hash] assert Enum.all?(transaction_hashes, fn transaction_hash ->
Enum.any?(transaction_tiles, &String.contains?(&1, transaction_hash))
end)
end end
test "includes USD exchange rate value for address in assigns", %{conn: conn} do test "includes USD exchange rate value for address in assigns", %{conn: conn} do
@ -66,15 +69,15 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
conn = conn =
get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{ get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{
"block_number" => Integer.to_string(block_number), "block_number" => Integer.to_string(block_number),
"index" => Integer.to_string(index) "index" => Integer.to_string(index),
"type" => "JSON"
}) })
actual_hashes = transaction_tiles = json_response(conn, 200)["items"]
conn.assigns.transactions
|> Enum.reverse()
|> Enum.map(& &1.hash)
assert second_page_hashes == actual_hashes assert Enum.all?(second_page_hashes, fn address_hash ->
Enum.any?(transaction_tiles, &String.contains?(&1, to_string(address_hash)))
end)
end end
test "next_page_params exist if not on last page", %{conn: conn} do test "next_page_params exist if not on last page", %{conn: conn} do
@ -85,15 +88,9 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert_list(:transaction, from_address: address) |> insert_list(:transaction, from_address: address)
|> with_block(block) |> with_block(block)
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash)) conn = get(conn, address_transaction_path(conn, :index, address.hash, %{"type" => "JSON"}))
expected_next_page_params = %{
"address_id" => to_string(address.hash),
"block_number" => number,
"index" => 10
}
assert conn.assigns.next_page_params == expected_next_page_params assert json_response(conn, 200)["next_page_path"]
end end
test "next_page_params are empty if on last page", %{conn: conn} do test "next_page_params are empty if on last page", %{conn: conn} do
@ -103,9 +100,9 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(from_address: address) |> insert(from_address: address)
|> with_block() |> with_block()
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash)) conn = get(conn, address_transaction_path(conn, :index, address.hash, %{"type" => "JSON"}))
refute conn.assigns.next_page_params refute json_response(conn, 200)["next_page_path"]
end end
test "returns parent transaction for a contract address", %{conn: conn} do test "returns parent transaction for a contract address", %{conn: conn} do
@ -128,9 +125,11 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
conn = get(conn, address_transaction_path(conn, :index, address), %{"type" => "JSON"}) conn = get(conn, address_transaction_path(conn, :index, address), %{"type" => "JSON"})
transaction_hashes = Enum.map(conn.assigns.transactions, & &1.hash) transaction_tiles = json_response(conn, 200)["items"]
assert [transaction.hash] == transaction_hashes assert Enum.all?([transaction.hash], fn transaction_hash ->
Enum.any?(transaction_tiles, &String.contains?(&1, to_string(transaction_hash)))
end)
end end
end end
end end

Loading…
Cancel
Save