After "mix phx.gen.json BiddingRounds BiddingRound bidding_rounds round_number:integer running:boolean --no-scope".
This commit is contained in:
61
test/beet_round_server/bidding_rounds_test.exs
Normal file
61
test/beet_round_server/bidding_rounds_test.exs
Normal file
@ -0,0 +1,61 @@
|
||||
defmodule BeetRoundServer.BiddingRoundsTest do
|
||||
use BeetRoundServer.DataCase
|
||||
|
||||
alias BeetRoundServer.BiddingRounds
|
||||
|
||||
describe "bidding_rounds" do
|
||||
alias BeetRoundServer.BiddingRounds.BiddingRound
|
||||
|
||||
import BeetRoundServer.BiddingRoundsFixtures
|
||||
|
||||
@invalid_attrs %{running: nil, round_number: nil}
|
||||
|
||||
test "list_bidding_rounds/0 returns all bidding_rounds" do
|
||||
bidding_round = bidding_round_fixture()
|
||||
assert BiddingRounds.list_bidding_rounds() == [bidding_round]
|
||||
end
|
||||
|
||||
test "get_bidding_round!/1 returns the bidding_round with given id" do
|
||||
bidding_round = bidding_round_fixture()
|
||||
assert BiddingRounds.get_bidding_round!(bidding_round.id) == bidding_round
|
||||
end
|
||||
|
||||
test "create_bidding_round/1 with valid data creates a bidding_round" do
|
||||
valid_attrs = %{running: true, round_number: 42}
|
||||
|
||||
assert {:ok, %BiddingRound{} = bidding_round} = BiddingRounds.create_bidding_round(valid_attrs)
|
||||
assert bidding_round.running == true
|
||||
assert bidding_round.round_number == 42
|
||||
end
|
||||
|
||||
test "create_bidding_round/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = BiddingRounds.create_bidding_round(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_bidding_round/2 with valid data updates the bidding_round" do
|
||||
bidding_round = bidding_round_fixture()
|
||||
update_attrs = %{running: false, round_number: 43}
|
||||
|
||||
assert {:ok, %BiddingRound{} = bidding_round} = BiddingRounds.update_bidding_round(bidding_round, update_attrs)
|
||||
assert bidding_round.running == false
|
||||
assert bidding_round.round_number == 43
|
||||
end
|
||||
|
||||
test "update_bidding_round/2 with invalid data returns error changeset" do
|
||||
bidding_round = bidding_round_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = BiddingRounds.update_bidding_round(bidding_round, @invalid_attrs)
|
||||
assert bidding_round == BiddingRounds.get_bidding_round!(bidding_round.id)
|
||||
end
|
||||
|
||||
test "delete_bidding_round/1 deletes the bidding_round" do
|
||||
bidding_round = bidding_round_fixture()
|
||||
assert {:ok, %BiddingRound{}} = BiddingRounds.delete_bidding_round(bidding_round)
|
||||
assert_raise Ecto.NoResultsError, fn -> BiddingRounds.get_bidding_round!(bidding_round.id) end
|
||||
end
|
||||
|
||||
test "change_bidding_round/1 returns a bidding_round changeset" do
|
||||
bidding_round = bidding_round_fixture()
|
||||
assert %Ecto.Changeset{} = BiddingRounds.change_bidding_round(bidding_round)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,88 @@
|
||||
defmodule BeetRoundServerWeb.BiddingRoundControllerTest do
|
||||
use BeetRoundServerWeb.ConnCase
|
||||
|
||||
import BeetRoundServer.BiddingRoundsFixtures
|
||||
alias BeetRoundServer.BiddingRounds.BiddingRound
|
||||
|
||||
@create_attrs %{
|
||||
running: true,
|
||||
round_number: 42
|
||||
}
|
||||
@update_attrs %{
|
||||
running: false,
|
||||
round_number: 43
|
||||
}
|
||||
@invalid_attrs %{running: nil, round_number: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all bidding_rounds", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/bidding_rounds")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create bidding_round" do
|
||||
test "renders bidding_round when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/bidding_rounds", bidding_round: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/bidding_rounds/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"round_number" => 42,
|
||||
"running" => true
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/bidding_rounds", bidding_round: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update bidding_round" do
|
||||
setup [:create_bidding_round]
|
||||
|
||||
test "renders bidding_round when data is valid", %{conn: conn, bidding_round: %BiddingRound{id: id} = bidding_round} do
|
||||
conn = put(conn, ~p"/api/bidding_rounds/#{bidding_round}", bidding_round: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/bidding_rounds/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"round_number" => 43,
|
||||
"running" => false
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, bidding_round: bidding_round} do
|
||||
conn = put(conn, ~p"/api/bidding_rounds/#{bidding_round}", bidding_round: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete bidding_round" do
|
||||
setup [:create_bidding_round]
|
||||
|
||||
test "deletes chosen bidding_round", %{conn: conn, bidding_round: bidding_round} do
|
||||
conn = delete(conn, ~p"/api/bidding_rounds/#{bidding_round}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/bidding_rounds/#{bidding_round}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_bidding_round(_) do
|
||||
bidding_round = bidding_round_fixture()
|
||||
|
||||
%{bidding_round: bidding_round}
|
||||
end
|
||||
end
|
||||
21
test/support/fixtures/bidding_rounds_fixtures.ex
Normal file
21
test/support/fixtures/bidding_rounds_fixtures.ex
Normal file
@ -0,0 +1,21 @@
|
||||
defmodule BeetRoundServer.BiddingRoundsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `BeetRoundServer.BiddingRounds` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a bidding_round.
|
||||
"""
|
||||
def bidding_round_fixture(attrs \\ %{}) do
|
||||
{:ok, bidding_round} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
round_number: 42,
|
||||
running: true
|
||||
})
|
||||
|> BeetRoundServer.BiddingRounds.create_bidding_round()
|
||||
|
||||
bidding_round
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user