diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 21:09:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 21:09:35 +0300 |
commit | 5bfb8d1fad825eec90b0af688c7cd1b352c9056e (patch) | |
tree | 385411919c4186d11a769385ad8dafeef6cc36a7 /spec/support | |
parent | aaf59610548d9b0fd01acfd50e831cbe519ecba2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
3 files changed, 22 insertions, 15 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 370162b45f0..1bb942ff39b 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -71,10 +71,10 @@ module GraphqlHelpers mutation_name = GraphqlHelpers.fieldnamerize(name) input_variable_name = "$#{input_variable_name_for_mutation(name)}" mutation_field = GitlabSchema.mutation.fields[mutation_name] - fields ||= all_graphql_fields_for(mutation_field.type) + fields ||= all_graphql_fields_for(mutation_field.type.to_graphql) query = <<~MUTATION - mutation(#{input_variable_name}: #{mutation_field.arguments['input'].type}) { + mutation(#{input_variable_name}: #{mutation_field.arguments['input'].type.to_graphql}) { #{mutation_name}(input: #{input_variable_name}) { #{fields} } @@ -118,15 +118,22 @@ module GraphqlHelpers GraphqlHelpers.fieldnamerize(input_type) end - def query_graphql_field(name, attributes = {}, fields = nil) - field_params = if attributes.present? + def field_with_params(name, attributes = {}) + namerized = GraphqlHelpers.fieldnamerize(name.to_s) + return "#{namerized}" if attributes.blank? + + field_params = if attributes.is_a?(Hash) "(#{attributes_to_graphql(attributes)})" else - '' + "(#{attributes})" end + "#{namerized}#{field_params}" + end + + def query_graphql_field(name, attributes = {}, fields = nil) <<~QUERY - #{GraphqlHelpers.fieldnamerize(name.to_s)}#{field_params} + #{field_with_params(name, attributes)} #{wrap_fields(fields || all_graphql_fields_for(name.to_s.classify))} QUERY end @@ -300,7 +307,7 @@ module GraphqlHelpers end def field_type(field) - field_type = field.type + field_type = field.type.respond_to?(:to_graphql) ? field.type.to_graphql : field.type # The type could be nested. For example `[GraphQL::STRING_TYPE]`: # - List diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb index 31b0290bb15..6439b68764e 100644 --- a/spec/support/matchers/graphql_matchers.rb +++ b/spec/support/matchers/graphql_matchers.rb @@ -2,7 +2,7 @@ RSpec::Matchers.define :require_graphql_authorizations do |*expected| match do |field| - expect(field.metadata[:authorize]).to eq(*expected) + expect(field.to_graphql.metadata[:authorize]).to eq(*expected) end end @@ -87,13 +87,13 @@ end RSpec::Matchers.define :have_graphql_type do |expected| match do |field| - expect(field.type).to eq(expected.to_graphql) + expect(field.type).to eq(expected) end end RSpec::Matchers.define :have_non_null_graphql_type do |expected| match do |field| - expect(field.type).to eq(!expected.to_graphql) + expect(field.type.to_graphql).to eq(!expected.to_graphql) end end @@ -101,16 +101,16 @@ RSpec::Matchers.define :have_graphql_resolver do |expected| match do |field| case expected when Method - expect(field.metadata[:type_class].resolve_proc).to eq(expected) + expect(field.to_graphql.metadata[:type_class].resolve_proc).to eq(expected) else - expect(field.metadata[:type_class].resolver).to eq(expected) + expect(field.to_graphql.metadata[:type_class].resolver).to eq(expected) end end end RSpec::Matchers.define :have_graphql_extension do |expected| match do |field| - expect(field.metadata[:type_class].extensions).to include(expected) + expect(field.to_graphql.metadata[:type_class].extensions).to include(expected) end end diff --git a/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb b/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb index ca77c68c130..4c80bbef153 100644 --- a/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb +++ b/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb @@ -15,7 +15,7 @@ RSpec.shared_context 'group and project boards query context' do board_parent_type, { 'fullPath' => board_parent.full_path }, <<~BOARDS - boards(#{board_params}) { + #{field_with_params('boards', board_params)} { pageInfo { startCursor endCursor @@ -35,7 +35,7 @@ RSpec.shared_context 'group and project boards query context' do board_parent_type, { 'fullPath' => board_parent.full_path }, <<~BOARD - board(#{board_params}) { + #{field_with_params('board', board_params)} { #{all_graphql_fields_for('board'.classify)} } BOARD |