diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/services/notification_service_spec.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) | |
download | gitlab-ce-e8d2c2579383897a1dd7f9debd359abe8ae8373d.tar.gz |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/services/notification_service_spec.rb')
-rw-r--r-- | spec/services/notification_service_spec.rb | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index c3a0766cb17..ac82e4c025f 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -361,6 +361,7 @@ RSpec.describe NotificationService, :mailer do let_it_be_with_reload(:issue) { create(:issue, project: project, assignees: [assignee]) } let_it_be(:mentioned_issue) { create(:issue, assignees: issue.assignees) } let_it_be_with_reload(:author) { create(:user) } + let(:note) { create(:note_on_issue, author: author, noteable: issue, project_id: issue.project_id, note: '@mention referenced, @unsubscribed_mentioned and @outsider also') } subject { notification.new_note(note) } @@ -376,41 +377,31 @@ RSpec.describe NotificationService, :mailer do let(:subject) { NotificationService.new } let(:mailer) { double(deliver_later: true) } + let(:issue) { create(:issue, author: User.support_bot) } + let(:project) { issue.project } + let(:note) { create(:note, noteable: issue, project: project) } - def should_email! - expect(Notify).to receive(:service_desk_new_note_email) - .with(issue.id, note.id, issue.external_author) - end + shared_examples 'notification with exact metric events' do |number_of_events| + it 'adds metric event' do + metric_transaction = double('Gitlab::Metrics::WebTransaction', increment: true, observe: true) + allow(::Gitlab::Metrics::BackgroundTransaction).to receive(:current).and_return(metric_transaction) + expect(metric_transaction).to receive(:add_event).with(:service_desk_new_note_email).exactly(number_of_events).times - def should_not_email! - expect(Notify).not_to receive(:service_desk_new_note_email) + subject.new_note(note) + end end - def execute! - subject.new_note(note) - end + shared_examples 'no participants are notified' do + it 'does not send the email' do + expect(Notify).not_to receive(:service_desk_new_note_email) - def self.it_should_email! - it 'sends the email' do - should_email! - execute! + subject.new_note(note) end - end - def self.it_should_not_email! - it 'doesn\'t send the email' do - should_not_email! - execute! - end + it_behaves_like 'notification with exact metric events', 0 end - let(:issue) { create(:issue, author: User.support_bot) } - let(:project) { issue.project } - let(:note) { create(:note, noteable: issue, project: project) } - - context 'do not exist' do - it_should_not_email! - end + it_behaves_like 'no participants are notified' context 'do exist and note not confidential' do let!(:issue_email_participant) { issue.issue_email_participants.create!(email: 'service.desk@example.com') } @@ -420,7 +411,14 @@ RSpec.describe NotificationService, :mailer do project.update!(service_desk_enabled: true) end - it_should_email! + it 'sends the email' do + expect(Notify).to receive(:service_desk_new_note_email) + .with(issue.id, note.id, issue.external_author) + + subject.new_note(note) + end + + it_behaves_like 'notification with exact metric events', 1 end context 'do exist and note is confidential' do @@ -432,7 +430,7 @@ RSpec.describe NotificationService, :mailer do project.update!(service_desk_enabled: true) end - it_should_not_email! + it_behaves_like 'no participants are notified' end end @@ -644,6 +642,7 @@ RSpec.describe NotificationService, :mailer do let_it_be(:issue) { create(:issue, project: project, assignees: [assignee]) } let_it_be(:mentioned_issue) { create(:issue, assignees: issue.assignees) } let_it_be(:author) { create(:user) } + let(:note) { create(:note_on_issue, author: author, noteable: issue, project_id: issue.project_id, note: '@all mentioned') } before_all do @@ -930,6 +929,10 @@ RSpec.describe NotificationService, :mailer do end context 'design management is disabled' do + before do + enable_design_management(false) + end + it 'does not notify anyone' do notification.new_note(note) @@ -2616,6 +2619,16 @@ RSpec.describe NotificationService, :mailer do end end + describe '#user_deactivated', :deliver_mails_inline do + let_it_be(:user) { create(:user) } + + it 'sends the user an email' do + notification.user_deactivated(user.name, user.notification_email) + + should_only_email(user) + end + end + describe 'GroupMember', :deliver_mails_inline do let(:added_user) { create(:user) } |