summaryrefslogtreecommitdiff
path: root/spec/serializers/test_case_entity_spec.rb
blob: 45e63e3feecc7a6742832a089c6c251687a704d5 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe TestCaseEntity do
  include TestReportsHelper

  let_it_be(:job) { create(:ci_build) }

  let(:entity) { described_class.new(test_case) }

  describe '#as_json' do
    subject { entity.as_json }

    context 'when test case is success' do
      let(:test_case) { create_test_case_rspec_success }

      it 'contains correct test case details' do
        expect(subject[:status]).to eq('success')
        expect(subject[:name]).to eq('Test#sum when a is 1 and b is 3 returns summary')
        expect(subject[:classname]).to eq('spec.test_spec')
        expect(subject[:file]).to eq('./spec/test_spec.rb')
        expect(subject[:execution_time]).to eq(1.11)
      end
    end

    context 'when test case is failed' do
      let(:test_case) { create_test_case_rspec_failed }

      it 'contains correct test case details' do
        expect(subject[:status]).to eq('failed')
        expect(subject[:name]).to eq('Test#sum when a is 1 and b is 3 returns summary')
        expect(subject[:classname]).to eq('spec.test_spec')
        expect(subject[:file]).to eq('./spec/test_spec.rb')
        expect(subject[:execution_time]).to eq(2.22)
      end
    end

    context 'when feature is enabled' do
      before do
        stub_feature_flags(junit_pipeline_screenshots_view: true)
      end

      context 'when attachment is present' do
        let(:test_case) { build(:test_case, :failed_with_attachment, job: job) }

        it 'returns the attachment_url' do
          expect(subject).to include(:attachment_url)
        end
      end

      context 'when attachment is not present' do
        let(:test_case) { build(:test_case, job: job) }

        it 'returns a nil attachment_url' do
          expect(subject[:attachment_url]).to be_nil
        end
      end
    end

    context 'when feature is disabled' do
      before do
        stub_feature_flags(junit_pipeline_screenshots_view: false)
      end

      context 'when attachment is present' do
        let(:test_case) { build(:test_case, :failed_with_attachment, job: job) }

        it 'returns no attachment_url' do
          expect(subject).not_to include(:attachment_url)
        end
      end

      context 'when attachment is not present' do
        let(:test_case) { build(:test_case, job: job) }

        it 'returns no attachment_url' do
          expect(subject).not_to include(:attachment_url)
        end
      end
    end
  end
end