fix address_token_controller tests

pull/2012/head
Ayrat Badykov 6 years ago
parent 2b278387b6
commit 286ec31376
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex
  2. 44
      apps/block_scout_web/test/block_scout_web/controllers/address_token_controller_test.exs

@ -67,6 +67,12 @@ defmodule BlockScoutWeb.AddressTokenController do
transaction_count: transaction_count(address), transaction_count: transaction_count(address),
validation_count: validation_count(address) validation_count: validation_count(address)
) )
else
:error ->
unprocessable_entity(conn)
{:error, :not_found} ->
not_found(conn)
end end
end end
end end

@ -57,15 +57,15 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
to_address: address to_address: address
) )
conn = get(conn, address_token_path(conn, :index, address)) conn = get(conn, address_token_path(conn, :index, address), type: "JSON")
actual_token_hashes = {:ok, %{"items" => items}} =
conn.assigns.tokens conn.resp_body
|> Enum.map(& &1.contract_address_hash) |> Poison.decode()
assert html_response(conn, 200) assert json_response(conn, 200)
assert Enum.member?(actual_token_hashes, token1.contract_address_hash) assert Enum.any?(items, fn item -> String.contains?(item, to_string(token1.contract_address_hash)) end)
refute Enum.member?(actual_token_hashes, token2.contract_address_hash) refute Enum.any?(items, fn item -> String.contains?(item, to_string(token2.contract_address_hash)) end)
end end
test "returns next page of results based on last seen token", %{conn: conn} do test "returns next page of results based on last seen token", %{conn: conn} do
@ -102,15 +102,17 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash), %{ get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash), %{
"token_name" => name, "token_name" => name,
"token_type" => type, "token_type" => type,
"token_inserted_at" => inserted_at "token_inserted_at" => inserted_at,
"type" => "JSON"
}) })
actual_tokens = {:ok, %{"items" => items}} =
conn.assigns.tokens conn.resp_body
|> Enum.map(& &1.name) |> Poison.decode()
|> Enum.sort()
assert second_page_tokens == actual_tokens assert Enum.any?(items, fn item ->
Enum.any?(second_page_tokens, fn token_name -> String.contains?(item, token_name) end)
end)
end end
test "next_page_params exists if not on last page", %{conn: conn} do test "next_page_params exists if not on last page", %{conn: conn} do
@ -129,9 +131,13 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
insert(:token_transfer, token_contract_address: token.contract_address, from_address: address) insert(:token_transfer, token_contract_address: token.contract_address, from_address: address)
end) end)
conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash)) conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash), type: "JSON")
{:ok, %{"next_page_path" => next_page_path}} =
conn.resp_body
|> Poison.decode()
assert conn.assigns.next_page_params assert 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
@ -139,9 +145,13 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
token = insert(:token) token = insert(:token)
insert(:token_transfer, token_contract_address: token.contract_address, from_address: address) insert(:token_transfer, token_contract_address: token.contract_address, from_address: address)
conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash)) conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash), type: "JSON")
{:ok, %{"next_page_path" => next_page_path}} =
conn.resp_body
|> Poison.decode()
refute conn.assigns.next_page_params refute next_page_path
end end
end end
end end

Loading…
Cancel
Save