debian-mirror-gitlab/spec/graphql/resolvers/ci/jobs_resolver_spec.rb

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

90 lines
3.2 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe Resolvers::Ci::JobsResolver, feature_category: :continuous_integration do
2021-01-29 00:20:46 +05:30
include GraphqlHelpers
2021-03-08 18:12:59 +05:30
let_it_be(:project) { create(:project, :repository, :public) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
2021-01-29 00:20:46 +05:30
before_all do
create(:ci_build, name: 'Normal job', pipeline: pipeline)
create(:ci_build, :sast, name: 'DAST job', pipeline: pipeline)
create(:ci_build, :dast, name: 'SAST job', pipeline: pipeline)
create(:ci_build, :container_scanning, name: 'Container scanning job', pipeline: pipeline)
2021-04-29 21:17:54 +05:30
create(:ci_build, name: 'Job with tags', pipeline: pipeline, tag_list: ['review'])
2023-07-09 08:55:56 +05:30
create(:ci_bridge, name: 'Bridge job', pipeline: pipeline)
2021-01-29 00:20:46 +05:30
end
describe '#resolve' do
2023-07-09 08:55:56 +05:30
context 'when none of the optional params are given' do
2021-01-29 00:20:46 +05:30
it "returns all of the pipeline's jobs" do
2022-07-23 23:45:48 +05:30
jobs = resolve(described_class, obj: pipeline, arg_style: :internal)
2021-02-22 17:27:13 +05:30
expect(jobs).to contain_exactly(
have_attributes(name: 'Normal job'),
have_attributes(name: 'DAST job'),
have_attributes(name: 'SAST job'),
2021-04-29 21:17:54 +05:30
have_attributes(name: 'Container scanning job'),
2023-07-09 08:55:56 +05:30
have_attributes(name: 'Job with tags'),
have_attributes(name: 'Bridge job')
2021-02-22 17:27:13 +05:30
)
2021-01-29 00:20:46 +05:30
end
end
context 'when security_report_types is present' do
it "returns the pipeline's jobs with the given security report types" do
report_types = [
::Types::Security::ReportTypeEnum.values['SAST'].value,
::Types::Security::ReportTypeEnum.values['DAST'].value
]
2022-07-23 23:45:48 +05:30
jobs = resolve(described_class, obj: pipeline, args: { security_report_types: report_types },
2022-10-11 01:57:18 +05:30
arg_style: :internal)
2021-01-29 00:20:46 +05:30
2021-02-22 17:27:13 +05:30
expect(jobs).to contain_exactly(
have_attributes(name: 'DAST job'),
have_attributes(name: 'SAST job')
)
2021-01-29 00:20:46 +05:30
end
end
2021-04-29 21:17:54 +05:30
context 'when a job has tags' do
it "returns jobs with tags when applicable" do
2022-07-23 23:45:48 +05:30
jobs = resolve(described_class, obj: pipeline, arg_style: :internal)
2023-07-09 08:55:56 +05:30
2021-04-29 21:17:54 +05:30
expect(jobs).to contain_exactly(
have_attributes(tag_list: []),
have_attributes(tag_list: []),
have_attributes(tag_list: []),
have_attributes(tag_list: []),
2023-07-09 08:55:56 +05:30
have_attributes(tag_list: ['review']),
have_attributes(name: 'Bridge job') # A bridge job has no tag list
2021-04-29 21:17:54 +05:30
)
end
end
2023-03-17 16:20:25 +05:30
context 'when a job is manual' do
before_all do
create(:ci_build, name: 'Manual job', pipeline: pipeline, when: 'manual')
end
it "returns jobs with when set to 'manual'" do
jobs = resolve(described_class, obj: pipeline, arg_style: :internal, args: { when_executed: ['manual'] })
expect(jobs).to contain_exactly(
have_attributes(name: 'Manual job')
)
end
end
2023-07-09 08:55:56 +05:30
context 'when filtering by job kind' do
it "returns jobs with that type" do
jobs = resolve(described_class, obj: pipeline, arg_style: :internal, args: { job_kind: ::Ci::Bridge })
expect(jobs).to contain_exactly(
have_attributes(name: 'Bridge job')
)
end
end
2021-01-29 00:20:46 +05:30
end
end