summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-22 12:16:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-22 12:16:22 +0000
commit96891fec6dfa20a8342a3daa25935213cfddae22 (patch)
treea09d9a3c565d28b33d0bbc1c1202061c8eb061b9 /spec/requests
parent8bf2e2b73e5898c78dd057e02828b6acc1647a70 (diff)
downloadgitlab-ce-96891fec6dfa20a8342a3daa25935213cfddae22.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/graphql/ci/pipelines_spec.rb64
-rw-r--r--spec/requests/api/graphql/group/work_item_types_spec.rb71
2 files changed, 135 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/ci/pipelines_spec.rb b/spec/requests/api/graphql/ci/pipelines_spec.rb
index 95ddd0250e7..820b1dc7d12 100644
--- a/spec/requests/api/graphql/ci/pipelines_spec.rb
+++ b/spec/requests/api/graphql/ci/pipelines_spec.rb
@@ -12,6 +12,38 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
travel_to(Time.current) { example.run }
end
+ describe 'sha' do
+ let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
+
+ let(:pipelines_graphql_data) { graphql_data.dig(*%w[project pipelines nodes]).first }
+
+ let(:query) do
+ %(
+ query {
+ project(fullPath: "#{project.full_path}") {
+ pipelines {
+ nodes {
+ fullSha: sha
+ shortSha: sha(format: SHORT)
+ alsoFull: sha(format: LONG)
+ }
+ }
+ }
+ }
+ )
+ end
+
+ it 'returns all formats of the SHA' do
+ post_graphql(query, current_user: user)
+
+ expect(pipelines_graphql_data).to include(
+ 'fullSha' => eq(pipeline.sha),
+ 'alsoFull' => eq(pipeline.sha),
+ 'shortSha' => eq(pipeline.short_sha)
+ )
+ end
+ end
+
describe 'duration fields' do
let_it_be(:pipeline) do
create(:ci_pipeline, project: project)
@@ -420,4 +452,36 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
end
end
end
+
+ describe 'ref_path' do
+ let_it_be(:merge_request) { create(:merge_request, source_project: project) }
+ let_it_be(:pipeline_1) { create(:ci_pipeline, project: project, user: user, merge_request: merge_request) }
+ let_it_be(:pipeline_2) { create(:ci_pipeline, project: project, user: user, merge_request: merge_request) }
+
+ let(:query) do
+ %(
+ query {
+ project(fullPath: "#{project.full_path}") {
+ pipelines {
+ nodes {
+ refPath
+ }
+ }
+ }
+ }
+ )
+ end
+
+ it 'avoids N+1 queries' do
+ control_count = ActiveRecord::QueryRecorder.new do
+ post_graphql(query, current_user: user)
+ end
+
+ create(:ci_pipeline, project: project, user: user, merge_request: merge_request)
+
+ expect do
+ post_graphql(query, current_user: user)
+ end.not_to exceed_query_limit(control_count)
+ end
+ end
end
diff --git a/spec/requests/api/graphql/group/work_item_types_spec.rb b/spec/requests/api/graphql/group/work_item_types_spec.rb
new file mode 100644
index 00000000000..0667e09d1e9
--- /dev/null
+++ b/spec/requests/api/graphql/group/work_item_types_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'getting a list of work item types for a group' do
+ include GraphqlHelpers
+
+ let_it_be(:developer) { create(:user) }
+ let_it_be(:group) { create(:group, :private) }
+
+ before_all do
+ group.add_developer(developer)
+ end
+
+ let(:current_user) { developer }
+
+ let(:fields) do
+ <<~GRAPHQL
+ workItemTypes{
+ nodes { id name iconName }
+ }
+ GRAPHQL
+ end
+
+ let(:query) do
+ graphql_query_for(
+ 'group',
+ { 'fullPath' => group.full_path },
+ fields
+ )
+ end
+
+ context 'when user has access to the group' do
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+
+ it_behaves_like 'a working graphql query'
+
+ it 'returns all default work item types' do
+ expect(graphql_data.dig('group', 'workItemTypes', 'nodes')).to match_array(
+ WorkItems::Type.default.map do |type|
+ hash_including('id' => type.to_global_id.to_s, 'name' => type.name, 'iconName' => type.icon_name)
+ end
+ )
+ end
+ end
+
+ context "when user doesn't have acces to the group" do
+ let(:current_user) { create(:user) }
+
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+
+ it 'does not return the group' do
+ expect(graphql_data).to eq('group' => nil)
+ end
+ end
+
+ context 'when the work_items feature flag is disabled' do
+ before do
+ stub_feature_flags(work_items: false)
+ post_graphql(query, current_user: current_user)
+ end
+
+ it 'makes the workItemTypes field unavailable' do
+ expect(graphql_errors).to contain_exactly(hash_including("message" => "Field 'workItemTypes' doesn't exist on type 'Group'"))
+ end
+ end
+end