fix: Allow optional email values in custom fields
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e9290b7156
commit
2b3c94d3b2
3 changed files with 42 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Mv.Membership.CustomFieldValidationTest do
|
||||
@moduledoc """
|
||||
Tests for CustomField validation constraints.
|
||||
|
||||
|
||||
Tests cover:
|
||||
- Name length validation (max 100 characters)
|
||||
- Name trimming
|
||||
|
|
@ -203,4 +203,3 @@ defmodule Mv.Membership.CustomFieldValidationTest do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Mv.Membership.CustomFieldValueValidationTest do
|
||||
@moduledoc """
|
||||
Tests for CustomFieldValue validation constraints.
|
||||
|
||||
|
||||
Tests cover:
|
||||
- String value length validation (max 10,000 characters)
|
||||
- String value trimming
|
||||
|
|
@ -184,6 +184,36 @@ defmodule Mv.Membership.CustomFieldValueValidationTest do
|
|||
end
|
||||
|
||||
describe "email value validation" do
|
||||
test "accepts nil value (optional field)", %{member: member, email_field: email_field} do
|
||||
assert {:ok, custom_field_value} =
|
||||
CustomFieldValue
|
||||
|> Ash.Changeset.for_create(:create, %{
|
||||
member_id: member.id,
|
||||
custom_field_id: email_field.id,
|
||||
value: %{"_union_type" => "email", "_union_value" => nil}
|
||||
})
|
||||
|> Ash.create()
|
||||
|
||||
assert custom_field_value.value.value == nil
|
||||
end
|
||||
|
||||
test "accepts empty string (becomes nil after trim)", %{
|
||||
member: member,
|
||||
email_field: email_field
|
||||
} do
|
||||
assert {:ok, custom_field_value} =
|
||||
CustomFieldValue
|
||||
|> Ash.Changeset.for_create(:create, %{
|
||||
member_id: member.id,
|
||||
custom_field_id: email_field.id,
|
||||
value: %{"_union_type" => "email", "_union_value" => ""}
|
||||
})
|
||||
|> Ash.create()
|
||||
|
||||
# Empty string after trim should become nil
|
||||
assert custom_field_value.value.value == nil
|
||||
end
|
||||
|
||||
test "accepts valid email", %{member: member, email_field: email_field} do
|
||||
assert {:ok, custom_field_value} =
|
||||
CustomFieldValue
|
||||
|
|
@ -273,4 +303,3 @@ defmodule Mv.Membership.CustomFieldValueValidationTest do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue