2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe PipelineHooksWorker, feature_category: :continuous_integration do
|
2016-11-03 12:29:30 +05:30
|
|
|
describe '#perform' do
|
|
|
|
context 'when pipeline exists' do
|
|
|
|
let(:pipeline) { create(:ci_pipeline) }
|
|
|
|
|
|
|
|
it 'executes hooks for the pipeline' do
|
2021-11-18 22:05:49 +05:30
|
|
|
hook_service = double
|
|
|
|
|
|
|
|
expect(Ci::Pipelines::HookService).to receive(:new).and_return(hook_service)
|
|
|
|
expect(hook_service).to receive(:execute)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
described_class.new.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline does not exist' do
|
|
|
|
it 'does not raise exception' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(Ci::Pipelines::HookService).not_to receive(:new)
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect { described_class.new.perform(123) }
|
|
|
|
.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
context 'when the user is blocked' do
|
|
|
|
let(:pipeline) { create(:ci_pipeline, user: create(:user, :blocked)) }
|
|
|
|
|
|
|
|
it 'returns early without executing' do
|
|
|
|
expect(Ci::Pipelines::HookService).not_to receive(:new)
|
|
|
|
|
|
|
|
described_class.new.perform(pipeline.id)
|
|
|
|
end
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
it_behaves_like 'worker with data consistency',
|
|
|
|
described_class,
|
|
|
|
data_consistency: :delayed
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|