gitlab-org--gitlab-foss/spec/workers/pipeline_notification_worker_spec.rb

134 lines
3.7 KiB
Ruby
Raw Normal View History

2016-09-13 13:10:58 -04:00
require 'spec_helper'
describe PipelineNotificationWorker do
include EmailHelpers
2016-09-23 07:45:48 -04:00
let(:pipeline) do
2016-09-23 09:43:40 -04:00
create(:ci_pipeline,
project: project,
sha: project.commit('master').sha,
user: pusher,
2016-09-23 09:43:40 -04:00
status: status)
2016-09-23 07:45:48 -04:00
end
2016-11-29 07:43:58 -05:00
let(:project) { create(:project, public_builds: false) }
2016-09-13 13:10:58 -04:00
let(:user) { create(:user) }
2016-09-14 07:23:04 -04:00
let(:pusher) { user }
let(:watcher) { pusher }
2016-09-13 13:10:58 -04:00
describe '#execute' do
2016-09-23 08:27:20 -04:00
before do
reset_delivered_emails!
pipeline.project.team << [pusher, Gitlab::Access::DEVELOPER]
2016-09-23 08:27:20 -04:00
end
context 'when watcher has developer access' do
before do
pipeline.project.team << [watcher, Gitlab::Access::DEVELOPER]
end
2016-09-13 13:10:58 -04:00
shared_examples 'sending emails' do
it 'sends emails' do
perform_enqueued_jobs do
subject.perform(pipeline.id)
end
2016-09-14 07:23:04 -04:00
emails = ActionMailer::Base.deliveries
actual = emails.flat_map(&:bcc).sort
expected_receivers = receivers.map(&:email).uniq.sort
2016-09-13 13:10:58 -04:00
expect(actual).to eq(expected_receivers)
expect(emails.size).to eq(1)
expect(emails.last.subject).to include(email_subject)
end
end
2016-09-13 13:10:58 -04:00
context 'with success pipeline' do
let(:status) { 'success' }
let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" }
let(:receivers) { [pusher, watcher] }
2016-09-14 07:23:04 -04:00
it_behaves_like 'sending emails'
2016-09-14 07:23:04 -04:00
context 'with pipeline from someone else' do
let(:pusher) { create(:user) }
2016-09-14 07:23:04 -04:00
let(:watcher) { user }
context 'with success pipeline notification on' do
before do
watcher.global_notification_setting.
update(level: 'custom', success_pipeline: true)
end
it_behaves_like 'sending emails'
2016-09-14 07:23:04 -04:00
end
context 'with success pipeline notification off' do
let(:receivers) { [pusher] }
before do
watcher.global_notification_setting.
update(level: 'custom', success_pipeline: false)
end
2016-09-14 07:23:04 -04:00
it_behaves_like 'sending emails'
2016-09-14 07:23:04 -04:00
end
end
context 'with failed pipeline' do
let(:status) { 'failed' }
let(:email_subject) { "Pipeline ##{pipeline.id} has failed" }
2016-09-14 07:23:04 -04:00
it_behaves_like 'sending emails'
context 'with pipeline from someone else' do
let(:pusher) { create(:user) }
let(:watcher) { user }
context 'with failed pipeline notification on' do
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
let(:receivers) { [pusher] }
before do
watcher.global_notification_setting.
update(level: 'custom', failed_pipeline: false)
end
it_behaves_like 'sending emails'
end
end
2016-09-14 07:23:04 -04:00
end
end
2016-09-13 13:10:58 -04:00
end
context 'when watcher has no read_build access' do
2016-09-13 13:10:58 -04:00
let(:status) { 'failed' }
2016-10-08 03:31:26 -04:00
let(:email_subject) { "Pipeline ##{pipeline.id} has failed" }
let(:watcher) { create(:user) }
2016-09-13 13:10:58 -04:00
before do
pipeline.project.team << [watcher, Gitlab::Access::GUEST]
2016-09-14 07:23:04 -04:00
watcher.global_notification_setting.
update(level: 'custom', failed_pipeline: true)
2016-09-14 07:23:04 -04:00
perform_enqueued_jobs do
subject.perform(pipeline.id)
2016-09-14 07:23:04 -04:00
end
end
2016-09-14 07:23:04 -04:00
it 'does not send emails' do
should_only_email(pusher, kind: :bcc)
2016-09-14 07:23:04 -04:00
end
2016-09-13 13:10:58 -04:00
end
end
end