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:
Diffstat (limited to 'spec/frontend/graphql_shared/utils_spec.js')
-rw-r--r--spec/frontend/graphql_shared/utils_spec.js39
1 files changed, 38 insertions, 1 deletions
diff --git a/spec/frontend/graphql_shared/utils_spec.js b/spec/frontend/graphql_shared/utils_spec.js
index 6a630195126..d392b0f0575 100644
--- a/spec/frontend/graphql_shared/utils_spec.js
+++ b/spec/frontend/graphql_shared/utils_spec.js
@@ -1,4 +1,12 @@
-import { getIdFromGraphQLId } from '~/graphql_shared/utils';
+import {
+ getIdFromGraphQLId,
+ convertToGraphQLId,
+ convertToGraphQLIds,
+} from '~/graphql_shared/utils';
+
+const mockType = 'Group';
+const mockId = 12;
+const mockGid = `gid://gitlab/Group/12`;
describe('getIdFromGraphQLId', () => {
[
@@ -44,3 +52,32 @@ describe('getIdFromGraphQLId', () => {
});
});
});
+
+describe('convertToGraphQLId', () => {
+ it('combines $type and $id into $result', () => {
+ expect(convertToGraphQLId(mockType, mockId)).toBe(mockGid);
+ });
+
+ it.each`
+ type | id | message
+ ${mockType} | ${null} | ${'id must be a number or string; got object'}
+ ${null} | ${mockId} | ${'type must be a string; got object'}
+ `('throws TypeError with "$message" if a param is missing', ({ type, id, message }) => {
+ expect(() => convertToGraphQLId(type, id)).toThrow(new TypeError(message));
+ });
+});
+
+describe('convertToGraphQLIds', () => {
+ it('combines $type and $id into $result', () => {
+ expect(convertToGraphQLIds(mockType, [mockId])).toStrictEqual([mockGid]);
+ });
+
+ it.each`
+ type | ids | message
+ ${mockType} | ${null} | ${"Cannot read property 'map' of null"}
+ ${mockType} | ${[mockId, null]} | ${'id must be a number or string; got object'}
+ ${null} | ${[mockId]} | ${'type must be a string; got object'}
+ `('throws TypeError with "$message" if a param is missing', ({ type, ids, message }) => {
+ expect(() => convertToGraphQLIds(type, ids)).toThrow(new TypeError(message));
+ });
+});