Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-06-25 11:59:00 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2018-06-28 14:50:17 +0300
commit54b56f20b7a70d3e6284c8105eb3d4a568e255b0 (patch)
treede18fca7bd27dcd55817e21c4654cf36c1430c5f /spec/support/matchers
parent627236c9edd7f085ec5070ef7fcfbcbfc9b6de78 (diff)
Expose permissions on types in GraphQL
This adds a reusable way to expose permissions for a user to types in GraphQL.
Diffstat (limited to 'spec/support/matchers')
-rw-r--r--spec/support/matchers/graphql_matchers.rb29
1 files changed, 27 insertions, 2 deletions
diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb
index d23cbaf4beb..be6fa4c71a0 100644
--- a/spec/support/matchers/graphql_matchers.rb
+++ b/spec/support/matchers/graphql_matchers.rb
@@ -7,9 +7,24 @@ RSpec::Matchers.define :require_graphql_authorizations do |*expected|
end
RSpec::Matchers.define :have_graphql_fields do |*expected|
+ def expected_field_names
+ expected.map { |name| GraphqlHelpers.fieldnamerize(name) }
+ end
+
match do |kls|
- field_names = expected.map { |name| GraphqlHelpers.fieldnamerize(name) }
- expect(kls.fields.keys).to contain_exactly(*field_names)
+ expect(kls.fields.keys).to contain_exactly(*expected_field_names)
+ end
+
+ failure_message do |kls|
+ missing = expected_field_names - kls.fields.keys
+ extra = kls.fields.keys - expected_field_names
+
+ message = []
+
+ message << "is missing fields: <#{missing.inspect}>" if missing.any?
+ message << "contained unexpected fields: <#{extra.inspect}>" if extra.any?
+
+ message.join("\n")
end
end
@@ -44,3 +59,13 @@ RSpec::Matchers.define :have_graphql_resolver do |expected|
end
end
end
+
+RSpec::Matchers.define :expose_permissions_using do |expected|
+ match do |type|
+ permission_field = type.fields['userPermissions']
+
+ expect(permission_field).not_to be_nil
+ expect(permission_field.type).to be_non_null
+ expect(permission_field.type.of_type.graphql_name).to eq(expected.graphql_name)
+ end
+end