diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/requests/api/graphql/work_item_spec.rb | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/work_item_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/work_item_spec.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/work_item_spec.rb b/spec/requests/api/graphql/work_item_spec.rb new file mode 100644 index 00000000000..bc5a8b3e006 --- /dev/null +++ b/spec/requests/api/graphql/work_item_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Query.work_item(id)' do + include GraphqlHelpers + + let_it_be(:developer) { create(:user) } + let_it_be(:project) { create(:project, :private).tap { |project| project.add_developer(developer) } } + let_it_be(:work_item) { create(:work_item, project: project) } + + let(:current_user) { developer } + let(:work_item_data) { graphql_data['workItem'] } + let(:work_item_fields) { all_graphql_fields_for('WorkItem') } + let(:global_id) { work_item.to_gid.to_s } + + let(:query) do + graphql_query_for('workItem', { 'id' => global_id }, work_item_fields) + end + + context 'when the user can read the work item' do + before do + post_graphql(query, current_user: current_user) + end + + it_behaves_like 'a working graphql query' + + it 'returns all fields' do + expect(work_item_data).to include( + 'description' => work_item.description, + 'id' => work_item.to_gid.to_s, + 'iid' => work_item.iid.to_s, + 'lockVersion' => work_item.lock_version, + 'state' => "OPEN", + 'title' => work_item.title, + 'workItemType' => hash_including('id' => work_item.work_item_type.to_gid.to_s) + ) + end + + context 'when an Issue Global ID is provided' do + let(:global_id) { Issue.find(work_item.id).to_gid.to_s } + + it 'allows an Issue GID as input' do + expect(work_item_data).to include('id' => work_item.to_gid.to_s) + end + end + end + + context 'when the user can not read the work item' do + let(:current_user) { create(:user) } + + before do + post_graphql(query) + end + + it 'returns an access error' do + expect(work_item_data).to be_nil + expect(graphql_errors).to contain_exactly( + hash_including('message' => ::Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR) + ) + end + end + + context 'when the work_items feature flag is disabled' do + before do + stub_feature_flags(work_items: false) + end + + it 'returns nil' do + post_graphql(query) + + expect(work_item_data).to be_nil + end + end +end |