From 50ac63c7644b68485a7803a73e7cc4bd8fb2ebcf Mon Sep 17 00:00:00 2001 From: Suresh-Krishna-P Date: Thu, 2 Apr 2026 19:23:19 +0530 Subject: [PATCH] Fixed Vote Schema Changeset Validation --- copi.owasp.org/lib/copi/cornucopia/vote.ex | 4 ++-- .../test/copi/cornucopia/vote_test.exs | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 copi.owasp.org/test/copi/cornucopia/vote_test.exs diff --git a/copi.owasp.org/lib/copi/cornucopia/vote.ex b/copi.owasp.org/lib/copi/cornucopia/vote.ex index 9cd451776..cb72deb18 100644 --- a/copi.owasp.org/lib/copi/cornucopia/vote.ex +++ b/copi.owasp.org/lib/copi/cornucopia/vote.ex @@ -12,7 +12,7 @@ defmodule Copi.Cornucopia.Vote do @doc false def changeset(vote, attrs) do vote - |> cast(attrs, []) - |> validate_required([]) + |> cast(attrs, [:dealt_card_id, :player_id]) + |> validate_required([:dealt_card_id, :player_id]) end end diff --git a/copi.owasp.org/test/copi/cornucopia/vote_test.exs b/copi.owasp.org/test/copi/cornucopia/vote_test.exs new file mode 100644 index 000000000..2be200ac3 --- /dev/null +++ b/copi.owasp.org/test/copi/cornucopia/vote_test.exs @@ -0,0 +1,22 @@ +defmodule Copi.Cornucopia.VoteTest do + use Copi.DataCase + + alias Copi.Cornucopia.Vote + + describe "votes" do + @valid_attrs %{dealt_card_id: 1, player_id: Ecto.ULID.generate()} + @invalid_attrs %{dealt_card_id: nil, player_id: nil} + + test "changeset with valid attributes" do + changeset = Vote.changeset(%Vote{}, @valid_attrs) + assert changeset.valid? + end + + test "changeset with invalid attributes" do + changeset = Vote.changeset(%Vote{}, @invalid_attrs) + refute changeset.valid? + assert "can't be blank" in errors_on(changeset).dealt_card_id + assert "can't be blank" in errors_on(changeset).player_id + end + end +end \ No newline at end of file