2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::ActivationReminderEmails do
|
2019-04-10 23:40:11 +08:00
|
|
|
before { Jobs.run_immediately! }
|
|
|
|
|
|
|
|
# should be between 2 and 3 days
|
|
|
|
let(:created_at) { 50.hours.ago }
|
2019-04-10 22:53:52 +08:00
|
|
|
|
|
|
|
it "should email inactive users" do
|
2019-04-10 23:40:11 +08:00
|
|
|
user = Fabricate(:user, active: false, created_at: created_at)
|
2019-04-10 22:53:52 +08:00
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to change { ActionMailer::Base.deliveries.size }.by(
|
2023-01-09 19:18:21 +08:00
|
|
|
1,
|
2019-04-10 22:53:52 +08:00
|
|
|
).and change { user.email_tokens.count }.by(1)
|
2022-05-16 21:21:33 +08:00
|
|
|
|
|
|
|
expect(user.custom_fields["activation_reminder"]).to eq("t")
|
2022-07-19 22:03:03 +08:00
|
|
|
expect { described_class.new.execute({}) }.not_to change { ActionMailer::Base.deliveries.size }
|
2022-05-16 21:21:33 +08:00
|
|
|
|
|
|
|
user.activate
|
|
|
|
expect(user.reload.custom_fields["activation_reminder"]).to eq(nil)
|
2019-04-10 22:53:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not email active users" do
|
2019-04-10 23:40:11 +08:00
|
|
|
user = Fabricate(:user, active: true, created_at: created_at)
|
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to not_change {
|
2022-07-19 22:03:03 +08:00
|
|
|
ActionMailer::Base.deliveries.size
|
|
|
|
}.and not_change { user.email_tokens.count }
|
2019-04-10 23:40:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not email staged users" do
|
|
|
|
user = Fabricate(:user, active: false, staged: true, created_at: created_at)
|
2019-04-10 22:53:52 +08:00
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to not_change {
|
2022-07-19 22:03:03 +08:00
|
|
|
ActionMailer::Base.deliveries.size
|
|
|
|
}.and not_change { user.email_tokens.count }
|
2019-04-10 22:53:52 +08:00
|
|
|
end
|
|
|
|
end
|