summaryrefslogtreecommitdiff
path: root/spec/serializers/ci/dag_job_entity_spec.rb
blob: 19b849c3879d18853741865b232aabf00d24f595 (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
# frozen_string_literal: true

require 'spec_helper'

describe Ci::DagJobEntity do
  let_it_be(:request) { double(:request) }

  let(:job) { create(:ci_build, name: 'dag_job') }
  let(:entity) { described_class.new(job, request: request) }

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

    it 'contains the name' do
      expect(subject[:name]).to eq 'dag_job'
    end

    context 'when job is stage scheduled' do
      it 'does not expose needs' do
        expect(subject).not_to include(:needs)
      end
    end

    context 'when job is dag scheduled' do
      context 'when job has needs' do
        let(:job) { create(:ci_build, scheduling_type: 'dag') }
        let!(:need) { create(:ci_build_need, build: job, name: 'compile') }

        it 'exposes the array of needs' do
          expect(subject[:needs]).to eq ['compile']
        end
      end

      context 'when job has empty needs' do
        let(:job) { create(:ci_build, scheduling_type: 'dag') }

        it 'exposes an empty array of needs' do
          expect(subject[:needs]).to eq []
        end
      end
    end
  end
end