diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/requests/api/graphql/mutations/work_items | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/mutations/work_items')
-rw-r--r-- | spec/requests/api/graphql/mutations/work_items/delete_task_spec.rb | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/work_items/delete_task_spec.rb b/spec/requests/api/graphql/mutations/work_items/delete_task_spec.rb new file mode 100644 index 00000000000..05d3587d342 --- /dev/null +++ b/spec/requests/api/graphql/mutations/work_items/delete_task_spec.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe "Delete a task in a work item's description" do + include GraphqlHelpers + + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user).tap { |user| project.add_developer(user) } } + let_it_be(:task) { create(:work_item, :task, project: project, author: developer) } + let_it_be(:work_item, refind: true) do + create(:work_item, project: project, description: "- [ ] #{task.to_reference}+", lock_version: 3) + end + + before_all do + create(:issue_link, source_id: work_item.id, target_id: task.id) + end + + let(:lock_version) { work_item.lock_version } + let(:input) do + { + 'id' => work_item.to_global_id.to_s, + 'lockVersion' => lock_version, + 'taskData' => { + 'id' => task.to_global_id.to_s, + 'lineNumberStart' => 1, + 'lineNumberEnd' => 1 + } + } + end + + let(:mutation) { graphql_mutation(:workItemDeleteTask, input) } + let(:mutation_response) { graphql_mutation_response(:work_item_delete_task) } + + context 'the user is not allowed to update a work item' do + let(:current_user) { create(:user) } + + it_behaves_like 'a mutation that returns a top-level access error' + end + + context 'when user can update the description but not delete the task' do + let(:current_user) { create(:user).tap { |u| project.add_developer(u) } } + + it_behaves_like 'a mutation that returns a top-level access error' + end + + context 'when user has permissions to remove a task' do + let(:current_user) { developer } + + it 'removes the task from the work item' do + expect do + post_graphql_mutation(mutation, current_user: current_user) + work_item.reload + end.to change(WorkItem, :count).by(-1).and( + change(IssueLink, :count).by(-1) + ).and( + change(work_item, :description).from("- [ ] #{task.to_reference}+").to('') + ) + + expect(response).to have_gitlab_http_status(:success) + expect(mutation_response['workItem']).to include('id' => work_item.to_global_id.to_s) + end + + context 'when removing the task fails' do + let(:lock_version) { 2 } + + it 'makes no changes to the DB and returns an error message' do + expect do + post_graphql_mutation(mutation, current_user: current_user) + work_item.reload + end.to not_change(WorkItem, :count).and( + not_change(work_item, :description) + ) + + expect(mutation_response['errors']).to contain_exactly('Stale work item. Check lock version') + end + end + + context 'when the work_items feature flag is disabled' do + before do + stub_feature_flags(work_items: false) + end + + it 'does nothing and returns and error' do + expect do + post_graphql_mutation(mutation, current_user: current_user) + end.to not_change(WorkItem, :count) + + expect(mutation_response['errors']).to contain_exactly('`work_items` feature flag disabled for this project') + end + end + end +end |