2017-08-16 09:04:41 -04:00
|
|
|
RSpec::Matchers.define :require_graphql_authorizations do |*expected|
|
|
|
|
match do |field|
|
2018-05-23 03:55:14 -04:00
|
|
|
field_definition = field.metadata[:type_class]
|
|
|
|
expect(field_definition).to respond_to(:required_permissions)
|
|
|
|
expect(field_definition.required_permissions).to contain_exactly(*expected)
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec::Matchers.define :have_graphql_fields do |*expected|
|
|
|
|
match do |kls|
|
2018-05-23 03:55:14 -04:00
|
|
|
field_names = expected.map { |name| GraphqlHelpers.fieldnamerize(name) }
|
|
|
|
expect(kls.fields.keys).to contain_exactly(*field_names)
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-14 09:06:53 -04:00
|
|
|
RSpec::Matchers.define :have_graphql_field do |field_name|
|
|
|
|
match do |kls|
|
|
|
|
expect(kls.fields.keys).to include(GraphqlHelpers.fieldnamerize(field_name))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-16 09:04:41 -04:00
|
|
|
RSpec::Matchers.define :have_graphql_arguments do |*expected|
|
2018-05-23 03:55:14 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
|
2017-08-16 09:04:41 -04:00
|
|
|
match do |field|
|
2018-05-23 03:55:14 -04:00
|
|
|
argument_names = expected.map { |name| GraphqlHelpers.fieldnamerize(name) }
|
|
|
|
expect(field.arguments.keys).to contain_exactly(*argument_names)
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec::Matchers.define :have_graphql_type do |expected|
|
|
|
|
match do |field|
|
2018-05-23 03:55:14 -04:00
|
|
|
expect(field.type).to eq(expected.to_graphql)
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec::Matchers.define :have_graphql_resolver do |expected|
|
|
|
|
match do |field|
|
2018-05-23 03:55:14 -04:00
|
|
|
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
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
end
|