Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-05 09:10:38 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-05 09:10:38 +0300
commit78bc17257c53bc100a4a1eb07c0fdf032236068f (patch)
treeb74fed64161ca5c0131c26340ee1393187d4c169 /spec
parent0fb607f5565c6476c508410914075172ff5899b2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/graphql/resolvers/ci/template_resolver_spec.rb33
-rw-r--r--spec/graphql/types/ci/template_type_spec.rb16
-rw-r--r--spec/graphql/types/project_type_spec.rb8
-rw-r--r--spec/lib/banzai/filter/custom_emoji_filter_spec.rb2
-rw-r--r--spec/requests/api/graphql/ci/template_spec.rb48
5 files changed, 106 insertions, 1 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
diff --git a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
index 5e76e8164dd..94e77663d0f 100644
--- a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
+++ b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
@@ -53,7 +53,7 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
end
expect do
- filter('<p>:tanuki: :party-parrot:</p>')
+ filter('<p>:tanuki:</p> <p>:party-parrot:</p>')
end.not_to exceed_all_query_limit(control_count.count)
end
end
diff --git a/spec/requests/api/graphql/ci/template_spec.rb b/spec/requests/api/graphql/ci/template_spec.rb
new file mode 100644
index 00000000000..1bbef7d7f30
--- /dev/null
+++ b/spec/requests/api/graphql/ci/template_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+RSpec.describe 'Querying CI template' do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project, :public) }
+ let_it_be(:user) { create(:user) }
+
+ let(:query) do
+ <<~QUERY
+ {
+ project(fullPath: "#{project.full_path}") {
+ name
+ ciTemplate(name: "#{template_name}") {
+ name
+ content
+ }
+ }
+ }
+ QUERY
+ end
+
+ before do
+ post_graphql(query, current_user: user)
+ end
+
+ context 'when the template exists' do
+ let(:template_name) { 'Android' }
+
+ it_behaves_like 'a working graphql query'
+
+ it 'returns correct data' do
+ expect(graphql_data.dig('project', 'ciTemplate', 'name')).to eq(template_name)
+ expect(graphql_data.dig('project', 'ciTemplate', 'content')).not_to be_blank
+ end
+ end
+
+ context 'when the template does not exist' do
+ let(:template_name) { 'doesnotexist' }
+
+ it_behaves_like 'a working graphql query'
+
+ it 'returns correct data' do
+ expect(graphql_data.dig('project', 'ciTemplate')).to eq(nil)
+ end
+ end
+end