|
| 1 | +import update from './update'; |
| 2 | + |
| 3 | +test('returns undefined by default', () => { |
| 4 | + expect(update()(null, {})).toBeUndefined(); |
| 5 | +}); |
| 6 | + |
| 7 | +test('returns updated record when found', () => { |
| 8 | + const data = [{ id: 1, value: 'foo', bar: 'baz' }]; |
| 9 | + expect(update(data)(null, { id: 1, value: 'bar' })).toEqual({ |
| 10 | + id: 1, |
| 11 | + value: 'bar', |
| 12 | + bar: 'baz', |
| 13 | + }); |
| 14 | +}); |
| 15 | + |
| 16 | +test('returns undefined when not found', () => { |
| 17 | + const data = [{ id: 1, value: 'foo' }, { id: 2, value: 'bar' }]; |
| 18 | + expect(update(data)(null, { id: 3 })).toBeUndefined(); |
| 19 | +}); |
| 20 | + |
| 21 | +test('updates record when found', () => { |
| 22 | + const data = [{ id: 1, value: 'foo' }]; |
| 23 | + update(data)(null, { id: 1, value: 'bar', bar: 'baz' }); |
| 24 | + expect(data).toEqual([{ id: 1, value: 'bar', bar: 'baz' }]); |
| 25 | +}); |
| 26 | + |
| 27 | +test('removes property when setting the value to undefined', () => { |
| 28 | + const data = [{ id: 1, value: 'foo' }]; |
| 29 | + update(data)(null, { id: 1, value: undefined }); |
| 30 | + expect(data).toEqual([{ id: 1 }]); |
| 31 | +}); |
0 commit comments