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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-03 15:11:38 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-03 15:11:38 +0300
commit91035102b4e313787a45217ff12bb88f7f48bf20 (patch)
tree0b4c1147165bee39e199acae3d606683de97e087 /spec/requests
parentdda49284fcd29d631c2b7642a6430fdfa5793f48 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/graphql/group_query_spec.rb69
-rw-r--r--spec/requests/api/graphql/project_query_spec.rb84
2 files changed, 153 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/group_query_spec.rb b/spec/requests/api/graphql/group_query_spec.rb
index fd0ee5d52b9..41750f44794 100644
--- a/spec/requests/api/graphql/group_query_spec.rb
+++ b/spec/requests/api/graphql/group_query_spec.rb
@@ -122,6 +122,75 @@ RSpec.describe 'getting group information' do
end
end
+ context 'with timelog categories' do
+ let_it_be(:group) { create(:group) }
+ let_it_be(:timelog_category) { create(:timelog_category, namespace: group, name: 'TimelogCategoryTest') }
+
+ context 'when user is guest' do
+ it 'includes empty timelog categories array' do
+ post_graphql(group_query(group), current_user: user2)
+
+ expect(graphql_data_at(:group, :timelogCategories, :nodes)).to match([])
+ end
+ end
+
+ context 'when user has reporter role' do
+ before do
+ group.add_reporter(user2)
+ end
+
+ it 'returns the timelog category with all its fields' do
+ post_graphql(group_query(group), current_user: user2)
+
+ expect(graphql_data_at(:group, :timelogCategories, :nodes))
+ .to contain_exactly(a_graphql_entity_for(timelog_category))
+ end
+ end
+
+ context 'for N+1 queries' do
+ let!(:group1) { create(:group) }
+ let!(:group2) { create(:group) }
+
+ before do
+ group1.add_reporter(user2)
+ group2.add_reporter(user2)
+ end
+
+ it 'avoids N+1 database queries' do
+ pending('See: https://gitlab.com/gitlab-org/gitlab/-/issues/369396')
+
+ ctx = { current_user: user2 }
+
+ baseline_query = <<~GQL
+ query {
+ a: group(fullPath: "#{group1.full_path}") { ... g }
+ }
+
+ fragment g on Group {
+ timelogCategories { nodes { name } }
+ }
+ GQL
+
+ query = <<~GQL
+ query {
+ a: group(fullPath: "#{group1.full_path}") { ... g }
+ b: group(fullPath: "#{group2.full_path}") { ... g }
+ }
+
+ fragment g on Group {
+ timelogCategories { nodes { name } }
+ }
+ GQL
+
+ control = ActiveRecord::QueryRecorder.new do
+ run_with_clean_state(baseline_query, context: ctx)
+ end
+
+ expect { run_with_clean_state(query, context: ctx) }.not_to exceed_query_limit(control)
+ end
+ end
+ end
+
context "when authenticated as admin" do
it "returns any existing group" do
post_graphql(group_query(private_group), current_user: admin)
diff --git a/spec/requests/api/graphql/project_query_spec.rb b/spec/requests/api/graphql/project_query_spec.rb
index 310a8e9fa33..298462268fc 100644
--- a/spec/requests/api/graphql/project_query_spec.rb
+++ b/spec/requests/api/graphql/project_query_spec.rb
@@ -190,4 +190,88 @@ RSpec.describe 'getting project information' do
end
end
end
+
+ context 'with timelog categories' do
+ let_it_be(:timelog_category) do
+ create(:timelog_category, namespace: project.project_namespace, name: 'TimelogCategoryTest')
+ end
+
+ let(:project_fields) do
+ <<~GQL
+ timelogCategories {
+ nodes {
+ #{all_graphql_fields_for('TimeTrackingTimelogCategory')}
+ }
+ }
+ GQL
+ end
+
+ context 'when user is guest and the project is public' do
+ before do
+ project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
+ end
+
+ it 'includes empty timelog categories array' do
+ post_graphql(query, current_user: current_user)
+
+ expect(graphql_data_at(:project, :timelogCategories, :nodes)).to match([])
+ end
+ end
+
+ context 'when user has reporter role' do
+ before do
+ project.add_reporter(current_user)
+ end
+
+ it 'returns the timelog category with all its fields' do
+ post_graphql(query, current_user: current_user)
+
+ expect(graphql_data_at(:project, :timelogCategories, :nodes))
+ .to contain_exactly(a_graphql_entity_for(timelog_category))
+ end
+ end
+
+ context 'for N+1 queries' do
+ let!(:project1) { create(:project) }
+ let!(:project2) { create(:project) }
+
+ before do
+ project1.add_reporter(current_user)
+ project2.add_reporter(current_user)
+ end
+
+ it 'avoids N+1 database queries' do
+ pending('See: https://gitlab.com/gitlab-org/gitlab/-/issues/369396')
+
+ ctx = { current_user: current_user }
+
+ baseline_query = <<~GQL
+ query {
+ a: project(fullPath: "#{project1.full_path}") { ... p }
+ }
+
+ fragment p on Project {
+ timelogCategories { nodes { name } }
+ }
+ GQL
+
+ query = <<~GQL
+ query {
+ a: project(fullPath: "#{project1.full_path}") { ... p }
+ b: project(fullPath: "#{project2.full_path}") { ... p }
+ }
+
+ fragment p on Project {
+ timelogCategories { nodes { name } }
+ }
+ GQL
+
+ control = ActiveRecord::QueryRecorder.new do
+ run_with_clean_state(baseline_query, context: ctx)
+ end
+
+ expect { run_with_clean_state(query, context: ctx) }.not_to exceed_query_limit(control)
+ end
+ end
+ end
end