debian-mirror-gitlab/spec/serializers/ci/dag_job_entity_spec.rb

67 lines
1.6 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Ci::DagJobEntity do
2020-05-24 23:13:21 +05:30
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 }
2020-07-28 23:09:34 +05:30
RSpec.shared_examples "matches schema" do
it "matches schema" do
expect(subject.to_json).to match_schema('entities/dag_job')
end
end
2020-05-24 23:13:21 +05:30
it 'contains the name' do
expect(subject[:name]).to eq 'dag_job'
end
2020-07-28 23:09:34 +05:30
it_behaves_like "matches schema"
2020-05-24 23:13:21 +05:30
context 'when job is stage scheduled' do
2020-06-23 00:09:42 +05:30
it 'contains the name scheduling_type' do
expect(subject[:scheduling_type]).to eq 'stage'
end
2020-05-24 23:13:21 +05:30
it 'does not expose needs' do
expect(subject).not_to include(:needs)
end
2020-07-28 23:09:34 +05:30
it_behaves_like "matches schema"
2020-05-24 23:13:21 +05:30
end
context 'when job is dag scheduled' do
2020-06-23 00:09:42 +05:30
let(:job) { create(:ci_build, scheduling_type: 'dag') }
it 'contains the name scheduling_type' do
expect(subject[:scheduling_type]).to eq 'dag'
end
2020-07-28 23:09:34 +05:30
it_behaves_like "matches schema"
2020-05-24 23:13:21 +05:30
context 'when job has needs' do
let!(:need) { create(:ci_build_need, build: job, name: 'compile') }
it 'exposes the array of needs' do
expect(subject[:needs]).to eq ['compile']
end
2020-07-28 23:09:34 +05:30
it_behaves_like "matches schema"
2020-05-24 23:13:21 +05:30
end
context 'when job has empty needs' do
it 'exposes an empty array of needs' do
expect(subject[:needs]).to eq []
end
2020-07-28 23:09:34 +05:30
it_behaves_like "matches schema"
2020-05-24 23:13:21 +05:30
end
end
end
end