gitlab-org--gitlab-foss/spec/workers/send_pipeline_notification_...

104 lines
2.7 KiB
Ruby
Raw Normal View History

2016-09-13 17:10:58 +00:00
require 'spec_helper'
2016-09-28 09:29:53 +00:00
describe SendPipelineNotificationWorker do
2016-09-23 11:45:48 +00:00
let(:pipeline) do
2016-09-23 13:43:40 +00:00
create(:ci_pipeline,
project: project,
sha: project.commit('master').sha,
user: pusher,
2016-09-23 13:43:40 +00:00
status: status)
2016-09-23 11:45:48 +00:00
end
let(:project) { create(:project) }
2016-09-13 17:10:58 +00:00
let(:user) { create(:user) }
2016-09-14 11:23:04 +00:00
let(:pusher) { user }
let(:watcher) { pusher }
2016-09-13 17:10:58 +00:00
describe '#execute' do
2016-09-23 12:27:20 +00:00
before do
reset_delivered_emails!
2016-09-14 11:23:04 +00:00
pipeline.project.team << [watcher, Gitlab::Access::DEVELOPER]
2016-09-23 12:27:20 +00:00
end
2016-09-13 17:10:58 +00:00
shared_examples 'sending emails' do
2016-09-14 11:23:04 +00:00
it 'sends emails' do
2016-09-13 17:10:58 +00:00
perform_enqueued_jobs do
subject.perform(pipeline.id)
2016-09-13 17:10:58 +00:00
end
2016-09-14 11:23:04 +00:00
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
2016-09-13 17:10:58 +00:00
end
end
context 'with success pipeline' do
let(:status) { 'success' }
2016-10-08 07:31:26 +00:00
let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" }
2016-09-13 17:10:58 +00:00
it_behaves_like 'sending emails'
2016-09-14 11:23:04 +00:00
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
2016-09-13 17:10:58 +00:00
end
context 'with failed pipeline' do
let(:status) { 'failed' }
2016-10-08 07:31:26 +00:00
let(:email_subject) { "Pipeline ##{pipeline.id} has failed" }
2016-09-13 17:10:58 +00:00
it_behaves_like 'sending emails'
2016-09-14 11:23:04 +00:00
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
2016-09-13 17:10:58 +00:00
end
end
end