2022-06-25 12:48:46 +00:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class MemberTest < ActiveSupport::TestCase
|
|
|
|
setup do
|
|
|
|
@member = Member.create!(
|
|
|
|
email: 'dsfargeg@example.com',
|
|
|
|
display_name: 'dsfargeg',
|
|
|
|
joined_on: Date.today,
|
|
|
|
expires_on: Date.today + 1.year
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "no expired in the first year and 90 days" do
|
|
|
|
(1.year + 90.days).in_days.to_i.times do |n|
|
|
|
|
Timecop.freeze(Date.today + n.days) do
|
2023-01-24 23:06:12 +00:00
|
|
|
assert_not_equal :cancelled, @member.expected_status
|
2022-06-25 12:48:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "expired after 1 year and 90 days" do
|
|
|
|
Timecop.freeze(Date.today + 1.year + 90.days) do
|
2023-01-24 23:06:12 +00:00
|
|
|
assert_equal :cancelled, @member.expected_status
|
2022-06-25 12:48:46 +00:00
|
|
|
end
|
|
|
|
end
|
2023-01-24 18:26:10 +00:00
|
|
|
|
|
|
|
test "regenerate notifications creates all 6 notifications" do
|
|
|
|
@member.regenerate_notifications
|
|
|
|
|
2023-01-24 23:06:12 +00:00
|
|
|
assert_equal 6, @member.notifications.count
|
2023-01-24 18:26:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "regenerate_notifications does not create notifications in the past" do
|
|
|
|
Timecop.freeze(Date.today + 1.year) do
|
|
|
|
@member.regenerate_notifications
|
2023-01-24 23:06:12 +00:00
|
|
|
assert_equal 4, @member.notifications.count
|
2023-01-24 18:26:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Timecop.freeze(Date.today + 2.year) do
|
|
|
|
@member.regenerate_notifications
|
2023-01-24 23:06:12 +00:00
|
|
|
assert_equal 0, @member.notifications.count
|
2023-01-24 18:26:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "regenerate_notifications does not create manually sent notifications" do
|
|
|
|
@member.regenerate_notifications
|
|
|
|
|
|
|
|
@member.notifications.first.deliver!
|
|
|
|
assert_equal 5, @member.notifications.where(status: 'scheduled').count
|
|
|
|
|
|
|
|
@member.regenerate_notifications
|
|
|
|
assert_equal 1, @member.notifications.where(status: 'sent').count
|
|
|
|
assert_equal 5, @member.notifications.where(status: 'scheduled').count
|
|
|
|
end
|
2023-01-24 23:06:12 +00:00
|
|
|
|
|
|
|
test "regenerate_notifications when given a date generates only notifications after that date" do
|
|
|
|
@member.regenerate_notifications(Date.today + 1.year)
|
|
|
|
|
|
|
|
assert_equal 4, @member.notifications.count
|
|
|
|
end
|
2022-06-25 12:48:46 +00:00
|
|
|
end
|