summaryrefslogtreecommitdiff
path: root/spec/graphql/gitlab_schema_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 16:52:41 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 16:52:41 +0000
commita986819a7bce2002018dfafed3900dc3f2e8fb81 (patch)
tree15c063738d999a0aff035c4842885276a9ab6ac4 /spec/graphql/gitlab_schema_spec.rb
parent92d5172ad42ebc62eb78cac21b1e236ad6ace580 (diff)
downloadgitlab-ce-a986819a7bce2002018dfafed3900dc3f2e8fb81.tar.gz
Add latest changes from gitlab-org/security/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/graphql/gitlab_schema_spec.rb')
-rw-r--r--spec/graphql/gitlab_schema_spec.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb
index 5d6aa863994..e52f60a2c02 100644
--- a/spec/graphql/gitlab_schema_spec.rb
+++ b/spec/graphql/gitlab_schema_spec.rb
@@ -212,6 +212,55 @@ RSpec.describe GitlabSchema do
end
end
+ describe '.parse_gid' do
+ let_it_be(:global_id) { 'gid://gitlab/TestOne/2147483647' }
+
+ before do
+ test_base = Class.new
+ test_one = Class.new(test_base)
+ test_two = Class.new(test_base)
+
+ stub_const('TestBase', test_base)
+ stub_const('TestOne', test_one)
+ stub_const('TestTwo', test_two)
+ end
+
+ it 'parses the gid' do
+ gid = described_class.parse_gid(global_id)
+
+ expect(gid.model_id).to eq '2147483647'
+ expect(gid.model_class).to eq TestOne
+ end
+
+ context 'when gid is malformed' do
+ let_it_be(:global_id) { 'malformed://gitlab/TestOne/2147483647' }
+
+ it 'raises an error' do
+ expect { described_class.parse_gid(global_id) }
+ .to raise_error(Gitlab::Graphql::Errors::ArgumentError, "#{global_id} is not a valid GitLab id.")
+ end
+ end
+
+ context 'when using expected_type' do
+ it 'accepts a single type' do
+ gid = described_class.parse_gid(global_id, expected_type: TestOne)
+
+ expect(gid.model_class).to eq TestOne
+ end
+
+ it 'accepts an ancestor type' do
+ gid = described_class.parse_gid(global_id, expected_type: TestBase)
+
+ expect(gid.model_class).to eq TestOne
+ end
+
+ it 'rejects an unknown type' do
+ expect { described_class.parse_gid(global_id, expected_type: TestTwo) }
+ .to raise_error(Gitlab::Graphql::Errors::ArgumentError, "#{global_id} is not a valid id for TestTwo.")
+ end
+ end
+ end
+
def field_instrumenters
described_class.instrumenters[:field] + described_class.instrumenters[:field_after_built_ins]
end