summaryrefslogtreecommitdiff
path: root/spec/workers/build_finished_worker_spec.rb
blob: e7f7ae84621de263ea85347d002bf5842689031e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BuildFinishedWorker do
  subject { described_class.new.perform(build.id) }

  describe '#perform' do
    let(:build) { create(:ci_build, :success, pipeline: create(:ci_pipeline)) }

    context 'when build exists' do
      let!(:build) { create(:ci_build) }

      it 'calculates coverage and calls hooks' do
        expect(BuildTraceSectionsWorker)
          .to receive(:new).ordered.and_call_original
        expect(BuildCoverageWorker)
          .to receive(:new).ordered.and_call_original

        expect_any_instance_of(BuildTraceSectionsWorker).to receive(:perform)
        expect_any_instance_of(BuildCoverageWorker).to receive(:perform)
        expect(BuildHooksWorker).to receive(:perform_async)
        expect(ArchiveTraceWorker).to receive(:perform_async)
        expect(ExpirePipelineCacheWorker).to receive(:perform_async)
        expect(ChatNotificationWorker).not_to receive(:perform_async)
        expect(Ci::BuildReportResultWorker).not_to receive(:perform)

        subject
      end
    end

    context 'when build does not exist' do
      it 'does not raise exception' do
        expect { described_class.new.perform(123) }
          .not_to raise_error
      end
    end

    context 'when build has a chat' do
      let(:build) { create(:ci_build, :success, pipeline: create(:ci_pipeline, source: :chat)) }

      it 'schedules a ChatNotification job' do
        expect(ChatNotificationWorker).to receive(:perform_async).with(build.id)

        subject
      end
    end

    context 'when build has a test report' do
      let(:build) { create(:ci_build, :test_reports) }

      it 'schedules a BuildReportResult job' do
        expect_next_instance_of(Ci::BuildReportResultWorker) do |worker|
          expect(worker).to receive(:perform).with(build.id)
        end

        subject
      end
    end
  end
end