diff options
-rw-r--r-- | spec/services/ci/send_pipeline_notification_service_spec.rb | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/spec/services/ci/send_pipeline_notification_service_spec.rb b/spec/services/ci/send_pipeline_notification_service_spec.rb index 288302cc94f..9c840967aed 100644 --- a/spec/services/ci/send_pipeline_notification_service_spec.rb +++ b/spec/services/ci/send_pipeline_notification_service_spec.rb @@ -11,23 +11,30 @@ describe Ci::SendPipelineNotificationService, services: true do let(:project) { create(:project) } let(:user) { create(:user) } - - subject{ described_class.new(pipeline) } + let(:pusher) { user } + let(:watcher) { pusher } describe '#execute' do before do reset_delivered_emails! + pipeline.project.team << [watcher, Gitlab::Access::DEVELOPER] end shared_examples 'sending emails' do - it 'sends an email to pipeline user' do + it 'sends emails' do perform_enqueued_jobs do subject.execute([user.email]) end - email = ActionMailer::Base.deliveries.last - expect(email.subject).to include(email_subject) - expect(email.to).to eq([user.email]) + expected_receivers = [pusher, watcher].uniq.sort_by(&:email) + actual = ActionMailer::Base.deliveries.sort_by(&:to) + + expect(expected_receivers.size).to eq(actual.size) + + actual.zip(expected_receivers).each do |(email, receiver)| + expect(email.subject).to include(email_subject) + expect(email.to).to eq([receiver.email]) + end end end @@ -36,6 +43,30 @@ describe Ci::SendPipelineNotificationService, services: true do let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" } it_behaves_like 'sending emails' + + context 'with pipeline from someone else' do + let(:pusher) { create(:user) } + + context 'with success pipeline notification on' do + let(:watcher) { user } + + before do + watcher.global_notification_setting. + update(level: 'custom', success_pipeline: true) + end + + it_behaves_like 'sending emails' + end + + context 'with success pipeline notification off' do + before do + watcher.global_notification_setting. + update(level: 'custom', success_pipeline: false) + end + + it_behaves_like 'sending emails' + end + end end context 'with failed pipeline' do @@ -43,6 +74,30 @@ describe Ci::SendPipelineNotificationService, services: true do let(:email_subject) { "Pipeline ##{pipeline.id} has failed" } it_behaves_like 'sending emails' + + context 'with pipeline from someone else' do + let(:pusher) { create(:user) } + + context 'with failed pipeline notification on' do + let(:watcher) { user } + + before do + watcher.global_notification_setting. + update(level: 'custom', failed_pipeline: true) + end + + it_behaves_like 'sending emails' + end + + context 'with failed pipeline notification off' do + before do + watcher.global_notification_setting. + update(level: 'custom', failed_pipeline: false) + end + + it_behaves_like 'sending emails' + end + end end end end |