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

code_quality_mr_diff_presenter_spec.rb « pipeline_artifacts « ci « presenters « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f4f0990240d06403eff603004f6d118e4b35a742 (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
63
64
65
66
67
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::PipelineArtifacts::CodeQualityMrDiffPresenter, feature_category: :code_quality do
  let(:pipeline_artifact) { create(:ci_pipeline_artifact, :with_codequality_mr_diff_report) }
  let(:merge_request) { double(id: 123456789, new_paths: filenames) }

  subject(:presenter) { described_class.new(pipeline_artifact) }

  describe '#for_files' do
    subject(:quality_data) { presenter.for_files(merge_request) }

    context 'when code quality has data' do
      context 'when filenames is empty' do
        let(:filenames) { %w[] }

        it 'returns hash without quality' do
          expect(quality_data).to match(files: {})
        end
      end

      context 'when filenames do not match code quality data' do
        let(:filenames) { %w[demo.rb] }

        it 'returns hash without quality' do
          expect(quality_data).to match(files: {})
        end
      end

      context 'when filenames matches code quality data' do
        context 'when asking for one filename' do
          let(:filenames) { %w[file_a.rb] }

          it 'returns quality for the given filename' do
            expect(quality_data).to match(
              files: {
                "file_a.rb" => [
                  { line: 10, description: "Avoid parameter lists longer than 5 parameters. [12/5]", severity: "major" },
                  { line: 10, description: "Method `new_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.", severity: "minor" }
                ]
              }
            )
          end
        end

        context 'when asking for multiple filenames' do
          let(:filenames) { %w[file_a.rb file_b.rb] }

          it 'returns quality for the given filenames' do
            expect(quality_data).to match(
              files: {
                "file_a.rb" => [
                  { line: 10, description: "Avoid parameter lists longer than 5 parameters. [12/5]", severity: "major" },
                  { line: 10, description: "Method `new_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.", severity: "minor" }
                ],
                "file_b.rb" => [
                  { line: 10, description: "This cop checks for methods with too many parameters.\nThe maximum number of parameters is configurable.\nKeyword arguments can optionally be excluded from the total count.", severity: "minor" }
                ]
              }
            )
          end
        end
      end
    end
  end
end