Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_code_quality_mr_diff_report_service_spec.rb « pipeline_artifacts « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c48f15d72610680c665c592a3b490a785e6b7d7 (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
62
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Ci::PipelineArtifacts::CreateCodeQualityMrDiffReportService do
  describe '#execute' do
    subject(:pipeline_artifact) { described_class.new.execute(pipeline) }

    context 'when pipeline has codequality reports' do
      let(:project) { create(:project, :repository) }

      describe 'pipeline completed status' do
        using RSpec::Parameterized::TableSyntax

        where(:status, :result) do
          :success   | 1
          :failed    | 1
          :canceled  | 1
          :skipped   | 1
        end

        with_them do
          let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, status: status, project: project) }

          it 'creates a pipeline artifact' do
            expect { pipeline_artifact }.to change(Ci::PipelineArtifact, :count).by(result)
          end

          it 'persists the default file name' do
            expect(pipeline_artifact.file.filename).to eq('code_quality_mr_diff.json')
          end

          it 'sets expire_at to 1 week' do
            freeze_time do
              expect(pipeline_artifact.expire_at).to eq(1.week.from_now)
            end
          end
        end
      end

      context 'when pipeline artifact has already been created' do
        let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }

        it 'does not persist the same artifact twice' do
          2.times { described_class.new.execute(pipeline) }

          expect(Ci::PipelineArtifact.count).to eq(1)
        end
      end
    end

    context 'when pipeline is not completed and codequality report does not exist' do
      let(:pipeline) { create(:ci_pipeline, :running) }

      it 'does not persist data' do
        pipeline_artifact

        expect(Ci::PipelineArtifact.count).to eq(0)
      end
    end
  end
end