fix(membership-fees): show error for unparseable cycle date instead of crashing
Date.from_iso8601/1 returns {:error, reason}, so the with else clause matching a bare :error never fired and an invalid date raised a WithClauseError. Match the real date/calendar error reasons so the user sees the validation message.
This commit is contained in:
parent
2db467d5d1
commit
ec6422d450
2 changed files with 23 additions and 1 deletions
|
|
@ -1027,7 +1027,7 @@ defmodule MvWeb.MemberLive.Show.MembershipFeesComponent do
|
||||||
|> assign(:create_cycle_error, format_error(error))}
|
|> assign(:create_cycle_error, format_error(error))}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
:error ->
|
{:error, reason} when reason in [:invalid_format, :invalid_date, :incompatible_calendars] ->
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:create_cycle_error, gettext("Invalid date format"))}
|
|> assign(:create_cycle_error, gettext("Invalid date format"))}
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,28 @@ defmodule MvWeb.MemberLive.ShowMembershipFeesTest do
|
||||||
# Should not crash
|
# Should not crash
|
||||||
assert html =~ member.first_name
|
assert html =~ member.first_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "create_cycle with an unparseable date shows an error instead of crashing", %{conn: conn} do
|
||||||
|
fee_type = create_fee_type(%{interval: :yearly})
|
||||||
|
member = Mv.Fixtures.member_fixture(%{membership_fee_type_id: fee_type.id})
|
||||||
|
|
||||||
|
{:ok, view, _html} = live(conn, "/members/#{member.id}")
|
||||||
|
|
||||||
|
view
|
||||||
|
|> element("button[phx-click='switch_tab'][phx-value-tab='membership_fees']")
|
||||||
|
|> render_click()
|
||||||
|
|
||||||
|
view
|
||||||
|
|> element("button[phx-click='open_create_cycle_modal']")
|
||||||
|
|> render_click()
|
||||||
|
|
||||||
|
html =
|
||||||
|
view
|
||||||
|
|> element("form[phx-submit='create_cycle']")
|
||||||
|
|> render_submit(%{"date" => "not-a-date", "amount" => "10"})
|
||||||
|
|
||||||
|
assert html =~ "Invalid date format"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "read_only user (Vorstand/Buchhaltung) - no cycle action buttons" do
|
describe "read_only user (Vorstand/Buchhaltung) - no cycle action buttons" do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue