95 lines
2.9 KiB
Ruby
95 lines
2.9 KiB
Ruby
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
|
|
assert_not_equal :cancelled, @member.expected_status
|
|
end
|
|
end
|
|
end
|
|
|
|
test "expired after 1 year and 90 days" do
|
|
Timecop.freeze(Date.today + 1.year + 90.days) do
|
|
assert_equal :cancelled, @member.expected_status
|
|
end
|
|
end
|
|
|
|
test "no notifications in the first ~10 months" do
|
|
(Date.today .. (@member.expires_on + Notification.templates.first[:to_be_sent_on] - 1.day)).each do |day|
|
|
Timecop.freeze(day) do
|
|
assert_nil @member.todays_notification
|
|
end
|
|
end
|
|
end
|
|
|
|
test "first warning notification 60~30 days before expiration" do
|
|
(@member.expires_on - 60.days .. (@member.expires_on - 31.days)).each do |day|
|
|
Timecop.freeze(day) do
|
|
assert_equal "expiration_in_60d", @member.todays_notification[:template]
|
|
end
|
|
end
|
|
end
|
|
|
|
test "no duplicate notification" do
|
|
@member
|
|
.notifications
|
|
.create(template: "expiration_in_60d", to_be_sent_on: @member.expires_on - 60.days, status: "sent", sent_at: @member.expires_on - 60.days)
|
|
|
|
Timecop.freeze(@member.expires_on - 60.days) do
|
|
assert_nil @member.todays_notification
|
|
end
|
|
end
|
|
|
|
test "don't consider old notifications as duplicate" do
|
|
@member
|
|
.notifications
|
|
.create(template: "expiration_in_60d", to_be_sent_on: @member.expires_on - 60.days - 1.year, status: "sent", sent_at: @member.expires_on - 60.days - 1.year)
|
|
|
|
Timecop.freeze(@member.expires_on - 60.days) do
|
|
assert_equal "expiration_in_60d", @member.todays_notification[:template]
|
|
end
|
|
end
|
|
|
|
test "don't consider unsent notifications as duplicate" do
|
|
@member
|
|
.notifications
|
|
.create(template: "expiration_in_60d", to_be_sent_on: @member.expires_on - 60.days, status: "sent", sent_at: nil)
|
|
|
|
Timecop.freeze(@member.expires_on - 60.days) do
|
|
assert_equal "expiration_in_60d", @member.todays_notification[:template]
|
|
end
|
|
end
|
|
|
|
test "last notification ~90 days after expiration" do
|
|
Timecop.freeze(@member.expires_on + 90.days) do
|
|
assert_equal "cancelled", @member.todays_notification[:template]
|
|
end
|
|
end
|
|
|
|
test "last notification ~95 days after expiration" do
|
|
Timecop.freeze(@member.expires_on + 95.days) do
|
|
assert_equal "cancelled", @member.todays_notification[:template]
|
|
end
|
|
end
|
|
|
|
test "no duplicate last notification" do
|
|
@member
|
|
.notifications
|
|
.create(template: "cancelled", to_be_sent_on: @member.expires_on + 90.days, status: "sent", sent_at: @member.expires_on + 90.days)
|
|
|
|
Timecop.freeze(@member.expires_on + 95.days) do
|
|
assert_nil @member.todays_notification
|
|
end
|
|
end
|
|
end
|