Something went wrong. Try again.
Mirrored from GitHub github.com/roostorg/coop
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import { stripTypename, taggedUnionToOneOfInput } from './inputHelpers';
describe('GraphQL input helpers', () => { describe('taggedUnionToOneOfInput', () => { it('should perform the basic mapping as expected', () => { const res = taggedUnionToOneOfInput<'CONTENT_FIELD' | 'FULL_ITEM'>( { type: 'CONTENT_FIELD', name: 'hi', contentTypeId: 'abc', }, { CONTENT_FIELD: 'contentField', FULL_ITEM: 'contentFullObject', }, ); expect(res).toMatchInlineSnapshot(` { "contentField": { "contentTypeId": "abc", "name": "hi", }, } `); });
it('should use an input object w/ a dummy placeholder field when there are no other keys', () => { const res = taggedUnionToOneOfInput<'CONTENT_FIELD' | 'FULL_ITEM'>( { type: 'FULL_ITEM' }, { CONTENT_FIELD: 'contentField', FULL_ITEM: 'contentFullObject', }, );
expect(res).toMatchInlineSnapshot(` { "contentFullObject": {}, } `); }); });
describe('stripTypename', () => { it('should work', () => { expect( stripTypename([ { __typename: 'Hello', someKey: true, otherKey: { __typename: 'a', otherOtherKey: true }, }, ]), ).toMatchInlineSnapshot(` [ { "otherKey": { "otherOtherKey": true, }, "someKey": true, }, ] `); }); });});