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

daily_report_result_spec.rb « ci « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 61aa58c66926392a0895a7c2a0fc8ee02c3232a9 (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'

describe Ci::DailyReportResult do
  describe '.upsert_reports' do
    let!(:rspec_coverage) do
      create(
        :ci_daily_report_result,
        title: 'rspec',
        date: '2020-03-09',
        value: 71.2
      )
    end
    let!(:new_pipeline) { create(:ci_pipeline) }

    it 'creates or updates matching report results' do
      described_class.upsert_reports([
        {
          project_id: rspec_coverage.project_id,
          ref_path: rspec_coverage.ref_path,
          param_type: described_class.param_types[rspec_coverage.param_type],
          last_pipeline_id: new_pipeline.id,
          date: rspec_coverage.date,
          title: 'rspec',
          value: 81.0
        },
        {
          project_id: rspec_coverage.project_id,
          ref_path: rspec_coverage.ref_path,
          param_type: described_class.param_types[rspec_coverage.param_type],
          last_pipeline_id: new_pipeline.id,
          date: rspec_coverage.date,
          title: 'karma',
          value: 87.0
        }
      ])

      rspec_coverage.reload

      expect(rspec_coverage).to have_attributes(
        last_pipeline_id: new_pipeline.id,
        value: 81.0
      )

      expect(described_class.find_by_title('karma')).to have_attributes(
        project_id: rspec_coverage.project_id,
        ref_path: rspec_coverage.ref_path,
        param_type: rspec_coverage.param_type,
        last_pipeline_id: new_pipeline.id,
        date: rspec_coverage.date,
        value: 87.0
      )
    end

    context 'when given data is empty' do
      it 'does nothing' do
        expect { described_class.upsert_reports([]) }.not_to raise_error
      end
    end
  end
end