diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/services/notification_service_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/services/notification_service_spec.rb')
-rw-r--r-- | spec/services/notification_service_spec.rb | 95 |
1 files changed, 94 insertions, 1 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 3c1c3e2dfc3..2fe7a46de4b 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe NotificationService, :mailer do +RSpec.describe NotificationService, :mailer do include EmailSpec::Matchers include ExternalAuthorizationServiceHelpers include NotificationHelpers @@ -343,6 +343,79 @@ describe NotificationService, :mailer do end end + context 'on service desk issue' do + before do + allow(Notify).to receive(:service_desk_new_note_email) + .with(Integer, Integer).and_return(mailer) + + allow(::Gitlab::IncomingEmail).to receive(:enabled?) { true } + allow(::Gitlab::IncomingEmail).to receive(:supports_wildcard?) { true } + end + + let(:subject) { NotificationService.new } + let(:mailer) { double(deliver_later: true) } + + def should_email! + expect(Notify).to receive(:service_desk_new_note_email) + .with(issue.id, note.id) + end + + def should_not_email! + expect(Notify).not_to receive(:service_desk_new_note_email) + end + + def execute! + subject.new_note(note) + end + + def self.it_should_email! + it 'sends the email' do + should_email! + execute! + end + end + + def self.it_should_not_email! + it 'doesn\'t send the email' do + should_not_email! + execute! + end + end + + let(:issue) { create(:issue, author: User.support_bot) } + let(:project) { issue.project } + let(:note) { create(:note, noteable: issue, project: project) } + + context 'a non-service-desk issue' do + it_should_not_email! + end + + context 'a service-desk issue' do + before do + issue.update!(service_desk_reply_to: 'service.desk@example.com') + project.update!(service_desk_enabled: true) + end + + it_should_email! + + context 'where the project has disabled the feature' do + before do + project.update(service_desk_enabled: false) + end + + it_should_not_email! + end + + context 'when the support bot has unsubscribed' do + before do + issue.unsubscribe(User.support_bot, project) + end + + it_should_not_email! + end + end + end + describe 'new note on issue in project that belongs to a group' do before do note.project.namespace_id = group.id @@ -1950,6 +2023,26 @@ describe NotificationService, :mailer do let(:notification_trigger) { notification.resolve_all_discussions(merge_request, @u_disabled) } end end + + describe '#merge_when_pipeline_succeeds' do + it 'send notification that merge will happen when pipeline succeeds' do + notification.merge_when_pipeline_succeeds(merge_request, assignee) + should_email(merge_request.author) + should_email(@u_watcher) + should_email(@subscriber) + end + + it_behaves_like 'participating notifications' do + let(:participant) { create(:user, username: 'user-participant') } + let(:issuable) { merge_request } + let(:notification_trigger) { notification.merge_when_pipeline_succeeds(merge_request, @u_disabled) } + end + + it_behaves_like 'project emails are disabled' do + let(:notification_target) { merge_request } + let(:notification_trigger) { notification.merge_when_pipeline_succeeds(merge_request, @u_disabled) } + end + end end describe 'Projects', :deliver_mails_inline do |