After "mix phx.gen.live Biddings Bidding biddings bidding_round:integer amount:integer depot_wish_one:string depot_wish_two:string".

This commit is contained in:
2026-02-11 16:14:19 +01:00
parent 7ad08fa91d
commit 2bec68b9ed
9 changed files with 677 additions and 0 deletions

View File

@ -0,0 +1,97 @@
defmodule BeetRoundServer.BiddingsTest do
use BeetRoundServer.DataCase
alias BeetRoundServer.Biddings
describe "biddings" do
alias BeetRoundServer.Biddings.Bidding
import BeetRoundServer.AccountsFixtures, only: [user_scope_fixture: 0]
import BeetRoundServer.BiddingsFixtures
@invalid_attrs %{amount: nil, bidding_round: nil, depot_wish_one: nil, depot_wish_two: nil}
test "list_biddings/1 returns all scoped biddings" do
scope = user_scope_fixture()
other_scope = user_scope_fixture()
bidding = bidding_fixture(scope)
other_bidding = bidding_fixture(other_scope)
assert Biddings.list_biddings(scope) == [bidding]
assert Biddings.list_biddings(other_scope) == [other_bidding]
end
test "get_bidding!/2 returns the bidding with given id" do
scope = user_scope_fixture()
bidding = bidding_fixture(scope)
other_scope = user_scope_fixture()
assert Biddings.get_bidding!(scope, bidding.id) == bidding
assert_raise Ecto.NoResultsError, fn -> Biddings.get_bidding!(other_scope, bidding.id) end
end
test "create_bidding/2 with valid data creates a bidding" do
valid_attrs = %{amount: 42, bidding_round: 42, depot_wish_one: "some depot_wish_one", depot_wish_two: "some depot_wish_two"}
scope = user_scope_fixture()
assert {:ok, %Bidding{} = bidding} = Biddings.create_bidding(scope, valid_attrs)
assert bidding.amount == 42
assert bidding.bidding_round == 42
assert bidding.depot_wish_one == "some depot_wish_one"
assert bidding.depot_wish_two == "some depot_wish_two"
assert bidding.user_id == scope.user.id
end
test "create_bidding/2 with invalid data returns error changeset" do
scope = user_scope_fixture()
assert {:error, %Ecto.Changeset{}} = Biddings.create_bidding(scope, @invalid_attrs)
end
test "update_bidding/3 with valid data updates the bidding" do
scope = user_scope_fixture()
bidding = bidding_fixture(scope)
update_attrs = %{amount: 43, bidding_round: 43, depot_wish_one: "some updated depot_wish_one", depot_wish_two: "some updated depot_wish_two"}
assert {:ok, %Bidding{} = bidding} = Biddings.update_bidding(scope, bidding, update_attrs)
assert bidding.amount == 43
assert bidding.bidding_round == 43
assert bidding.depot_wish_one == "some updated depot_wish_one"
assert bidding.depot_wish_two == "some updated depot_wish_two"
end
test "update_bidding/3 with invalid scope raises" do
scope = user_scope_fixture()
other_scope = user_scope_fixture()
bidding = bidding_fixture(scope)
assert_raise MatchError, fn ->
Biddings.update_bidding(other_scope, bidding, %{})
end
end
test "update_bidding/3 with invalid data returns error changeset" do
scope = user_scope_fixture()
bidding = bidding_fixture(scope)
assert {:error, %Ecto.Changeset{}} = Biddings.update_bidding(scope, bidding, @invalid_attrs)
assert bidding == Biddings.get_bidding!(scope, bidding.id)
end
test "delete_bidding/2 deletes the bidding" do
scope = user_scope_fixture()
bidding = bidding_fixture(scope)
assert {:ok, %Bidding{}} = Biddings.delete_bidding(scope, bidding)
assert_raise Ecto.NoResultsError, fn -> Biddings.get_bidding!(scope, bidding.id) end
end
test "delete_bidding/2 with invalid scope raises" do
scope = user_scope_fixture()
other_scope = user_scope_fixture()
bidding = bidding_fixture(scope)
assert_raise MatchError, fn -> Biddings.delete_bidding(other_scope, bidding) end
end
test "change_bidding/2 returns a bidding changeset" do
scope = user_scope_fixture()
bidding = bidding_fixture(scope)
assert %Ecto.Changeset{} = Biddings.change_bidding(scope, bidding)
end
end
end

View File

@ -0,0 +1,125 @@
defmodule BeetRoundServerWeb.BiddingLiveTest do
use BeetRoundServerWeb.ConnCase
import Phoenix.LiveViewTest
import BeetRoundServer.BiddingsFixtures
@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 :register_and_log_in_user
defp create_bidding(%{scope: scope}) do
bidding = bidding_fixture(scope)
%{bidding: bidding}
end
describe "Index" do
setup [:create_bidding]
test "lists all biddings", %{conn: conn, bidding: bidding} do
{:ok, _index_live, html} = live(conn, ~p"/biddings")
assert html =~ "Listing Biddings"
assert html =~ bidding.depot_wish_one
end
test "saves new bidding", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/biddings")
assert {:ok, form_live, _} =
index_live
|> element("a", "New Bidding")
|> render_click()
|> follow_redirect(conn, ~p"/biddings/new")
assert render(form_live) =~ "New Bidding"
assert form_live
|> form("#bidding-form", bidding: @invalid_attrs)
|> render_change() =~ "can't be blank"
assert {:ok, index_live, _html} =
form_live
|> form("#bidding-form", bidding: @create_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/biddings")
html = render(index_live)
assert html =~ "Bidding created successfully"
assert html =~ "some depot_wish_one"
end
test "updates bidding in listing", %{conn: conn, bidding: bidding} do
{:ok, index_live, _html} = live(conn, ~p"/biddings")
assert {:ok, form_live, _html} =
index_live
|> element("#biddings-#{bidding.id} a", "Edit")
|> render_click()
|> follow_redirect(conn, ~p"/biddings/#{bidding}/edit")
assert render(form_live) =~ "Edit Bidding"
assert form_live
|> form("#bidding-form", bidding: @invalid_attrs)
|> render_change() =~ "can't be blank"
assert {:ok, index_live, _html} =
form_live
|> form("#bidding-form", bidding: @update_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/biddings")
html = render(index_live)
assert html =~ "Bidding updated successfully"
assert html =~ "some updated depot_wish_one"
end
test "deletes bidding in listing", %{conn: conn, bidding: bidding} do
{:ok, index_live, _html} = live(conn, ~p"/biddings")
assert index_live |> element("#biddings-#{bidding.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#biddings-#{bidding.id}")
end
end
describe "Show" do
setup [:create_bidding]
test "displays bidding", %{conn: conn, bidding: bidding} do
{:ok, _show_live, html} = live(conn, ~p"/biddings/#{bidding}")
assert html =~ "Show Bidding"
assert html =~ bidding.depot_wish_one
end
test "updates bidding and returns to show", %{conn: conn, bidding: bidding} do
{:ok, show_live, _html} = live(conn, ~p"/biddings/#{bidding}")
assert {:ok, form_live, _} =
show_live
|> element("a", "Edit")
|> render_click()
|> follow_redirect(conn, ~p"/biddings/#{bidding}/edit?return_to=show")
assert render(form_live) =~ "Edit Bidding"
assert form_live
|> form("#bidding-form", bidding: @invalid_attrs)
|> render_change() =~ "can't be blank"
assert {:ok, show_live, _html} =
form_live
|> form("#bidding-form", bidding: @update_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/biddings/#{bidding}")
html = render(show_live)
assert html =~ "Bidding updated successfully"
assert html =~ "some updated depot_wish_one"
end
end
end

View File

@ -0,0 +1,22 @@
defmodule BeetRoundServer.BiddingsFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `BeetRoundServer.Biddings` context.
"""
@doc """
Generate a bidding.
"""
def bidding_fixture(scope, attrs \\ %{}) do
attrs =
Enum.into(attrs, %{
amount: 42,
bidding_round: 42,
depot_wish_one: "some depot_wish_one",
depot_wish_two: "some depot_wish_two"
})
{:ok, bidding} = BeetRoundServer.Biddings.create_bidding(scope, attrs)
bidding
end
end