debian-mirror-gitlab/spec/requests/api/graphql/mutations/issues/update_spec.rb

138 lines
5 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Update of an existing issue' do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue) { create(:issue, project: project) }
2021-10-27 15:23:28 +05:30
let_it_be(:label1) { create(:label, project: project) }
let_it_be(:label2) { create(:label, project: project) }
2021-09-30 23:02:18 +05:30
2020-10-24 23:57:45 +05:30
let(:input) do
{
2021-01-03 14:25:43 +05:30
'iid' => issue.iid.to_s,
'title' => 'new title',
'description' => 'new description',
'confidential' => true,
2021-06-08 01:23:25 +05:30
'dueDate' => Date.tomorrow.strftime('%Y-%m-%d'),
'type' => 'ISSUE'
2020-10-24 23:57:45 +05:30
}
end
2021-10-27 15:23:28 +05:30
let(:extra_params) { { project_path: project.full_path, locked: true } }
let(:input_params) { input.merge(extra_params) }
let(:mutation) { graphql_mutation(:update_issue, input_params) }
2020-10-24 23:57:45 +05:30
let(:mutation_response) { graphql_mutation_response(:update_issue) }
context 'the user is not allowed to update issue' do
2020-11-24 15:15:51 +05:30
it_behaves_like 'a mutation that returns a top-level access error'
2020-10-24 23:57:45 +05:30
end
context 'when user has permissions to update issue' do
before do
project.add_developer(current_user)
end
it 'updates the issue' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
2021-01-03 14:25:43 +05:30
expect(mutation_response['issue']).to include(input)
expect(mutation_response['issue']).to include('discussionLocked' => true)
2020-10-24 23:57:45 +05:30
end
2021-10-27 15:23:28 +05:30
2021-11-11 11:23:49 +05:30
context 'when issue_type is updated' do
let(:input) { { 'iid' => issue.iid.to_s, 'type' => 'INCIDENT' } }
it 'updates issue_type and work_item_type' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
issue.reload
end.to change { issue.work_item_type.base_type }.from('issue').to('incident').and(
change(issue, :issue_type).from('issue').to('incident')
)
end
end
2021-10-27 15:23:28 +05:30
context 'setting labels' do
let(:mutation) do
graphql_mutation(:update_issue, input_params) do
<<~QL
issue {
labels {
nodes {
id
}
}
}
errors
QL
end
end
context 'reset labels' do
let(:input_params) { input.merge(extra_params).merge({ labelIds: [label1.id, label2.id] }) }
it 'resets labels' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(json_response['errors']).to be_nil
expect(mutation_response['issue']['labels']).to include({ "nodes" => [{ "id" => label1.to_global_id.to_s }, { "id" => label2.to_global_id.to_s }] })
end
context 'reset labels and add labels' do
let(:input_params) { input.merge(extra_params).merge({ labelIds: [label1.id], addLabelIds: [label2.id] }) }
it 'returns error for mutually exclusive arguments' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(json_response['errors'].first['message']).to eq('labelIds is mutually exclusive with any of addLabelIds or removeLabelIds')
expect(mutation_response).to be_nil
end
end
context 'reset labels and remove labels' do
let(:input_params) { input.merge(extra_params).merge({ labelIds: [label1.id], removeLabelIds: [label2.id] }) }
it 'returns error for mutually exclusive arguments' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(json_response['errors'].first['message']).to eq('labelIds is mutually exclusive with any of addLabelIds or removeLabelIds')
expect(mutation_response).to be_nil
end
end
context 'with global label ids' do
let(:input_params) { input.merge(extra_params).merge({ labelIds: [label1.to_global_id.to_s, label2.to_global_id.to_s] }) }
it 'resets labels' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(json_response['errors']).to be_nil
expect(mutation_response['issue']['labels']).to include({ "nodes" => [{ "id" => label1.to_global_id.to_s }, { "id" => label2.to_global_id.to_s }] })
end
end
end
context 'add and remove labels' do
let(:input_params) { input.merge(extra_params).merge({ addLabelIds: [label1.id], removeLabelIds: [label2.id] }) }
it 'returns error for mutually exclusive arguments' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(json_response['errors']).to be_nil
expect(mutation_response['issue']['labels']).to include({ "nodes" => [{ "id" => label1.to_global_id.to_s }] })
end
end
end
2020-10-24 23:57:45 +05:30
end
end