2019-03-30 03:15:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-14 06:53:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe BuildFinishedWorker do
|
2020-06-02 17:08:00 -04:00
|
|
|
subject { described_class.new.perform(build.id) }
|
|
|
|
|
2016-10-14 06:53:51 -04:00
|
|
|
describe '#perform' do
|
2020-06-02 17:08:00 -04:00
|
|
|
let(:build) { create(:ci_build, :success, pipeline: create(:ci_pipeline)) }
|
|
|
|
|
2016-10-14 06:53:51 -04:00
|
|
|
context 'when build exists' do
|
2017-08-23 05:46:10 -04:00
|
|
|
let!(:build) { create(:ci_build) }
|
2016-10-14 06:53:51 -04:00
|
|
|
|
2020-10-23 14:08:31 -04:00
|
|
|
it 'calculates coverage and calls hooks', :aggregate_failures do
|
|
|
|
trace_worker = double('trace worker')
|
|
|
|
coverage_worker = double('coverage worker')
|
|
|
|
|
|
|
|
allow(BuildTraceSectionsWorker).to receive(:new).and_return(trace_worker)
|
|
|
|
allow(BuildCoverageWorker).to receive(:new).and_return(coverage_worker)
|
|
|
|
|
|
|
|
# Unfortunately, `ordered` does not seem to work when called within `allow_next_instance_of`
|
|
|
|
# so we're doing this the long and dirty way
|
|
|
|
expect(trace_worker).to receive(:perform).ordered
|
|
|
|
expect(coverage_worker).to receive(:perform).ordered
|
|
|
|
|
|
|
|
expect_next_instance_of(Ci::BuildReportResultWorker) do |instance|
|
|
|
|
expect(instance).to receive(:perform)
|
|
|
|
end
|
|
|
|
expect_next_instance_of(Ci::TestCasesService) do |instance|
|
|
|
|
expect(instance).to receive(:execute)
|
|
|
|
end
|
|
|
|
|
2018-02-05 11:52:46 -05:00
|
|
|
expect(BuildHooksWorker).to receive(:perform_async)
|
2019-05-20 20:31:03 -04:00
|
|
|
expect(ExpirePipelineCacheWorker).to receive(:perform_async)
|
2020-06-02 17:08:00 -04:00
|
|
|
expect(ChatNotificationWorker).not_to receive(:perform_async)
|
2020-10-16 11:08:46 -04:00
|
|
|
expect(ArchiveTraceWorker).to receive(:perform_in)
|
2016-10-14 06:53:51 -04:00
|
|
|
|
2020-06-02 17:08:00 -04:00
|
|
|
subject
|
2016-10-14 06:53:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build does not exist' do
|
|
|
|
it 'does not raise exception' do
|
2020-10-23 14:08:31 -04:00
|
|
|
expect { described_class.new.perform(non_existing_record_id) }
|
2016-10-14 06:53:51 -04:00
|
|
|
.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2019-02-20 16:29:48 -05:00
|
|
|
|
2020-06-02 17:08:00 -04:00
|
|
|
context 'when build has a chat' do
|
|
|
|
let(:build) { create(:ci_build, :success, pipeline: create(:ci_pipeline, source: :chat)) }
|
2019-02-20 16:29:48 -05:00
|
|
|
|
2020-06-02 17:08:00 -04:00
|
|
|
it 'schedules a ChatNotification job' do
|
|
|
|
expect(ChatNotificationWorker).to receive(:perform_async).with(build.id)
|
2019-02-20 16:29:48 -05:00
|
|
|
|
2020-06-02 17:08:00 -04:00
|
|
|
subject
|
|
|
|
end
|
2019-02-20 16:29:48 -05:00
|
|
|
end
|
2016-10-14 06:53:51 -04:00
|
|
|
end
|
|
|
|
end
|