diff options
Diffstat (limited to 'spec/workers/personal_access_tokens')
-rw-r--r-- | spec/workers/personal_access_tokens/expiring_worker_spec.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/spec/workers/personal_access_tokens/expiring_worker_spec.rb b/spec/workers/personal_access_tokens/expiring_worker_spec.rb index c8bdf02f4d3..7fa777b911a 100644 --- a/spec/workers/personal_access_tokens/expiring_worker_spec.rb +++ b/spec/workers/personal_access_tokens/expiring_worker_spec.rb @@ -7,18 +7,23 @@ RSpec.describe PersonalAccessTokens::ExpiringWorker, type: :worker do describe '#perform' do context 'when a token needs to be notified' do - let_it_be(:pat) { create(:personal_access_token, expires_at: 5.days.from_now) } + let_it_be(:user) { create(:user) } + let_it_be(:expiring_token) { create(:personal_access_token, user: user, expires_at: 5.days.from_now) } + let_it_be(:expiring_token2) { create(:personal_access_token, user: user, expires_at: 3.days.from_now) } + let_it_be(:notified_token) { create(:personal_access_token, user: user, expires_at: 5.days.from_now, expire_notification_delivered: true) } + let_it_be(:not_expiring_token) { create(:personal_access_token, user: user, expires_at: 1.month.from_now) } + let_it_be(:impersonation_token) { create(:personal_access_token, user: user, expires_at: 5.days.from_now, impersonation: true) } it 'uses notification service to send the email' do expect_next_instance_of(NotificationService) do |notification_service| - expect(notification_service).to receive(:access_token_about_to_expire).with(pat.user) + expect(notification_service).to receive(:access_token_about_to_expire).with(user, match_array([expiring_token.name, expiring_token2.name])) end worker.perform end it 'marks the notification as delivered' do - expect { worker.perform }.to change { pat.reload.expire_notification_delivered }.from(false).to(true) + expect { worker.perform }.to change { expiring_token.reload.expire_notification_delivered }.from(false).to(true) end end @@ -27,7 +32,7 @@ RSpec.describe PersonalAccessTokens::ExpiringWorker, type: :worker do it "doesn't use notification service to send the email" do expect_next_instance_of(NotificationService) do |notification_service| - expect(notification_service).not_to receive(:access_token_about_to_expire).with(pat.user) + expect(notification_service).not_to receive(:access_token_about_to_expire).with(pat.user, [pat.name]) end worker.perform @@ -43,7 +48,7 @@ RSpec.describe PersonalAccessTokens::ExpiringWorker, type: :worker do it "doesn't use notification service to send the email" do expect_next_instance_of(NotificationService) do |notification_service| - expect(notification_service).not_to receive(:access_token_about_to_expire).with(pat.user) + expect(notification_service).not_to receive(:access_token_about_to_expire).with(pat.user, [pat.name]) end worker.perform |