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.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/frontend/graphql_shared/utils_spec.js b/spec/frontend/graphql_shared/utils_spec.js
index d392b0f0575..56bfb02ea4a 100644
--- a/spec/frontend/graphql_shared/utils_spec.js
+++ b/spec/frontend/graphql_shared/utils_spec.js
@@ -2,6 +2,8 @@ import {
getIdFromGraphQLId,
convertToGraphQLId,
convertToGraphQLIds,
+ convertFromGraphQLIds,
+ convertNodeIdsFromGraphQLIds,
} from '~/graphql_shared/utils';
const mockType = 'Group';
@@ -81,3 +83,35 @@ describe('convertToGraphQLIds', () => {
expect(() => convertToGraphQLIds(type, ids)).toThrow(new TypeError(message));
});
});
+
+describe('convertFromGraphQLIds', () => {
+ it.each`
+ ids | expected
+ ${[mockGid]} | ${[mockId]}
+ ${[mockGid, 'invalid id']} | ${[mockId, null]}
+ `('converts $ids from GraphQL Ids', ({ ids, expected }) => {
+ expect(convertFromGraphQLIds(ids)).toEqual(expected);
+ });
+
+ it("throws TypeError if `ids` parameter isn't an array", () => {
+ expect(() => convertFromGraphQLIds('invalid')).toThrow(
+ new TypeError('ids must be an array; got string'),
+ );
+ });
+});
+
+describe('convertNodeIdsFromGraphQLIds', () => {
+ it.each`
+ nodes | expected
+ ${[{ id: mockGid, name: 'foo bar' }, { id: mockGid, name: 'baz' }]} | ${[{ id: mockId, name: 'foo bar' }, { id: mockId, name: 'baz' }]}
+ ${[{ name: 'foo bar' }]} | ${[{ name: 'foo bar' }]}
+ `('converts `id` properties in $nodes from GraphQL Id', ({ nodes, expected }) => {
+ expect(convertNodeIdsFromGraphQLIds(nodes)).toEqual(expected);
+ });
+
+ it("throws TypeError if `nodes` parameter isn't an array", () => {
+ expect(() => convertNodeIdsFromGraphQLIds('invalid')).toThrow(
+ new TypeError('nodes must be an array; got string'),
+ );
+ });
+});