2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Shared example for expecting top-level errors.
|
|
|
|
# See https://graphql-ruby.org/mutations/mutation_errors#raising-errors
|
|
|
|
#
|
|
|
|
# { errors: [] }
|
|
|
|
#
|
|
|
|
# There must be a method or let called `mutation` defined that executes
|
|
|
|
# the mutation.
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.shared_examples 'a mutation that returns top-level errors' do |errors: []|
|
|
|
|
let(:match_errors) { eq(errors) }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it do
|
|
|
|
post_graphql_mutation(mutation, current_user: current_user)
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(graphql_errors).to be_present
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
error_messages = graphql_errors.map { |e| e['message'] }
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(error_messages).to match_errors
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
# There must be a method or let called `mutation` defined that executes
|
|
|
|
# the mutation.
|
|
|
|
RSpec.shared_examples 'a mutation that returns a top-level access error' do
|
|
|
|
include_examples 'a mutation that returns top-level errors',
|
|
|
|
errors: [Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR]
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.shared_examples 'an invalid argument to the mutation' do |argument_name:|
|
|
|
|
it_behaves_like 'a mutation that returns top-level errors' do
|
|
|
|
let(:match_errors) do
|
|
|
|
contain_exactly(include("invalid value for #{GraphqlHelpers.fieldnamerize(argument_name)}"))
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Shared example for expecting schema-level errors.
|
|
|
|
# See https://graphql-ruby.org/mutations/mutation_errors#errors-as-data
|
|
|
|
#
|
|
|
|
# { data: { mutationName: { errors: [] } } }
|
|
|
|
#
|
|
|
|
# There must be:
|
|
|
|
# - a method or let called `mutation` defined that executes the mutation
|
|
|
|
# - a `mutation_response` method defined that returns the data of the mutation response.
|
|
|
|
RSpec.shared_examples 'a mutation that returns errors in the response' do |errors:|
|
|
|
|
it do
|
|
|
|
post_graphql_mutation(mutation, current_user: current_user)
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(mutation_response['errors']).to match_array(errors)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|