97 lines
2.9 KiB
Elixir
97 lines
2.9 KiB
Elixir
defmodule BeetRoundServerWeb.BiddingControllerTest do
|
|
use BeetRoundServerWeb.ConnCase
|
|
|
|
import BeetRoundServer.BiddingsFixtures
|
|
alias BeetRoundServer.Biddings.Bidding
|
|
|
|
@create_attrs %{
|
|
amount: 42,
|
|
bidding_round: 42,
|
|
depot_wish_one: "some depot_wish_one",
|
|
depot_wish_two: "some depot_wish_two"
|
|
}
|
|
@update_attrs %{
|
|
amount: 43,
|
|
bidding_round: 43,
|
|
depot_wish_one: "some updated depot_wish_one",
|
|
depot_wish_two: "some updated depot_wish_two"
|
|
}
|
|
@invalid_attrs %{amount: nil, bidding_round: nil, depot_wish_one: nil, depot_wish_two: nil}
|
|
|
|
setup %{conn: conn} do
|
|
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
|
end
|
|
|
|
describe "index" do
|
|
test "lists all biddings", %{conn: conn} do
|
|
conn = get(conn, ~p"/api/biddings")
|
|
assert json_response(conn, 200)["data"] == []
|
|
end
|
|
end
|
|
|
|
describe "create bidding" do
|
|
test "renders bidding when data is valid", %{conn: conn} do
|
|
conn = post(conn, ~p"/api/biddings", bidding: @create_attrs)
|
|
assert %{"id" => id} = json_response(conn, 201)["data"]
|
|
|
|
conn = get(conn, ~p"/api/biddings/#{id}")
|
|
|
|
assert %{
|
|
"id" => ^id,
|
|
"amount" => 42,
|
|
"bidding_round" => 42,
|
|
"depot_wish_one" => "some depot_wish_one",
|
|
"depot_wish_two" => "some depot_wish_two"
|
|
} = json_response(conn, 200)["data"]
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{conn: conn} do
|
|
conn = post(conn, ~p"/api/biddings", bidding: @invalid_attrs)
|
|
assert json_response(conn, 422)["errors"] != %{}
|
|
end
|
|
end
|
|
|
|
describe "update bidding" do
|
|
setup [:create_bidding]
|
|
|
|
test "renders bidding when data is valid", %{conn: conn, bidding: %Bidding{id: id} = bidding} do
|
|
conn = put(conn, ~p"/api/biddings/#{bidding}", bidding: @update_attrs)
|
|
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
|
|
|
conn = get(conn, ~p"/api/biddings/#{id}")
|
|
|
|
assert %{
|
|
"id" => ^id,
|
|
"amount" => 43,
|
|
"bidding_round" => 43,
|
|
"depot_wish_one" => "some updated depot_wish_one",
|
|
"depot_wish_two" => "some updated depot_wish_two"
|
|
} = json_response(conn, 200)["data"]
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{conn: conn, bidding: bidding} do
|
|
conn = put(conn, ~p"/api/biddings/#{bidding}", bidding: @invalid_attrs)
|
|
assert json_response(conn, 422)["errors"] != %{}
|
|
end
|
|
end
|
|
|
|
describe "delete bidding" do
|
|
setup [:create_bidding]
|
|
|
|
test "deletes chosen bidding", %{conn: conn, bidding: bidding} do
|
|
conn = delete(conn, ~p"/api/biddings/#{bidding}")
|
|
assert response(conn, 204)
|
|
|
|
assert_error_sent 404, fn ->
|
|
get(conn, ~p"/api/biddings/#{bidding}")
|
|
end
|
|
end
|
|
end
|
|
|
|
defp create_bidding(_) do
|
|
bidding = bidding_fixture()
|
|
|
|
%{bidding: bidding}
|
|
end
|
|
end
|