|
| 1 | +import { isMemberPropValid, removeFormKeys } from '../../src/utils' |
| 2 | + |
| 3 | +describe('#utils', () => { |
| 4 | + describe('#isMemberPropValid', () => { |
| 5 | + test.each(['1', 'foobar', [], ['foo', 'bar'], [1, 2, 3]])( |
| 6 | + '%p should return truthy', |
| 7 | + (value) => { |
| 8 | + expect(isMemberPropValid(value as string)).toBeTruthy() |
| 9 | + } |
| 10 | + ) |
| 11 | + |
| 12 | + test.each(['', 1, null, undefined, true, false, {}, { foo: 1 }])( |
| 13 | + '%p should return falsy', |
| 14 | + (value) => { |
| 15 | + expect(isMemberPropValid(value as string)).toBeFalsy() |
| 16 | + } |
| 17 | + ) |
| 18 | + }) |
| 19 | + |
| 20 | + describe('#removeFormKeys', () => { |
| 21 | + it('should remove unwanted keys from the form object', () => { |
| 22 | + expect( |
| 23 | + removeFormKeys({ |
| 24 | + id: 'foo', |
| 25 | + title: 'foobar', |
| 26 | + items: [ |
| 27 | + { id: 1, title: 'one' }, |
| 28 | + { |
| 29 | + id: 2, |
| 30 | + title: 'two', |
| 31 | + application: { id: 'a', installation_id: 'b', value: 'c' }, |
| 32 | + }, |
| 33 | + { |
| 34 | + id: 3, |
| 35 | + title: 'three', |
| 36 | + values: ['foo', 'bar'], |
| 37 | + settings: { id: 33, value: false }, |
| 38 | + integrations: [5, 6, 7], |
| 39 | + }, |
| 40 | + ], |
| 41 | + integrations: { foo: 'bar' }, |
| 42 | + application: { id: 11, installation_id: 22 }, |
| 43 | + settings: { id: 'bar', enabled: true }, |
| 44 | + links: [ |
| 45 | + 'http://example.com', |
| 46 | + 'http://localhost', |
| 47 | + { id: 'foo', url: 'http://foo' }, |
| 48 | + ], |
| 49 | + }) |
| 50 | + ).toEqual({ |
| 51 | + title: 'foobar', |
| 52 | + items: [ |
| 53 | + { title: 'one' }, |
| 54 | + { title: 'two', application: { id: 'a', value: 'c' } }, |
| 55 | + { |
| 56 | + title: 'three', |
| 57 | + values: ['foo', 'bar'], |
| 58 | + settings: { value: false }, |
| 59 | + }, |
| 60 | + ], |
| 61 | + application: { id: 11 }, |
| 62 | + settings: { enabled: true }, |
| 63 | + links: [ |
| 64 | + 'http://example.com', |
| 65 | + 'http://localhost', |
| 66 | + { url: 'http://foo' }, |
| 67 | + ], |
| 68 | + }) |
| 69 | + }) |
| 70 | + }) |
| 71 | +}) |
0 commit comments