Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import { stripTypename, taggedUnionToOneOfInput } from './inputHelpers';
2
3describe('GraphQL input helpers', () => {
4 describe('taggedUnionToOneOfInput', () => {
5 it('should perform the basic mapping as expected', () => {
6 const res = taggedUnionToOneOfInput<'CONTENT_FIELD' | 'FULL_ITEM'>(
7 {
8 type: 'CONTENT_FIELD',
9 name: 'hi',
10 contentTypeId: 'abc',
11 },
12 {
13 CONTENT_FIELD: 'contentField',
14 FULL_ITEM: 'contentFullObject',
15 },
16 );
17 expect(res).toMatchInlineSnapshot(`
18 Object {
19 "contentField": Object {
20 "contentTypeId": "abc",
21 "name": "hi",
22 },
23 }
24 `);
25 });
26
27 it('should use an input object w/ a dummy placeholder field when there are no other keys', () => {
28 const res = taggedUnionToOneOfInput<'CONTENT_FIELD' | 'FULL_ITEM'>(
29 { type: 'FULL_ITEM' },
30 {
31 CONTENT_FIELD: 'contentField',
32 FULL_ITEM: 'contentFullObject',
33 },
34 );
35
36 expect(res).toMatchInlineSnapshot(`
37 Object {
38 "contentFullObject": Object {},
39 }
40 `);
41 });
42 });
43
44 describe('stripTypename', () => {
45 it('should work', () => {
46 expect(
47 stripTypename([
48 {
49 __typename: 'Hello',
50 someKey: true,
51 otherKey: { __typename: 'a', otherOtherKey: true },
52 },
53 ]),
54 ).toMatchInlineSnapshot(`
55 Array [
56 Object {
57 "otherKey": Object {
58 "otherOtherKey": true,
59 },
60 "someKey": true,
61 },
62 ]
63 `);
64 });
65 });
66});