Add tests and require that address and transaction hashes are validpull/232/head
parent
b0fd53bc06
commit
32f29f8cea
@ -1,7 +1,15 @@ |
||||
defmodule ExplorerWeb.AddressQRCodeController do |
||||
use ExplorerWeb, :controller |
||||
|
||||
alias Explorer.Chain.Hash.Truncated |
||||
|
||||
def index(conn, %{"address_id" => id}) do |
||||
case Truncated.cast(id) do |
||||
{:ok, _} -> |
||||
send_download(conn, {:binary, QRCode.to_png(id)}, "content-type": "image/png", filename: "#{id}.png") |
||||
|
||||
_ -> |
||||
send_resp(conn, :not_found, "") |
||||
end |
||||
end |
||||
end |
||||
|
@ -0,0 +1,15 @@ |
||||
defmodule ExplorerWeb.TransactionQRCodeController do |
||||
use ExplorerWeb, :controller |
||||
|
||||
alias Explorer.Chain.Hash.Full |
||||
|
||||
def index(conn, %{"transaction_id" => id}) do |
||||
case Full.cast(id) do |
||||
{:ok, _} -> |
||||
send_download(conn, {:binary, QRCode.to_png(id)}, "content-type": "image/png", filename: "#{id}.png") |
||||
|
||||
_ -> |
||||
send_resp(conn, :not_found, "") |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,19 @@ |
||||
defmodule ExplorerWeb.AddressQRCodeControllerTest do |
||||
use ExplorerWeb.ConnCase |
||||
|
||||
import ExplorerWeb.Router.Helpers, only: [address_qr_code_path: 4] |
||||
|
||||
describe "GET index/3" do |
||||
test "with valid address hash returns a QR code", %{conn: conn} do |
||||
conn = get(conn, address_qr_code_path(conn, :index, :en, address_hash())) |
||||
|
||||
assert response(conn, 200) |
||||
end |
||||
|
||||
test "with invalid address hash returns 404", %{conn: conn} do |
||||
conn = get(conn, address_qr_code_path(conn, :index, :en, "0xhaha")) |
||||
|
||||
assert response(conn, 404) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,19 @@ |
||||
defmodule ExplorerWeb.TransactionQRCodeControllerTest do |
||||
use ExplorerWeb.ConnCase |
||||
|
||||
import ExplorerWeb.Router.Helpers, only: [transaction_qr_code_path: 4] |
||||
|
||||
describe "GET index/3" do |
||||
test "with valid `Hash.Full` returns a QR code", %{conn: conn} do |
||||
conn = get(conn, transaction_qr_code_path(conn, :index, :en, transaction_hash())) |
||||
|
||||
assert response(conn, 200) |
||||
end |
||||
|
||||
test "with invalid address hash returns 404", %{conn: conn} do |
||||
conn = get(conn, transaction_qr_code_path(conn, :index, :en, "0xhaha")) |
||||
|
||||
assert response(conn, 404) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue