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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.9 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::DagJobGroupEntity do
2020-05-24 23:13:21 +05:30
let_it_be(:request) { double(:request) }
let_it_be(:pipeline) { create(:ci_pipeline) }
let_it_be(:stage) { create(:ci_stage, pipeline: pipeline) }
let(:group) { Ci::Group.new(pipeline.project, stage, name: 'test', jobs: jobs) }
let(:entity) { described_class.new(group, request: request) }
describe '#as_json' do
subject { entity.as_json }
context 'when group contains 1 job' do
2022-08-13 15:12:31 +05:30
let(:job) { create(:ci_build, stage_id: stage.id, pipeline: pipeline, name: 'test') }
2020-05-24 23:13:21 +05:30
let(:jobs) { [job] }
it 'exposes a name' do
expect(subject.fetch(:name)).to eq 'test'
end
it 'exposes the size' do
expect(subject.fetch(:size)).to eq 1
end
it 'exposes the jobs' do
exposed_jobs = subject.fetch(:jobs)
expect(exposed_jobs.size).to eq 1
expect(exposed_jobs.first.fetch(:name)).to eq 'test'
end
2020-07-28 23:09:34 +05:30
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_job_group')
end
2020-05-24 23:13:21 +05:30
end
context 'when group contains multiple parallel jobs' do
2022-08-13 15:12:31 +05:30
let(:job_1) { create(:ci_build, stage_id: stage.id, pipeline: pipeline, name: 'test 1/2') }
let(:job_2) { create(:ci_build, stage_id: stage.id, pipeline: pipeline, name: 'test 2/2') }
2020-05-24 23:13:21 +05:30
let(:jobs) { [job_1, job_2] }
it 'exposes a name' do
expect(subject.fetch(:name)).to eq 'test'
end
it 'exposes the size' do
expect(subject.fetch(:size)).to eq 2
end
it 'exposes the jobs' do
exposed_jobs = subject.fetch(:jobs)
expect(exposed_jobs.size).to eq 2
expect(exposed_jobs.first.fetch(:name)).to eq 'test 1/2'
expect(exposed_jobs.last.fetch(:name)).to eq 'test 2/2'
end
2020-07-28 23:09:34 +05:30
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_job_group')
end
2020-05-24 23:13:21 +05:30
end
end
end