diff options
Diffstat (limited to 'spec/requests/api/graphql/project')
4 files changed, 175 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/project/alert_management/alerts_spec.rb b/spec/requests/api/graphql/project/alert_management/alerts_spec.rb index 7f586edd510..55d223daf27 100644 --- a/spec/requests/api/graphql/project/alert_management/alerts_spec.rb +++ b/spec/requests/api/graphql/project/alert_management/alerts_spec.rb @@ -74,6 +74,7 @@ RSpec.describe 'getting Alert Management Alerts', feature_category: :incident_ma 'details' => { 'custom.alert' => 'payload', 'runbook' => 'runbook' }, 'createdAt' => triggered_alert.created_at.strftime('%Y-%m-%dT%H:%M:%SZ'), 'updatedAt' => triggered_alert.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ'), + 'metricsDashboardUrl' => nil, 'detailsUrl' => triggered_alert.details_url, 'prometheusAlert' => nil, 'runbook' => 'runbook' diff --git a/spec/requests/api/graphql/project/autocomplete_users_spec.rb b/spec/requests/api/graphql/project/autocomplete_users_spec.rb new file mode 100644 index 00000000000..7c416465ed4 --- /dev/null +++ b/spec/requests/api/graphql/project/autocomplete_users_spec.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'autocomplete users for a project', feature_category: :team_planning do + include GraphqlHelpers + + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, :repository, :public, group: group) } + + let_it_be(:direct_member) { create(:user).tap { |u| project.add_guest(u) } } + let_it_be(:indirect_member) { create(:user).tap { |u| group.add_guest(u) } } + + let_it_be(:group_invited_to_project) do + create(:group).tap { |g| create(:project_group_link, project: project, group: g) } + end + + let_it_be(:member_from_project_share) { create(:user).tap { |u| group_invited_to_project.add_guest(u) } } + + let_it_be(:group_invited_to_parent_group) do + create(:group).tap { |g| create(:group_group_link, shared_group: group, shared_with_group: g) } + end + + let_it_be(:member_from_parent_group_share) { create(:user).tap { |u| group_invited_to_parent_group.add_guest(u) } } + + let_it_be(:sibling_project) { create(:project, :repository, :public, group: group) } + let_it_be(:sibling_member) { create(:user).tap { |u| sibling_project.add_guest(u) } } + + let(:params) { {} } + let(:query) do + graphql_query_for( + 'project', + { 'fullPath' => project.full_path }, + query_graphql_field('autocompleteUsers', params, 'id') + ) + end + + let(:response_user_ids) { graphql_data.dig('project', 'autocompleteUsers').pluck('id') } + + it 'returns members of the project' do + post_graphql(query, current_user: direct_member) + + expected_user_ids = [ + direct_member, + indirect_member, + member_from_project_share, + member_from_parent_group_share + ].map { |u| u.to_global_id.to_s } + + expect(response_user_ids).to match_array(expected_user_ids) + end + + context 'with search param' do + let(:params) { { search: indirect_member.username } } + + it 'only returns users matching the search query' do + post_graphql(query, current_user: direct_member) + + expect(response_user_ids).to contain_exactly(indirect_member.to_global_id.to_s) + end + end + + context 'with merge request interaction' do + let(:merge_request) { create(:merge_request, source_project: project) } + let(:fields) do + <<~FIELDS + id + mergeRequestInteraction(id: "#{merge_request.to_global_id}") { + canMerge + } + FIELDS + end + + let(:query) do + graphql_query_for( + 'project', + { 'fullPath' => project.full_path }, + query_graphql_field('autocompleteUsers', params, fields) + ) + end + + it 'returns MR state related to the users' do + project.add_maintainer(direct_member) + + post_graphql(query, current_user: direct_member) + + expect(graphql_data.dig('project', 'autocompleteUsers')).to include( + a_hash_including( + 'id' => direct_member.to_global_id.to_s, + 'mergeRequestInteraction' => { 'canMerge' => true } + ), + a_hash_including( + 'id' => indirect_member.to_global_id.to_s, + 'mergeRequestInteraction' => { 'canMerge' => false } + ) + ) + end + end +end diff --git a/spec/requests/api/graphql/project/merge_requests_spec.rb b/spec/requests/api/graphql/project/merge_requests_spec.rb index e3c4396e7d8..05ed0ed8729 100644 --- a/spec/requests/api/graphql/project/merge_requests_spec.rb +++ b/spec/requests/api/graphql/project/merge_requests_spec.rb @@ -396,6 +396,28 @@ RSpec.describe 'getting merge request listings nested in a project', feature_cat include_examples 'N+1 query check', skip_cached: false end + + context 'when requesting diffStats' do + let(:requested_fields) { ['diffStats { path }'] } + + before do + create_list(:merge_request_diff, 2, merge_request: merge_request_a) + create_list(:merge_request_diff, 2, merge_request: merge_request_b) + create_list(:merge_request_diff, 2, merge_request: merge_request_c) + end + + include_examples 'N+1 query check', skip_cached: false + + context 'when each merge request diff has no head_commit_sha' do + before do + [merge_request_a, merge_request_b, merge_request_c].each do |mr| + mr.merge_request_diffs.update!(head_commit_sha: nil) + end + end + + include_examples 'N+1 query check', skip_cached: false + end + end end describe 'performance' do diff --git a/spec/requests/api/graphql/project/work_items_spec.rb b/spec/requests/api/graphql/project/work_items_spec.rb index 478112b687a..4aba83dae92 100644 --- a/spec/requests/api/graphql/project/work_items_spec.rb +++ b/spec/requests/api/graphql/project/work_items_spec.rb @@ -361,6 +361,59 @@ RSpec.describe 'getting a work item list for a project', feature_category: :team end end + context 'when fetching work item linked items widget' do + let_it_be(:related_items) { create_list(:work_item, 3, project: project, milestone: milestone1) } + + let(:fields) do + <<~GRAPHQL + nodes { + widgets { + type + ... on WorkItemWidgetLinkedItems { + linkedItems { + nodes { + linkId + linkType + linkCreatedAt + linkUpdatedAt + workItem { + id + widgets { + ... on WorkItemWidgetMilestone { + milestone { + id + } + } + } + } + } + } + } + } + } + GRAPHQL + end + + before do + create(:work_item_link, source: item1, target: related_items[0], link_type: 'relates_to') + end + + it 'executes limited number of N+1 queries', :use_sql_query_cache do + control = ActiveRecord::QueryRecorder.new(skip_cached: false) do + post_graphql(query, current_user: current_user) + end + + create(:work_item_link, source: item1, target: related_items[1], link_type: 'relates_to') + create(:work_item_link, source: item1, target: related_items[2], link_type: 'relates_to') + + expect_graphql_errors_to_be_empty + # TODO: Fix N+1 queries executed for the linked work item widgets + # https://gitlab.com/gitlab-org/gitlab/-/issues/420605 + expect { post_graphql(query, current_user: current_user) } + .not_to exceed_all_query_limit(control).with_threshold(11) + end + end + def item_ids graphql_dig_at(items_data, :node, :id) end |