test: add monthly interval tests for cycle calculations
This commit is contained in:
parent
f08b520e66
commit
9f33db3fed
1 changed files with 71 additions and 0 deletions
|
|
@ -96,6 +96,23 @@ defmodule Mv.Membership.MemberCycleCalculationsTest do
|
||||||
member = Ash.load!(member, :current_cycle_status)
|
member = Ash.load!(member, :current_cycle_status)
|
||||||
assert member.current_cycle_status == nil
|
assert member.current_cycle_status == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns status of current cycle for monthly interval" do
|
||||||
|
fee_type = create_fee_type(%{interval: :monthly})
|
||||||
|
member = create_member(%{membership_fee_type_id: fee_type.id})
|
||||||
|
|
||||||
|
# Create a cycle that is active today (current month)
|
||||||
|
today = Date.utc_today()
|
||||||
|
cycle_start = CalendarCycles.calculate_cycle_start(today, :monthly)
|
||||||
|
|
||||||
|
create_cycle(member, fee_type, %{
|
||||||
|
cycle_start: cycle_start,
|
||||||
|
status: :unpaid
|
||||||
|
})
|
||||||
|
|
||||||
|
member = Ash.load!(member, :current_cycle_status)
|
||||||
|
assert member.current_cycle_status == :unpaid
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "last_cycle_status" do
|
describe "last_cycle_status" do
|
||||||
|
|
@ -153,6 +170,30 @@ defmodule Mv.Membership.MemberCycleCalculationsTest do
|
||||||
member = Ash.load!(member, :last_cycle_status)
|
member = Ash.load!(member, :last_cycle_status)
|
||||||
assert member.last_cycle_status == nil
|
assert member.last_cycle_status == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns status of last completed cycle for monthly interval" do
|
||||||
|
fee_type = create_fee_type(%{interval: :monthly})
|
||||||
|
member = create_member(%{membership_fee_type_id: fee_type.id})
|
||||||
|
|
||||||
|
today = Date.utc_today()
|
||||||
|
# Create cycles: last month (completed), current month (not completed)
|
||||||
|
last_month_start = Date.add(today, -32) |> CalendarCycles.calculate_cycle_start(:monthly)
|
||||||
|
current_month_start = CalendarCycles.calculate_cycle_start(today, :monthly)
|
||||||
|
|
||||||
|
create_cycle(member, fee_type, %{
|
||||||
|
cycle_start: last_month_start,
|
||||||
|
status: :paid
|
||||||
|
})
|
||||||
|
|
||||||
|
create_cycle(member, fee_type, %{
|
||||||
|
cycle_start: current_month_start,
|
||||||
|
status: :unpaid
|
||||||
|
})
|
||||||
|
|
||||||
|
member = Ash.load!(member, :last_cycle_status)
|
||||||
|
# Should return status of last month (last completed)
|
||||||
|
assert member.last_cycle_status == :paid
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "overdue_count" do
|
describe "overdue_count" do
|
||||||
|
|
@ -225,6 +266,36 @@ defmodule Mv.Membership.MemberCycleCalculationsTest do
|
||||||
assert member.overdue_count == 0
|
assert member.overdue_count == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "counts overdue cycles for monthly interval" do
|
||||||
|
fee_type = create_fee_type(%{interval: :monthly})
|
||||||
|
member = create_member(%{membership_fee_type_id: fee_type.id})
|
||||||
|
|
||||||
|
today = Date.utc_today()
|
||||||
|
# Create cycles: two months ago (unpaid, ended), last month (paid, ended), current month (unpaid, not ended)
|
||||||
|
two_months_ago_start = Date.add(today, -65) |> CalendarCycles.calculate_cycle_start(:monthly)
|
||||||
|
last_month_start = Date.add(today, -32) |> CalendarCycles.calculate_cycle_start(:monthly)
|
||||||
|
current_month_start = CalendarCycles.calculate_cycle_start(today, :monthly)
|
||||||
|
|
||||||
|
create_cycle(member, fee_type, %{
|
||||||
|
cycle_start: two_months_ago_start,
|
||||||
|
status: :unpaid
|
||||||
|
})
|
||||||
|
|
||||||
|
create_cycle(member, fee_type, %{
|
||||||
|
cycle_start: last_month_start,
|
||||||
|
status: :paid
|
||||||
|
})
|
||||||
|
|
||||||
|
create_cycle(member, fee_type, %{
|
||||||
|
cycle_start: current_month_start,
|
||||||
|
status: :unpaid
|
||||||
|
})
|
||||||
|
|
||||||
|
member = Ash.load!(member, :overdue_count)
|
||||||
|
# Should only count two_months_ago (unpaid and ended)
|
||||||
|
assert member.overdue_count == 1
|
||||||
|
end
|
||||||
|
|
||||||
test "counts multiple overdue cycles" do
|
test "counts multiple overdue cycles" do
|
||||||
fee_type = create_fee_type(%{interval: :yearly})
|
fee_type = create_fee_type(%{interval: :yearly})
|
||||||
member = create_member(%{membership_fee_type_id: fee_type.id})
|
member = create_member(%{membership_fee_type_id: fee_type.id})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue