|
| 1 | +/* @flow */ |
| 2 | + |
| 3 | +import { composeWithRelay } from '../composeWithRelay'; |
| 4 | +import { userTC } from '../__mocks__/userTC'; |
| 5 | +import { toGlobalId } from '../globalId'; |
| 6 | + |
| 7 | +describe('wrapMutationResolver', () => { |
| 8 | + composeWithRelay(userTC); |
| 9 | + const resolverCreateOne = userTC.getResolver('createOne'); |
| 10 | + const resolverWithInput = userTC.getResolver('manyArgsWithInput'); |
| 11 | + const resolverWithoutInput = userTC.getResolver('manyArgsWithoutInput'); |
| 12 | + |
| 13 | + describe('args', () => { |
| 14 | + it('should add `clientMutationId` field to args.input', () => { |
| 15 | + const itc = resolverCreateOne.getArgITC('input'); |
| 16 | + expect(itc.hasField('clientMutationId')).toBe(true); |
| 17 | + expect(itc.getFieldTypeName('clientMutationId')).toBe('String'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should create required args.input! if not exists', () => { |
| 21 | + expect(resolverWithoutInput.hasArg('input')).toBeTruthy(); |
| 22 | + expect(resolverWithoutInput.isArgNonNull('input')).toBeTruthy(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should create args.input if not exists and move all args into it', () => { |
| 26 | + expect(resolverWithoutInput.hasArg('input')).toBeTruthy(); |
| 27 | + const itc = resolverWithoutInput.getArgITC('input'); |
| 28 | + expect(itc.hasField('sort')).toBe(true); |
| 29 | + expect(itc.hasField('limit')).toBe(true); |
| 30 | + expect(itc.hasField('clientMutationId')).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should leave other arg untouched if args.input exists', () => { |
| 34 | + expect(resolverWithInput.getArgNames()).toEqual( |
| 35 | + expect.arrayContaining(['input', 'sort', 'limit']) |
| 36 | + ); |
| 37 | + |
| 38 | + const itc = resolverWithInput.getArgITC('input'); |
| 39 | + expect(itc.hasField('sort')).toBe(false); |
| 40 | + expect(itc.hasField('limit')).toBe(false); |
| 41 | + expect(itc.hasField('clientMutationId')).toBe(true); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('outputType', () => { |
| 46 | + it('should add `clientMutationId` field to payload', () => { |
| 47 | + const tc = resolverCreateOne.getOTC(); |
| 48 | + expect(tc.hasField('clientMutationId')).toBe(true); |
| 49 | + expect(tc.getFieldTypeName('clientMutationId')).toBe('String'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should add `nodeId` field to payload', () => { |
| 53 | + const tc = resolverCreateOne.getOTC(); |
| 54 | + expect(tc.hasField('nodeId')).toBe(true); |
| 55 | + expect(tc.getFieldTypeName('nodeId')).toBe('ID'); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('resolve', () => { |
| 60 | + it('should passthru `clientMutationId`', async () => { |
| 61 | + const result = await resolverCreateOne.resolve({ |
| 62 | + args: { input: { clientMutationId: '333' } }, |
| 63 | + }); |
| 64 | + expect(result.clientMutationId).toBe('333'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should return `nodeId` with globalId', async () => { |
| 68 | + const result = await resolverCreateOne.resolve({ args: { input: { id: 'newRecord' } } }); |
| 69 | + expect(result.nodeId).toBe(toGlobalId('User', 'newRecord')); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments