diff options
Diffstat (limited to 'spec/requests/api/graphql/mutations/work_items/update_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/mutations/work_items/update_spec.rb | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/work_items/update_spec.rb b/spec/requests/api/graphql/mutations/work_items/update_spec.rb new file mode 100644 index 00000000000..71b03103115 --- /dev/null +++ b/spec/requests/api/graphql/mutations/work_items/update_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Update a work item' do + include GraphqlHelpers + + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user).tap { |user| project.add_developer(user) } } + let_it_be(:work_item, refind: true) { create(:work_item, project: project) } + + let(:work_item_event) { 'CLOSE' } + let(:input) { { 'stateEvent' => work_item_event, 'title' => 'updated title' } } + + let(:mutation) { graphql_mutation(:workItemUpdate, input.merge('id' => work_item.to_global_id.to_s)) } + + let(:mutation_response) { graphql_mutation_response(:work_item_update) } + + 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 has permissions to update a work item' do + let(:current_user) { developer } + + context 'when the work item is open' do + it 'closes and updates the work item' do + expect do + post_graphql_mutation(mutation, current_user: current_user) + work_item.reload + end.to change(work_item, :state).from('opened').to('closed').and( + change(work_item, :title).from(work_item.title).to('updated title') + ) + + expect(response).to have_gitlab_http_status(:success) + expect(mutation_response['workItem']).to include( + 'state' => 'CLOSED', + 'title' => 'updated title' + ) + end + end + + context 'when the work item is closed' do + let(:work_item_event) { 'REOPEN' } + + before do + work_item.close! + end + + it 'reopens the work item' do + expect do + post_graphql_mutation(mutation, current_user: current_user) + work_item.reload + end.to change(work_item, :state).from('closed').to('opened') + + expect(response).to have_gitlab_http_status(:success) + expect(mutation_response['workItem']).to include( + 'state' => 'OPEN' + ) + end + end + + it_behaves_like 'has spam protection' do + let(:mutation_class) { ::Mutations::WorkItems::Update } + end + + context 'when the work_items feature flag is disabled' do + before do + stub_feature_flags(work_items: false) + end + + it 'does not update the work item and returns and error' do + expect do + post_graphql_mutation(mutation, current_user: current_user) + work_item.reload + end.to not_change(work_item, :title) + + expect(mutation_response['errors']).to contain_exactly('`work_items` feature flag disabled for this project') + end + end + end +end |