Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb')
-rw-r--r--spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb55
1 files changed, 38 insertions, 17 deletions
diff --git a/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb b/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb
index 97873b01338..bcede4d37dd 100644
--- a/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb
+++ b/spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb
@@ -5,11 +5,12 @@ require 'spec_helper'
RSpec.describe 'Setting assignees of a merge request' do
include GraphqlHelpers
- let(:current_user) { create(:user) }
- let(:merge_request) { create(:merge_request) }
- let(:project) { merge_request.project }
- let(:assignee) { create(:user) }
- let(:assignee2) { create(:user) }
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:current_user) { create(:user, developer_projects: [project]) }
+ let_it_be(:assignee) { create(:user) }
+ let_it_be(:assignee2) { create(:user) }
+ let_it_be_with_reload(:merge_request) { create(:merge_request, source_project: project) }
+
let(:input) { { assignee_usernames: [assignee.username] } }
let(:expected_result) do
[{ 'username' => assignee.username }]
@@ -44,10 +45,19 @@ RSpec.describe 'Setting assignees of a merge request' do
mutation_response['mergeRequest']['assignees']['nodes']
end
+ def run_mutation!
+ recorder = ActiveRecord::QueryRecorder.new do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end
+
+ expect(recorder.count).to be <= db_query_limit
+ end
+
before do
- project.add_developer(current_user)
project.add_developer(assignee)
project.add_developer(assignee2)
+
+ merge_request.update!(assignees: [])
end
it 'returns an error if the user is not allowed to update the merge request' do
@@ -56,23 +66,29 @@ RSpec.describe 'Setting assignees of a merge request' do
expect(graphql_errors).not_to be_empty
end
- it 'does not allow members without the right permission to add assignees' do
- user = create(:user)
- project.add_guest(user)
+ context 'when the current user does not have permission to add assignees' do
+ let(:current_user) { create(:user) }
+ let(:db_query_limit) { 27 }
- post_graphql_mutation(mutation, current_user: user)
+ it 'does not change the assignees' do
+ project.add_guest(current_user)
- expect(graphql_errors).not_to be_empty
+ expect { run_mutation! }.not_to change { merge_request.reset.assignees.pluck(:id) }
+
+ expect(graphql_errors).not_to be_empty
+ end
end
context 'with assignees already assigned' do
+ let(:db_query_limit) { 39 }
+
before do
merge_request.assignees = [assignee2]
merge_request.save!
end
it 'replaces the assignee' do
- post_graphql_mutation(mutation, current_user: current_user)
+ run_mutation!
expect(response).to have_gitlab_http_status(:success)
expect(mutation_assignee_nodes).to match_array(expected_result)
@@ -80,6 +96,7 @@ RSpec.describe 'Setting assignees of a merge request' do
end
context 'when passing an empty list of assignees' do
+ let(:db_query_limit) { 31 }
let(:input) { { assignee_usernames: [] } }
before do
@@ -88,7 +105,7 @@ RSpec.describe 'Setting assignees of a merge request' do
end
it 'removes assignee' do
- post_graphql_mutation(mutation, current_user: current_user)
+ run_mutation!
expect(response).to have_gitlab_http_status(:success)
expect(mutation_assignee_nodes).to eq([])
@@ -96,7 +113,9 @@ RSpec.describe 'Setting assignees of a merge request' do
end
context 'when passing append as true' do
- let(:input) { { assignee_usernames: [assignee2.username], operation_mode: Types::MutationOperationModeEnum.enum[:append] } }
+ let(:mode) { Types::MutationOperationModeEnum.enum[:append] }
+ let(:input) { { assignee_usernames: [assignee2.username], operation_mode: mode } }
+ let(:db_query_limit) { 20 }
before do
# In CE, APPEND is a NOOP as you can't have multiple assignees
@@ -108,7 +127,7 @@ RSpec.describe 'Setting assignees of a merge request' do
end
it 'does not replace the assignee in CE' do
- post_graphql_mutation(mutation, current_user: current_user)
+ run_mutation!
expect(response).to have_gitlab_http_status(:success)
expect(mutation_assignee_nodes).to match_array(expected_result)
@@ -116,7 +135,9 @@ RSpec.describe 'Setting assignees of a merge request' do
end
context 'when passing remove as true' do
- let(:input) { { assignee_usernames: [assignee.username], operation_mode: Types::MutationOperationModeEnum.enum[:remove] } }
+ let(:db_query_limit) { 31 }
+ let(:mode) { Types::MutationOperationModeEnum.enum[:remove] }
+ let(:input) { { assignee_usernames: [assignee.username], operation_mode: mode } }
let(:expected_result) { [] }
before do
@@ -125,7 +146,7 @@ RSpec.describe 'Setting assignees of a merge request' do
end
it 'removes the users in the list, while adding none' do
- post_graphql_mutation(mutation, current_user: current_user)
+ run_mutation!
expect(response).to have_gitlab_http_status(:success)
expect(mutation_assignee_nodes).to match_array(expected_result)