diff options
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/resolvers/ci/template_resolver_spec.rb | 33 | ||||
-rw-r--r-- | spec/graphql/types/ci/template_type_spec.rb | 16 | ||||
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 8 |
3 files changed, 57 insertions, 0 deletions
diff --git a/spec/graphql/resolvers/ci/template_resolver_spec.rb b/spec/graphql/resolvers/ci/template_resolver_spec.rb new file mode 100644 index 00000000000..bec25640c7f --- /dev/null +++ b/spec/graphql/resolvers/ci/template_resolver_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Ci::TemplateResolver do + include GraphqlHelpers + + describe '#resolve' do + let(:user) { create(:user) } + let(:project) { create(:project) } + + subject(:resolve_subject) { resolve(described_class, obj: project, ctx: { current_user: user }, args: { name: template_name }) } + + context 'when template exists' do + let(:template_name) { 'Android' } + + it 'returns the found template' do + found_template = resolve_subject + + expect(found_template).to be_an_instance_of(Gitlab::Template::GitlabCiYmlTemplate) + expect(found_template.name).to eq('Android') + end + end + + context 'when template does not exist' do + let(:template_name) { 'invalidname' } + + it 'returns nil' do + expect(resolve_subject).to eq(nil) + end + end + end +end diff --git a/spec/graphql/types/ci/template_type_spec.rb b/spec/graphql/types/ci/template_type_spec.rb new file mode 100644 index 00000000000..95ac9f97e31 --- /dev/null +++ b/spec/graphql/types/ci/template_type_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::Ci::TemplateType do + specify { expect(described_class.graphql_name).to eq('CiTemplate') } + + it 'exposes the expected fields' do + expected_fields = %i[ + name + content + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index f2c4068f048..3ef2fbba002 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -32,6 +32,7 @@ RSpec.describe GitlabSchema.types['Project'] do issue_status_counts terraform_states alert_management_integrations container_repositories container_repositories_count pipeline_analytics squash_read_only sast_ci_configuration + ci_template ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -379,4 +380,11 @@ RSpec.describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_type(Types::Ci::JobType.connection_type) } it { is_expected.to have_graphql_arguments(:statuses) } end + + describe 'ci_template field' do + subject { described_class.fields['ciTemplate'] } + + it { is_expected.to have_graphql_type(Types::Ci::TemplateType) } + it { is_expected.to have_graphql_arguments(:name) } + end end |