diff options
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/members/expiring_email_notification_worker_spec.rb | 50 | ||||
-rw-r--r-- | spec/workers/members/expiring_worker_spec.rb | 27 |
2 files changed, 77 insertions, 0 deletions
diff --git a/spec/workers/members/expiring_email_notification_worker_spec.rb b/spec/workers/members/expiring_email_notification_worker_spec.rb new file mode 100644 index 00000000000..600a81b37b8 --- /dev/null +++ b/spec/workers/members/expiring_email_notification_worker_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Members::ExpiringEmailNotificationWorker, type: :worker, feature_category: :system_access do + subject(:worker) { described_class.new } + + let_it_be(:member) { create(:project_member, :guest, expires_at: 7.days.from_now.to_date) } + let_it_be(:notified_member) do + create(:project_member, :guest, expires_at: 7.days.from_now.to_date, expiry_notified_at: Date.today) + end + + describe '#perform' do + context "with not notified member" do + it "notify member" do + expect_next_instance_of(NotificationService) do |notification_service| + expect(notification_service).to receive(:member_about_to_expire).with(member) + end + + worker.perform(member.id) + + expect(member.reload.expiry_notified_at).to be_present + end + end + + context "with notified member" do + it "not notify member" do + expect_next_instance_of(NotificationService) do |notification_service| + expect(notification_service).not_to receive(:member_about_to_expire).with(notified_member) + end + + worker.perform(notified_member.id) + end + end + + context "when feature member_expiring_email_notification is disabled" do + before do + stub_feature_flags(member_expiring_email_notification: false) + end + + it "not notify member" do + expect_next_instance_of(NotificationService) do |notification_service| + expect(notification_service).not_to receive(:member_about_to_expire).with(member) + end + + worker.perform(member.id) + end + end + end +end diff --git a/spec/workers/members/expiring_worker_spec.rb b/spec/workers/members/expiring_worker_spec.rb new file mode 100644 index 00000000000..3f46548dbb3 --- /dev/null +++ b/spec/workers/members/expiring_worker_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Members::ExpiringWorker, type: :worker, feature_category: :system_access do + subject(:worker) { described_class.new } + + describe '#perform' do + let_it_be(:expiring_7_days_project_member) { create(:project_member, :guest, expires_at: 7.days.from_now) } + let_it_be(:expiring_7_days_group_member) { create(:group_member, :guest, expires_at: 7.days.from_now) } + let_it_be(:expiring_10_days_project_member) { create(:project_member, :guest, expires_at: 10.days.from_now) } + let_it_be(:expiring_5_days_project_member) { create(:project_member, :guest, expires_at: 5.days.from_now) } + let_it_be(:expiring_7_days_blocked_project_member) do + create(:project_member, :guest, :blocked, expires_at: 7.days.from_now) + end + + let(:notifiy_worker) { Members::ExpiringEmailNotificationWorker } + + it "notifies only active users with membership expiring in less than 7 days" do + expect(notifiy_worker).to receive(:perform_async).with(expiring_7_days_project_member.id) + expect(notifiy_worker).to receive(:perform_async).with(expiring_7_days_group_member.id) + expect(notifiy_worker).to receive(:perform_async).with(expiring_5_days_project_member.id) + + worker.perform + end + end +end |