From 9dc93a4519d9d5d7be48ff274127136236a3adb3 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 20 Apr 2021 23:50:22 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-11-stable-ee --- spec/services/notification_service_spec.rb | 47 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'spec/services/notification_service_spec.rb') diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index f3cd2776ce7..6eff768eac2 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -105,7 +105,7 @@ RSpec.describe NotificationService, :mailer do recipient_1 = NotificationRecipient.new(user_1, :custom, custom_action: :new_release) allow(NotificationRecipients::BuildService).to receive(:build_new_release_recipients).and_return([recipient_1]) - expect(Gitlab::AppLogger).to receive(:warn).with(message: 'Skipping sending notifications', user: current_user.id, klass: object.class, object_id: object.id) + expect(Gitlab::AppLogger).to receive(:warn).with(message: 'Skipping sending notifications', user: current_user.id, klass: object.class.to_s, object_id: object.id) action @@ -290,6 +290,49 @@ RSpec.describe NotificationService, :mailer do end end + describe 'SSH Keys' do + let_it_be_with_reload(:user) { create(:user) } + let_it_be(:fingerprints) { ["aa:bb:cc:dd:ee:zz"] } + + shared_context 'block user' do + before do + user.block! + end + end + + describe '#ssh_key_expired' do + subject { notification.ssh_key_expired(user, fingerprints) } + + it 'sends email to the token owner' do + expect { subject }.to have_enqueued_email(user, fingerprints, mail: "ssh_key_expired_email") + end + + context 'when user is not allowed to receive notifications' do + include_context 'block user' + + it 'does not send email to the token owner' do + expect { subject }.not_to have_enqueued_email(user, fingerprints, mail: "ssh_key_expired_email") + end + end + end + + describe '#ssh_key_expiring_soon' do + subject { notification.ssh_key_expiring_soon(user, fingerprints) } + + it 'sends email to the token owner' do + expect { subject }.to have_enqueued_email(user, fingerprints, mail: "ssh_key_expiring_soon_email") + end + + context 'when user is not allowed to receive notifications' do + include_context 'block user' + + it 'does not send email to the token owner' do + expect { subject }.not_to have_enqueued_email(user, fingerprints, mail: "ssh_key_expiring_soon_email") + end + end + end + end + describe '#unknown_sign_in' do let_it_be(:user) { create(:user) } let_it_be(:ip) { '127.0.0.1' } @@ -1662,7 +1705,7 @@ RSpec.describe NotificationService, :mailer do notification.issue_due(issue) email = find_email_for(@subscriber) - expect(email.header[:from].display_names).to eq([issue.author.name]) + expect(email.header[:from].display_names).to eq(["#{issue.author.name} (@#{issue.author.username})"]) end it_behaves_like 'participating notifications' do -- cgit v1.2.3