diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-09-14 14:23:04 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-10-17 10:24:48 +0300 |
commit | 7f7c3e1a8aeba5d21c332c8cacdf8af9067199c4 (patch) | |
tree | 6983cca6fac98df07d8df3820e15fb4314e2c85c /spec/services/ci | |
parent | 09a7da7222d535948eadcf53c821360b037f7f6b (diff) |
Add notification tests for it
Diffstat (limited to 'spec/services/ci')
-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 |