|
| 1 | +import traverseAndAction from './traverseAndAction'; |
| 2 | +import envVarReplace from './envVarReplace'; |
| 3 | + |
| 4 | +describe('traverseAndAction', () => { |
| 5 | + it('returns correctly updated object', () => { |
| 6 | + const action = (value: string) => value.replace('a', 'e'); |
| 7 | + const newObject = traverseAndAction( |
| 8 | + { |
| 9 | + test: { |
| 10 | + example: 'aaaa', |
| 11 | + }, |
| 12 | + test2: 'bba', |
| 13 | + }, |
| 14 | + action |
| 15 | + ); |
| 16 | + expect(newObject).toEqual({ |
| 17 | + test: { |
| 18 | + example: 'eaaa', |
| 19 | + }, |
| 20 | + test2: 'bbe', |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('returns correcly when using env var replace', () => { |
| 25 | + process.env.EXAMPLE = 'test1'; |
| 26 | + const newObject = traverseAndAction( |
| 27 | + { |
| 28 | + test: { |
| 29 | + example: '${EXAMPLE}', |
| 30 | + }, |
| 31 | + test2: 'test:${EXAMPLE}', |
| 32 | + }, |
| 33 | + envVarReplace |
| 34 | + ); |
| 35 | + expect(newObject).toEqual({ |
| 36 | + test: { |
| 37 | + example: 'test1', |
| 38 | + }, |
| 39 | + test2: 'test:test1', |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('returns correcly when using arrays and numbers', () => { |
| 44 | + process.env.EXAMPLE = 'test1'; |
| 45 | + const newObject = traverseAndAction( |
| 46 | + { |
| 47 | + number: 1, |
| 48 | + array: ['test', '${EXAMPLE}'], |
| 49 | + arrayWithObjects: [{ test1: 'example', test2: '${EXAMPLE}' }], |
| 50 | + arrayWithArray: [[{ test: 'test' }, '${EXAMPLE}'], 'test'], |
| 51 | + }, |
| 52 | + envVarReplace |
| 53 | + ); |
| 54 | + expect(newObject).toEqual({ |
| 55 | + number: 1, |
| 56 | + array: ['test', 'test1'], |
| 57 | + arrayWithObjects: [{ test1: 'example', test2: 'test1' }], |
| 58 | + arrayWithArray: [[{ test: 'test' }, 'test1'], 'test'], |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments