Commit e6957553 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'clean-up-access-error-graphql-specs-238959' into 'master'

Clean up GraphQL access error specs with shared example

See merge request gitlab-org/gitlab!40053
parents 0cec257b 44b7005b
......@@ -21,9 +21,7 @@ RSpec.describe 'Create a new cluster agent' do
end
context 'without project permissions' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not create cluster agent' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Clusters::Agent, :count)
......
......@@ -18,9 +18,7 @@ RSpec.describe 'Add an issue to an Epic' do
end
shared_examples 'mutation without access' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not add issue to the epic' do
post_graphql_mutation(mutation, current_user: current_user)
......
......@@ -35,9 +35,7 @@ RSpec.describe 'Creating an Epic' do
stub_licensed_features(epics: true)
end
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not create epic' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Epic, :count)
......
......@@ -21,9 +21,7 @@ RSpec.describe 'Set an Epic Subscription' do
end
context 'when epics feature is disabled' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not subscribe user to the epic' do
post_graphql_mutation(mutation, current_user: current_user)
......
......@@ -39,9 +39,7 @@ RSpec.describe Mutations::Epics::Update do
stub_licensed_features(epics: true)
end
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not update the epic' do
post_graphql_mutation(mutation, current_user: current_user)
......
......@@ -38,9 +38,7 @@ RSpec.describe 'Creating an Iteration' do
stub_licensed_features(iterations: true)
end
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not create iteration' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Iteration, :count)
......
......@@ -36,9 +36,7 @@ RSpec.describe 'Updating an Iteration' do
group.add_guest(current_user)
end
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not update iteration' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(iteration, :title)
......
......@@ -24,9 +24,7 @@ RSpec.describe 'Creating a Requirement' do
stub_licensed_features(requirements: true)
end
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not create requirement' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(RequirementsManagement::Requirement, :count)
......
......@@ -17,9 +17,7 @@ RSpec.describe 'Updating a Requirement' do
end
shared_examples 'requirement update fails' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist '\
'or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not update requirement' do
expect do
......
......@@ -32,9 +32,7 @@ RSpec.describe 'Adding an AwardEmoji' do
context 'when the user does not have permission' do
it_behaves_like 'a mutation that does not create an AwardEmoji'
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when the user has permission' do
......
......@@ -33,9 +33,7 @@ RSpec.describe 'Removing an AwardEmoji' do
shared_examples 'a mutation that does not authorize the user' do
it_behaves_like 'a mutation that does not destroy an AwardEmoji'
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when the current_user does not own the award emoji' do
......
......@@ -143,8 +143,6 @@ RSpec.describe 'Toggling an AwardEmoji' do
context 'when the user does not have permission' do
it_behaves_like 'a mutation that does not create or destroy an AwardEmoji'
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
end
......@@ -15,8 +15,7 @@ RSpec.describe 'Update of an existing board list' do
let(:mutation_response) { graphql_mutation_response(:update_board_list) }
context 'the user is not allowed to read board lists' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
before do
......
......@@ -15,8 +15,7 @@ RSpec.describe 'Creation of a new branch' do
let(:mutation_response) { graphql_mutation_response(:create_branch) }
context 'the user is not allowed to create a branch' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user has permissions to create a branch' do
......
......@@ -24,8 +24,7 @@ RSpec.describe 'Creation of a new commit' do
let(:mutation_response) { graphql_mutation_response(:commit_create) }
context 'the user is not allowed to create a commit' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user has permissions to create a commit' do
......
......@@ -20,8 +20,7 @@ RSpec.describe 'Toggling the resolve status of a discussion' do
context 'when the user does not have permission' do
let_it_be(:current_user) { create(:user) }
it_behaves_like 'a mutation that returns top-level errors',
errors: ["The resource that you are attempting to access does not exist or you don't have permission to perform this action"]
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user has permission' do
......
......@@ -32,12 +32,7 @@ RSpec.describe 'Setting an issue as locked' do
end
context 'when the user is not allowed to update the issue' do
it 'returns an error' do
error = "The resource that you are attempting to access does not exist or you don't have permission to perform this action"
post_graphql_mutation(mutation, current_user: current_user)
expect(graphql_errors).to include(a_hash_including('message' => error))
end
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user is allowed to update the issue' do
......
......@@ -20,8 +20,7 @@ RSpec.describe 'Update of an existing issue' do
let(:mutation_response) { graphql_mutation_response(:update_issue) }
context 'the user is not allowed to update issue' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user has permissions to update issue' do
......
......@@ -24,8 +24,7 @@ RSpec.describe 'Creation of a new merge request' do
let(:mutation_response) { graphql_mutation_response(:merge_request_create) }
context 'the user is not allowed to create a branch' do
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user has permissions to create a merge request' do
......
......@@ -21,8 +21,7 @@ RSpec.describe 'Destroying a Note' do
context 'when the user does not have permission' do
let(:current_user) { create(:user) }
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not destroy the Note' do
expect do
......
......@@ -59,8 +59,7 @@ RSpec.describe 'Updating an image DiffNote' do
context 'when the user does not have permission' do
let_it_be(:current_user) { create(:user) }
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not update the DiffNote' do
post_graphql_mutation(mutation, current_user: current_user)
......
......@@ -22,8 +22,7 @@ RSpec.describe 'Updating a Note' do
context 'when the user does not have permission' do
let_it_be(:current_user) { create(:user) }
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not update the Note' do
post_graphql_mutation(mutation, current_user: current_user)
......
......@@ -59,7 +59,6 @@ RSpec.describe 'Marking all todos done' do
context 'when user is not logged in' do
let(:current_user) { nil }
it_behaves_like 'a mutation that returns top-level errors',
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
it_behaves_like 'a mutation that returns a top-level access error'
end
end
......@@ -63,14 +63,11 @@ RSpec.describe 'Marking todos done' do
context 'when todo does not belong to requesting user' do
let(:input) { { id: other_user_todo.to_global_id.to_s } }
let(:access_error) { 'The resource that you are attempting to access does not exist or you don\'t have permission to perform this action' }
it 'contains the expected error' do
post_graphql_mutation(mutation, current_user: current_user)
it_behaves_like 'a mutation that returns a top-level access error'
errors = json_response['errors']
expect(errors).not_to be_blank
expect(errors.first['message']).to eq(access_error)
it 'results in the correct todo states' do
post_graphql_mutation(mutation, current_user: current_user)
expect(todo1.reload.state).to eq('pending')
expect(todo2.reload.state).to eq('done')
......
......@@ -63,14 +63,11 @@ RSpec.describe 'Restoring Todos' do
context 'when todo does not belong to requesting user' do
let(:input) { { id: other_user_todo.to_global_id.to_s } }
let(:access_error) { 'The resource that you are attempting to access does not exist or you don\'t have permission to perform this action' }
it 'contains the expected error' do
post_graphql_mutation(mutation, current_user: current_user)
it_behaves_like 'a mutation that returns a top-level access error'
errors = json_response['errors']
expect(errors).not_to be_blank
expect(errors.first['message']).to eq(access_error)
it 'results in the correct todo states' do
post_graphql_mutation(mutation, current_user: current_user)
expect(todo1.reload.state).to eq('done')
expect(todo2.reload.state).to eq('pending')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment