2019-03-30 03:15:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 13:10:58 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe PipelineNotificationWorker, :mailer do
|
2020-02-27 13:09:21 -05:00
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline) }
|
2016-09-13 13:10:58 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
2017-03-30 07:29:52 -04:00
|
|
|
it 'calls NotificationService#pipeline_finished when the pipeline exists' do
|
2020-02-27 13:09:21 -05:00
|
|
|
notification_service_double = double
|
|
|
|
expect(notification_service_double).to receive(:pipeline_finished)
|
|
|
|
.with(pipeline, ref_status: 'success', recipients: ['test@gitlab.com'])
|
|
|
|
expect(NotificationService).to receive(:new).and_return(notification_service_double)
|
2016-10-21 06:16:39 -04:00
|
|
|
|
2020-02-27 13:09:21 -05:00
|
|
|
subject.perform(pipeline.id, ref_status: 'success', recipients: ['test@gitlab.com'])
|
2016-09-13 13:10:58 -04:00
|
|
|
end
|
|
|
|
|
2017-03-30 07:29:52 -04:00
|
|
|
it 'does nothing when the pipeline does not exist' do
|
|
|
|
expect(NotificationService).not_to receive(:new)
|
2016-09-14 07:23:04 -04:00
|
|
|
|
2020-04-01 11:07:45 -04:00
|
|
|
subject.perform(non_existing_record_id)
|
2016-09-13 13:10:58 -04:00
|
|
|
end
|
2021-07-23 11:09:21 -04:00
|
|
|
|
2022-06-10 11:09:22 -04:00
|
|
|
context 'when the user is blocked' do
|
|
|
|
before do
|
|
|
|
expect_next_found_instance_of(Ci::Pipeline) do |pipeline|
|
|
|
|
allow(pipeline).to receive(:user) { build(:user, :blocked) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing' do
|
|
|
|
expect(NotificationService).not_to receive(:new)
|
|
|
|
|
|
|
|
subject.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-23 11:09:21 -04:00
|
|
|
it_behaves_like 'worker with data consistency',
|
|
|
|
described_class,
|
|
|
|
data_consistency: :delayed
|
2016-09-13 13:10:58 -04:00
|
|
|
end
|
|
|
|
end
|