diff options
Diffstat (limited to 'spec/support/shared_examples/graphql')
4 files changed, 32 insertions, 31 deletions
diff --git a/spec/support/shared_examples/graphql/jira_import/jira_import_resolver_shared_examples.rb b/spec/support/shared_examples/graphql/jira_import/jira_import_resolver_shared_examples.rb index 2b96010477c..b2047f1d32c 100644 --- a/spec/support/shared_examples/graphql/jira_import/jira_import_resolver_shared_examples.rb +++ b/spec/support/shared_examples/graphql/jira_import/jira_import_resolver_shared_examples.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -shared_examples 'no Jira import data present' do +RSpec.shared_examples 'no Jira import data present' do it 'returns none' do expect(resolve_imports).to eq JiraImportState.none end end -shared_examples 'no Jira import access' do +RSpec.shared_examples 'no Jira import access' do it 'raises error' do expect do resolve_imports diff --git a/spec/support/shared_examples/graphql/mutation_shared_examples.rb b/spec/support/shared_examples/graphql/mutation_shared_examples.rb index 022d41c0bdd..86d2bb6c747 100644 --- a/spec/support/shared_examples/graphql/mutation_shared_examples.rb +++ b/spec/support/shared_examples/graphql/mutation_shared_examples.rb @@ -7,13 +7,23 @@ # # There must be a method or let called `mutation` defined that executes # the mutation. -RSpec.shared_examples 'a mutation that returns top-level errors' do |errors:| +RSpec.shared_examples 'a mutation that returns top-level errors' do |errors: []| + let(:match_errors) { eq(errors) } + it do post_graphql_mutation(mutation, current_user: current_user) error_messages = graphql_errors.map { |e| e['message'] } - expect(error_messages).to eq(errors) + expect(error_messages).to match_errors + end +end + +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 end end diff --git a/spec/support/shared_examples/graphql/projects/services_resolver_shared_examples.rb b/spec/support/shared_examples/graphql/projects/services_resolver_shared_examples.rb index 4bed322564a..94b7ed1618d 100644 --- a/spec/support/shared_examples/graphql/projects/services_resolver_shared_examples.rb +++ b/spec/support/shared_examples/graphql/projects/services_resolver_shared_examples.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -shared_examples 'no project services' do +RSpec.shared_examples 'no project services' do it 'returns empty collection' do expect(resolve_services).to eq [] end end -shared_examples 'cannot access project services' do +RSpec.shared_examples 'cannot access project services' do it 'raises error' do expect do resolve_services diff --git a/spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb b/spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb index 58cd3d21f66..67d1c2a8254 100644 --- a/spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb +++ b/spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb @@ -1,7 +1,12 @@ # frozen_string_literal: true RSpec.shared_examples 'resolving an issuable in GraphQL' do |type| - subject { mutation.resolve_issuable(type: type, parent_path: parent.full_path, iid: issuable.iid) } + include GraphqlHelpers + + let(:parent_path) { parent.full_path } + let(:iid) { issuable.iid } + + subject(:result) { mutation.resolve_issuable(type: type, parent_path: parent_path, iid: iid) } context 'when user has access' do before do @@ -9,37 +14,23 @@ RSpec.shared_examples 'resolving an issuable in GraphQL' do |type| end it 'resolves issuable by iid' do - result = type == :merge_request ? subject.sync : subject expect(result).to eq(issuable) end - it 'uses the correct Resolver to resolve issuable' do - resolver_class = "Resolvers::#{type.to_s.classify.pluralize}Resolver".constantize - resolve_method = type == :epic ? :resolve_group : :resolve_project - resolved_parent = mutation.send(resolve_method, full_path: parent.full_path) - - allow(mutation).to receive(resolve_method) - .with(full_path: parent.full_path) - .and_return(resolved_parent) - - expect(resolver_class.single).to receive(:new) - .with(object: resolved_parent, context: context, field: nil) - .and_call_original - - subject - end - - it 'returns nil if issuable is not found' do - result = mutation.resolve_issuable(type: type, parent_path: parent.full_path, iid: "100") - result = result.respond_to?(:sync) ? result.sync : result + context 'the IID does not refer to a valid issuable' do + let(:iid) { '100' } - expect(result).to be_nil + it 'returns nil' do + expect(result).to be_nil + end end - it 'returns nil if parent path is not present' do - result = mutation.resolve_issuable(type: type, parent_path: "", iid: issuable.iid) + context 'the parent path is not present' do + let(:parent_path) { '' } - expect(result).to be_nil + it 'returns nil' do + expect(result).to be_nil + end end end end |