|
| 1 | +import createMany from './createMany'; |
| 2 | + |
| 3 | +test('returns a new object with id 0 on empty datastore', () => { |
| 4 | + expect(createMany()(null, { data: [{}] })).toEqual([{ id: 0 }]); |
| 5 | +}); |
| 6 | + |
| 7 | +test('returns a new object with incremental id', () => { |
| 8 | + const data = [{ id: 1 }, { id: 3 }]; |
| 9 | + expect(createMany(data)(null, { data: [{}] })).toEqual([{ id: 4 }]); |
| 10 | +}); |
| 11 | + |
| 12 | +test('returns a new object using create data', () => { |
| 13 | + const data = [{ id: 0, value: 'foo' }]; |
| 14 | + expect(createMany(data)(null, { data: [{ value: 'toto' }] })).toEqual([ |
| 15 | + { |
| 16 | + id: 1, |
| 17 | + value: 'toto', |
| 18 | + }, |
| 19 | + ]); |
| 20 | +}); |
| 21 | + |
| 22 | +test('creates a new record', () => { |
| 23 | + const data = [{ id: 1 }, { id: 3 }]; |
| 24 | + createMany(data)(null, { data: [{ value: 'foo' }] }); |
| 25 | + expect(data).toEqual([{ id: 1 }, { id: 3 }, { id: 4, value: 'foo' }]); |
| 26 | +}); |
| 27 | + |
| 28 | +test('creates multiple new records', () => { |
| 29 | + const data = [{ id: 1 }, { id: 3 }]; |
| 30 | + createMany(data)(null, { |
| 31 | + data: [{ value: 'foo' }, { value: 'bar' }, { value: 'baz' }], |
| 32 | + }); |
| 33 | + expect(data).toEqual([ |
| 34 | + { id: 1 }, |
| 35 | + { id: 3 }, |
| 36 | + { id: 4, value: 'foo' }, |
| 37 | + { id: 5, value: 'bar' }, |
| 38 | + { id: 6, value: 'baz' }, |
| 39 | + ]); |
| 40 | +}); |
0 commit comments