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
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
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