summaryrefslogtreecommitdiff
path: root/spec/support/matchers/graphql_matchers.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-05-23 09:55:14 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-06-05 09:41:25 +0200
commit9b54580773d4453917545204ff7db6c689ba0d32 (patch)
tree7eb9cd3bde8e9ce9073fa76cf564934c6f4ccf1b /spec/support/matchers/graphql_matchers.rb
parent0ff160bb3e353710e8f7b0f29566e8388bf9b340 (diff)
downloadgitlab-ce-bvl-graphql-start-34754.tar.gz
Initial setup GraphQL using graphql-ruby 1.8bvl-graphql-start-34754
- All definitions have been replaced by classes: http://graphql-ruby.org/schema/class_based_api.html - Authorization & Presentation have been refactored to work in the class based system - Loaders have been replaced by resolvers - Times are now coersed as ISO 8601
Diffstat (limited to 'spec/support/matchers/graphql_matchers.rb')
-rw-r--r--spec/support/matchers/graphql_matchers.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb
index c0ed16ecaba..ba7a1c8cde0 100644
--- a/spec/support/matchers/graphql_matchers.rb
+++ b/spec/support/matchers/graphql_matchers.rb
@@ -1,31 +1,40 @@
RSpec::Matchers.define :require_graphql_authorizations do |*expected|
match do |field|
- authorizations = field.metadata[:authorize]
-
- expect(authorizations).to contain_exactly(*expected)
+ field_definition = field.metadata[:type_class]
+ expect(field_definition).to respond_to(:required_permissions)
+ expect(field_definition.required_permissions).to contain_exactly(*expected)
end
end
RSpec::Matchers.define :have_graphql_fields do |*expected|
match do |kls|
- expect(kls.fields.keys).to contain_exactly(*expected.map(&:to_s))
+ field_names = expected.map { |name| GraphqlHelpers.fieldnamerize(name) }
+ expect(kls.fields.keys).to contain_exactly(*field_names)
end
end
RSpec::Matchers.define :have_graphql_arguments do |*expected|
+ include GraphqlHelpers
+
match do |field|
- expect(field.arguments.keys).to contain_exactly(*expected.map(&:to_s))
+ argument_names = expected.map { |name| GraphqlHelpers.fieldnamerize(name) }
+ expect(field.arguments.keys).to contain_exactly(*argument_names)
end
end
RSpec::Matchers.define :have_graphql_type do |expected|
match do |field|
- expect(field.type).to eq(expected)
+ expect(field.type).to eq(expected.to_graphql)
end
end
RSpec::Matchers.define :have_graphql_resolver do |expected|
match do |field|
- expect(field.resolve_proc).to eq(expected)
+ case expected
+ when Method
+ expect(field.metadata[:type_class].resolve_proc).to eq(expected)
+ else
+ expect(field.metadata[:type_class].resolver).to eq(expected)
+ end
end
end