add response bodies

pull/1596/head
Ayrat Badykov 6 years ago
parent ead333610c
commit 3ef8293ded
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex
  2. 3
      apps/block_scout_web/test/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller_test.exs

@ -9,13 +9,13 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do
with :ok <- validate_address_hash(params["address_hash"]) do with :ok <- validate_address_hash(params["address_hash"]) do
case Chain.create_decompiled_smart_contract(params) do case Chain.create_decompiled_smart_contract(params) do
{:ok, _decompiled_source_code} -> {:ok, _decompiled_source_code} ->
send_resp(conn, :created, "") send_resp(conn, :created, "ok")
{:error, _changeset} -> {:error, _changeset} ->
send_resp(conn, :unprocessable_entity, "") send_resp(conn, :unprocessable_entity, "error")
end end
else else
:error -> send_resp(conn, :unprocessable_entity, "") :error -> send_resp(conn, :unprocessable_entity, "error")
end end
else else
send_resp(conn, :forbidden, "") send_resp(conn, :forbidden, "")

@ -22,6 +22,7 @@ defmodule BlockScoutWeb.API.V1.DecompiledControllerTest do
request = post(conn, api_v1_decompiled_smart_contract_path(conn, :create)) request = post(conn, api_v1_decompiled_smart_contract_path(conn, :create))
assert request.status == 422 assert request.status == 422
assert request.resp_body == "error"
end end
test "returns unprocessable_entity when address_hash is invalid", %{conn: conn} do test "returns unprocessable_entity when address_hash is invalid", %{conn: conn} do
@ -37,6 +38,7 @@ defmodule BlockScoutWeb.API.V1.DecompiledControllerTest do
request = post(conn, api_v1_decompiled_smart_contract_path(conn, :create), params) request = post(conn, api_v1_decompiled_smart_contract_path(conn, :create), params)
assert request.status == 422 assert request.status == 422
assert request.resp_body == "error"
end end
test "creates decompiled smart contract", %{conn: conn} do test "creates decompiled smart contract", %{conn: conn} do
@ -53,6 +55,7 @@ defmodule BlockScoutWeb.API.V1.DecompiledControllerTest do
request = post(conn, api_v1_decompiled_smart_contract_path(conn, :create), params) request = post(conn, api_v1_decompiled_smart_contract_path(conn, :create), params)
assert request.status == 201 assert request.status == 201
assert request.resp_body == "ok"
decompiled_smart_contract = Repo.one!(from(d in DecompiledSmartContract, where: d.address_hash == ^address_hash)) decompiled_smart_contract = Repo.one!(from(d in DecompiledSmartContract, where: d.address_hash == ^address_hash))
assert to_string(decompiled_smart_contract.address_hash) == address_hash assert to_string(decompiled_smart_contract.address_hash) == address_hash

Loading…
Cancel
Save