summaryrefslogtreecommitdiff
path: root/spec/support_specs
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-05 15:08:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-05 15:08:47 +0000
commitdad16033c2b7cfd54ffe20ca5cc1d844e9e41be6 (patch)
tree8010601f9b7066e07166d997624b723ea4c3f816 /spec/support_specs
parent3c86701bc89302550abb9bbaa060132fdcd52480 (diff)
downloadgitlab-ce-dad16033c2b7cfd54ffe20ca5cc1d844e9e41be6.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support_specs')
-rw-r--r--spec/support_specs/helpers/graphql_helpers_spec.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/support_specs/helpers/graphql_helpers_spec.rb b/spec/support_specs/helpers/graphql_helpers_spec.rb
index fae29ec32f5..0f9918351e2 100644
--- a/spec/support_specs/helpers/graphql_helpers_spec.rb
+++ b/spec/support_specs/helpers/graphql_helpers_spec.rb
@@ -10,6 +10,81 @@ RSpec.describe GraphqlHelpers do
query.tr("\n", ' ').gsub(/\s+/, ' ').strip
end
+ describe 'a_graphql_entity_for' do
+ context 'when no arguments are passed' do
+ it 'raises an error' do
+ expect { a_graphql_entity_for }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'when the model is nil, with no properties' do
+ it 'raises an error' do
+ expect { a_graphql_entity_for(nil) }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'when the model is nil, any fields are passed' do
+ it 'raises an error' do
+ expect { a_graphql_entity_for(nil, :username) }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'with no model' do
+ it 'behaves like hash-inclusion with camel-casing' do
+ response = { 'foo' => 1, 'bar' => 2, 'camelCased' => 3 }
+
+ expect(response).to match a_graphql_entity_for(foo: 1, camel_cased: 3)
+ expect(response).not_to match a_graphql_entity_for(missing: 5)
+ end
+ end
+
+ context 'with just a model' do
+ it 'only considers the ID' do
+ user = build_stubbed(:user)
+ response = { 'username' => 'foo', 'id' => global_id_of(user) }
+
+ expect(response).to match a_graphql_entity_for(user)
+ end
+ end
+
+ context 'with a model and some method names' do
+ it 'also considers the method names' do
+ user = build_stubbed(:user)
+ response = { 'username' => user.username, 'id' => global_id_of(user) }
+
+ expect(response).to match a_graphql_entity_for(user, :username)
+ expect(response).not_to match a_graphql_entity_for(user, :name)
+ end
+ end
+
+ context 'with a model and some other properties' do
+ it 'behaves like the superset' do
+ user = build_stubbed(:user)
+ response = { 'username' => 'foo', 'id' => global_id_of(user) }
+
+ expect(response).to match a_graphql_entity_for(user, username: 'foo')
+ expect(response).not_to match a_graphql_entity_for(user, name: 'foo')
+ end
+ end
+
+ context 'with a model, method names, and some other properties' do
+ it 'behaves like the superset' do
+ user = build_stubbed(:user)
+ response = {
+ 'username' => user.username,
+ 'name' => user.name,
+ 'foo' => 'bar',
+ 'baz' => 'fop',
+ 'id' => global_id_of(user)
+ }
+
+ expect(response).to match a_graphql_entity_for(user, :username, :name, foo: 'bar')
+ expect(response).to match a_graphql_entity_for(user, :name, foo: 'bar')
+ expect(response).not_to match a_graphql_entity_for(user, :name, bar: 'foo')
+ end
+ end
+ end
+
describe 'graphql_dig_at' do
it 'transforms symbol keys to graphql field names' do
data = { 'camelCased' => 'names' }