1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'getting a collection of projects', feature_category: :source_code_management do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group, name: 'public-group') }
let_it_be(:projects) { create_list(:project, 5, :public, group: group) }
let_it_be(:other_project) { create(:project, :public, group: group) }
let(:filters) { {} }
let(:query) do
graphql_query_for(
:projects,
filters,
"nodes {#{all_graphql_fields_for('Project', max_depth: 1, excluded: ['productAnalyticsState'])} }"
)
end
before_all do
group.add_developer(current_user)
end
context 'when providing full_paths filter' do
let(:project_full_paths) { projects.map(&:full_path) }
let(:filters) { { full_paths: project_full_paths } }
let(:single_project_query) do
graphql_query_for(
:projects,
{ full_paths: [project_full_paths.first] },
"nodes {#{all_graphql_fields_for('Project', max_depth: 1, excluded: ['productAnalyticsState'])} }"
)
end
it_behaves_like 'a working graphql query that returns data' do
before do
post_graphql(query, current_user: current_user)
end
end
it 'avoids N+1 queries', :use_sql_query_cache, :clean_gitlab_redis_cache do
post_graphql(single_project_query, current_user: current_user)
query_count = ActiveRecord::QueryRecorder.new do
post_graphql(single_project_query, current_user: current_user)
end.count
# There is an N+1 query for max_member_access_for_user_ids
expect do
post_graphql(query, current_user: current_user)
end.not_to exceed_all_query_limit(query_count + 5)
end
it 'returns the expected projects' do
post_graphql(query, current_user: current_user)
returned_full_paths = graphql_data_at(:projects, :nodes).pluck('fullPath')
expect(returned_full_paths).to match_array(project_full_paths)
end
context 'when users provides more than 50 full_paths' do
let(:filters) { { full_paths: Array.new(51) { other_project.full_path } } }
it 'returns an error' do
post_graphql(query, current_user: current_user)
expect(graphql_errors).to contain_exactly(
hash_including('message' => _('You cannot provide more than 50 full_paths'))
)
end
end
end
end
|