Commit 7f7c3e1a authored by Lin Jen-Shin's avatar Lin Jen-Shin

Add notification tests for it

parent 09a7da72
...@@ -11,23 +11,30 @@ describe Ci::SendPipelineNotificationService, services: true do ...@@ -11,23 +11,30 @@ describe Ci::SendPipelineNotificationService, services: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:pusher) { user }
subject{ described_class.new(pipeline) } let(:watcher) { pusher }
describe '#execute' do describe '#execute' do
before do before do
reset_delivered_emails! reset_delivered_emails!
pipeline.project.team << [watcher, Gitlab::Access::DEVELOPER]
end end
shared_examples 'sending emails' do shared_examples 'sending emails' do
it 'sends an email to pipeline user' do it 'sends emails' do
perform_enqueued_jobs do perform_enqueued_jobs do
subject.execute([user.email]) subject.execute([user.email])
end end
email = ActionMailer::Base.deliveries.last expected_receivers = [pusher, watcher].uniq.sort_by(&:email)
expect(email.subject).to include(email_subject) actual = ActionMailer::Base.deliveries.sort_by(&:to)
expect(email.to).to eq([user.email])
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
end end
...@@ -36,6 +43,30 @@ describe Ci::SendPipelineNotificationService, services: true do ...@@ -36,6 +43,30 @@ describe Ci::SendPipelineNotificationService, services: true do
let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" } let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" }
it_behaves_like 'sending emails' 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 end
context 'with failed pipeline' do context 'with failed pipeline' do
...@@ -43,6 +74,30 @@ describe Ci::SendPipelineNotificationService, services: true do ...@@ -43,6 +74,30 @@ describe Ci::SendPipelineNotificationService, services: true do
let(:email_subject) { "Pipeline ##{pipeline.id} has failed" } let(:email_subject) { "Pipeline ##{pipeline.id} has failed" }
it_behaves_like 'sending emails' 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 end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment