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