Vereinfacht fixes, test cleanup, and dev seed improvements #467
1 changed files with 23 additions and 23 deletions
|
|
@ -34,7 +34,7 @@ countries_list =
|
|||
|> List.replace_at(7, "Österreich")
|
||||
|> List.replace_at(14, "Schweiz")
|
||||
|
||||
# 20 members: varied names, cities, join dates; fee types by index (last 2 without fee type)
|
||||
# 20 members: varied names, cities, join dates; fee types distributed over all members (round-robin)
|
||||
member_configs = [
|
||||
%{
|
||||
first_name: "Anna",
|
||||
|
|
@ -218,7 +218,7 @@ member_configs = [
|
|||
}
|
||||
]
|
||||
|
||||
# Fee type index per member: 0..4 round-robin for first 18, nil for last 2
|
||||
# Fee type index per member: 0..4 round-robin for all 20 (each type used 4 times)
|
||||
# Cycle status: all_paid, all_unpaid, mixed (varied)
|
||||
cycle_statuses = [
|
||||
:all_paid,
|
||||
|
|
@ -240,18 +240,20 @@ cycle_statuses = [
|
|||
:all_unpaid,
|
||||
:all_paid,
|
||||
:mixed,
|
||||
nil
|
||||
:all_paid
|
||||
]
|
||||
|
||||
# Indices of members that get an exit date (5 distributed: 3, 7, 11, 15, 19)
|
||||
exit_date_member_indices = [3, 7, 11, 15, 19]
|
||||
|
||||
Enum.with_index(member_configs)
|
||||
|> Enum.each(fn {config, index} ->
|
||||
email = "mitglied#{index + 1}@example.de"
|
||||
fee_type_index = if index >= 18, do: nil, else: rem(index, length(all_fee_types))
|
||||
fee_type_id = if fee_type_index, do: Enum.at(all_fee_types, fee_type_index).id, else: nil
|
||||
fee_type_index = rem(index, length(all_fee_types))
|
||||
fee_type_id = Enum.at(all_fee_types, fee_type_index).id
|
||||
cycle_status = Enum.at(cycle_statuses, index)
|
||||
|
||||
# Do not include membership_fee_type_id in upsert so re-runs do not overwrite
|
||||
# existing assignments; set via update below only when member has none
|
||||
# Set fee type at create so cycles are generated with correct interval (no interval-change conflict)
|
||||
base_attrs = %{
|
||||
first_name: config.first_name,
|
||||
last_name: config.last_name,
|
||||
|
|
@ -264,6 +266,11 @@ Enum.with_index(member_configs)
|
|||
country: Enum.at(countries_list, index)
|
||||
}
|
||||
|
||||
base_attrs =
|
||||
if fee_type_id,
|
||||
do: Map.put(base_attrs, :membership_fee_type_id, fee_type_id),
|
||||
else: base_attrs
|
||||
|
||||
member =
|
||||
Membership.create_member!(base_attrs,
|
||||
upsert?: true,
|
||||
|
|
@ -271,26 +278,14 @@ Enum.with_index(member_configs)
|
|||
actor: admin_user_with_role
|
||||
)
|
||||
|
||||
final_member =
|
||||
if is_nil(member.membership_fee_type_id) and fee_type_id do
|
||||
{:ok, updated} =
|
||||
Membership.update_member(member, %{membership_fee_type_id: fee_type_id},
|
||||
actor: admin_user_with_role
|
||||
)
|
||||
|
||||
updated
|
||||
else
|
||||
member
|
||||
end
|
||||
|
||||
if not is_nil(final_member.membership_fee_type_id) and not is_nil(cycle_status) do
|
||||
if not is_nil(member.membership_fee_type_id) and not is_nil(cycle_status) do
|
||||
member_with_cycles =
|
||||
Ash.load!(final_member, :membership_fee_cycles, actor: admin_user_with_role)
|
||||
Ash.load!(member, :membership_fee_cycles, actor: admin_user_with_role)
|
||||
|
||||
cycles =
|
||||
if Enum.empty?(member_with_cycles.membership_fee_cycles) do
|
||||
{:ok, new_cycles, _} =
|
||||
CycleGenerator.generate_cycles_for_member(final_member.id,
|
||||
CycleGenerator.generate_cycles_for_member(member.id,
|
||||
skip_lock?: true,
|
||||
actor: admin_user_with_role
|
||||
)
|
||||
|
|
@ -330,6 +325,11 @@ Enum.with_index(member_configs)
|
|||
end
|
||||
end)
|
||||
end
|
||||
|
||||
if index in exit_date_member_indices do
|
||||
exit_date = Date.add(config.join_date, 365)
|
||||
Membership.update_member(member, %{exit_date: exit_date}, actor: admin_user_with_role)
|
||||
end
|
||||
end)
|
||||
|
||||
# Groups (idempotent)
|
||||
|
|
@ -482,7 +482,7 @@ for {email, values} <- custom_value_assignments do
|
|||
end
|
||||
|
||||
IO.puts("✅ Dev seeds completed.")
|
||||
IO.puts(" - Members: 20 with country (mostly Deutschland, 1 Österreich, 1 Schweiz)")
|
||||
IO.puts(" - Members: 20 with country (mostly Deutschland, 1 Österreich, 1 Schweiz), fee types distributed, 5 with exit date")
|
||||
IO.puts(" - Test users: 4 linked to mitglied1–4 with roles Mitglied, Vorstand, Kassenwart, Buchhaltung")
|
||||
IO.puts(" - Groups: Vorstand, Jugend, Newsletter (with assignments)")
|
||||
IO.puts(" - Custom field values: ~80% filled (16 members, 4–6 fields each)")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue