diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
commit | 3b1af5cc7ed2666ff18b718ce5d30fa5a2756674 (patch) | |
tree | 3bc4a40e0ee51ec27eabf917c537033c0c5b14d4 /spec/requests/api/graphql/work_item_spec.rb | |
parent | 9bba14be3f2c211bf79e15769cd9b77bc73a13bc (diff) |
Add latest changes from gitlab-org/gitlab@16-1-stable-eev16.1.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/work_item_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/work_item_spec.rb | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/spec/requests/api/graphql/work_item_spec.rb b/spec/requests/api/graphql/work_item_spec.rb index dc5004a121b..6702224f303 100644 --- a/spec/requests/api/graphql/work_item_spec.rb +++ b/spec/requests/api/graphql/work_item_spec.rb @@ -69,7 +69,8 @@ RSpec.describe 'Query.work_item(id)', feature_category: :team_planning do 'deleteWorkItem' => false, 'adminWorkItem' => true, 'adminParentLink' => true, - 'setWorkItemMetadata' => true + 'setWorkItemMetadata' => true, + 'createNote' => true }, 'project' => hash_including('id' => project.to_gid.to_s, 'fullPath' => project.full_path) ) @@ -540,6 +541,114 @@ RSpec.describe 'Query.work_item(id)', feature_category: :team_planning do end end + describe 'notes widget' do + let(:work_item_fields) do + <<~GRAPHQL + id + widgets { + type + ... on WorkItemWidgetNotes { + system: discussions(filter: ONLY_ACTIVITY, first: 10) { nodes { id notes { nodes { id system internal body } } } }, + comments: discussions(filter: ONLY_COMMENTS, first: 10) { nodes { id notes { nodes { id system internal body } } } }, + all_notes: discussions(filter: ALL_NOTES, first: 10) { nodes { id notes { nodes { id system internal body } } } } + } + } + GRAPHQL + end + + context 'when fetching award emoji from notes' do + let(:work_item_fields) do + <<~GRAPHQL + id + widgets { + type + ... on WorkItemWidgetNotes { + discussions(filter: ONLY_COMMENTS, first: 10) { + nodes { + id + notes { + nodes { + id + body + maxAccessLevelOfAuthor + authorIsContributor + awardEmoji { + nodes { + name + user { + name + } + } + } + } + } + } + } + } + } + GRAPHQL + end + + let_it_be(:note) { create(:note, project: work_item.project, noteable: work_item) } + + before_all do + create(:award_emoji, awardable: note, name: 'rocket', user: developer) + end + + it 'returns award emoji data' do + all_widgets = graphql_dig_at(work_item_data, :widgets) + notes_widget = all_widgets.find { |x| x['type'] == 'NOTES' } + notes = graphql_dig_at(notes_widget['discussions'], :nodes).flat_map { |d| d['notes']['nodes'] } + + note_with_emoji = notes.find { |n| n['id'] == note.to_gid.to_s } + + expect(note_with_emoji).to include( + 'awardEmoji' => { + 'nodes' => include( + hash_including( + 'name' => 'rocket', + 'user' => { + 'name' => developer.name + } + ) + ) + } + ) + end + + it 'returns author contributor status and max access level' do + all_widgets = graphql_dig_at(work_item_data, :widgets) + notes_widget = all_widgets.find { |x| x['type'] == 'NOTES' } + notes = graphql_dig_at(notes_widget['discussions'], :nodes).flat_map { |d| d['notes']['nodes'] } + + expect(notes).to contain_exactly( + hash_including('maxAccessLevelOfAuthor' => 'Owner', 'authorIsContributor' => false) + ) + end + + it 'avoids N+1 queries' do + another_user = create(:user).tap { |u| note.resource_parent.add_developer(u) } + create(:note, project: note.project, noteable: work_item, author: another_user) + + post_graphql(query, current_user: developer) + + control = ActiveRecord::QueryRecorder.new { post_graphql(query, current_user: developer) } + + expect_graphql_errors_to_be_empty + + another_note = create(:note, project: work_item.project, noteable: work_item) + create(:award_emoji, awardable: another_note, name: 'star', user: guest) + another_user = create(:user).tap { |u| note.resource_parent.add_developer(u) } + note_with_different_user = create(:note, project: note.project, noteable: work_item, author: another_user) + create(:award_emoji, awardable: note_with_different_user, name: 'star', user: developer) + + # TODO: Fix existing N+1 queries in https://gitlab.com/gitlab-org/gitlab/-/issues/414747 + expect { post_graphql(query, current_user: developer) }.not_to exceed_query_limit(control).with_threshold(3) + expect_graphql_errors_to_be_empty + end + end + end + context 'when an Issue Global ID is provided' do let(:global_id) { Issue.find(work_item.id).to_gid.to_s } |