fix: improve get_last_completed_cycle and fix test helpers

- Fix get_last_completed_cycle to find most recent completed cycle
- Fix create_cycle helpers to delete auto-generated cycles first
- Fix Ash.destroy return value handling
- Fix form selectors to use specific IDs
- Fix URL parameter names for filters
- Fix Ash.read_one return value expectations in tests
This commit is contained in:
Moritz 2025-12-16 14:11:15 +01:00
parent ab7fa38010
commit 128c712dbc
Signed by: moritz
GPG key ID: 1020A035E5DD0824
12 changed files with 177 additions and 43 deletions

View file

@ -442,7 +442,9 @@ defmodule MvWeb.MemberLive.Show.MembershipFeesComponent do
case Decimal.parse(amount_str) do
{amount, _} when is_struct(amount, Decimal) ->
case Ash.update(cycle, :update, %{amount: amount}) do
case cycle
|> Ash.Changeset.for_update(:update, %{amount: amount})
|> Ash.update() do
{:ok, updated_cycle} ->
updated_cycles = replace_cycle(socket.assigns.cycles, updated_cycle)
@ -489,6 +491,16 @@ defmodule MvWeb.MemberLive.Show.MembershipFeesComponent do
|> assign(:deleting_cycle, nil)
|> put_flash(:info, gettext("Cycle deleted"))}
{:ok, _destroyed} ->
# Handle case where return_destroyed? is true
updated_cycles = Enum.reject(socket.assigns.cycles, &(&1.id == cycle_id))
{:noreply,
socket
|> assign(:cycles, updated_cycles)
|> assign(:deleting_cycle, nil)
|> put_flash(:info, gettext("Cycle deleted"))}
{:error, error} ->
{:noreply,
socket