summaryrefslogtreecommitdiff
path: root/spec/serializers/evidences/evidence_entity_spec.rb
blob: 8ec0422fea2d7052a2995ca5abf1f46d9165fd6d (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Evidences::EvidenceEntity do
  let_it_be(:project) { create(:project) }
  let(:release) { create(:release, project: project) }
  let(:evidence) { build(:evidence, release: release) }
  let(:schema_file) { 'evidences/evidence' }

  subject { described_class.new(evidence).as_json }

  it 'exposes the expected fields' do
    expect(subject.keys).to contain_exactly(:release)
  end

  context 'when a release is associated to a milestone' do
    let(:milestone) { create(:milestone, project: project) }
    let(:release) { create(:release, project: project, milestones: [milestone]) }

    context 'when a milestone has no issue associated with it' do
      it 'creates a valid JSON object' do
        expect(subject[:release][:milestones].first[:issues]).to be_empty
        expect(subject.to_json).to match_schema(schema_file)
      end
    end

    context 'when a milestone has no description' do
      let(:milestone) { create(:milestone, project: project, description: nil) }

      it 'creates a valid JSON object' do
        expect(subject[:release][:milestones].first[:description]).to be_nil
        expect(subject.to_json).to match_schema(schema_file)
      end
    end

    context 'when a milestone has no due_date' do
      let(:milestone) { create(:milestone, project: project, due_date: nil) }

      it 'creates a valid JSON object' do
        expect(subject[:release][:milestones].first[:due_date]).to be_nil
        expect(subject.to_json).to match_schema(schema_file)
      end
    end

    context 'when a milestone has an issue' do
      context 'when the issue has no description' do
        let(:issue) { create(:issue, project: project, description: nil, state: 'closed') }

        before do
          milestone.issues << issue
        end

        it 'creates a valid JSON object' do
          expect(subject[:release][:milestones].first[:issues].first[:title]).to be_present
          expect(subject.to_json).to match_schema(schema_file)
        end
      end
    end
  end

  context 'when a release is not associated to any milestone' do
    it 'creates a valid JSON object' do
      expect(subject[:release][:milestones]).to be_empty
      expect(subject.to_json).to match_schema(schema_file)
    end
  end
end