-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from vantreeseba/add_create_many
Add create many
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import create from './create'; | ||
|
||
export default (entityData = []) => (_, entities) => { | ||
return entities.data.map((e) => create(entityData)(null, e)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import createMany from './createMany'; | ||
|
||
test('returns a new object with id 0 on empty datastore', () => { | ||
expect(createMany()(null, { data: [{}] })).toEqual([{ id: 0 }]); | ||
}); | ||
|
||
test('returns a new object with incremental id', () => { | ||
const data = [{ id: 1 }, { id: 3 }]; | ||
expect(createMany(data)(null, { data: [{}] })).toEqual([{ id: 4 }]); | ||
}); | ||
|
||
test('returns a new object using create data', () => { | ||
const data = [{ id: 0, value: 'foo' }]; | ||
expect(createMany(data)(null, { data: [{ value: 'toto' }] })).toEqual([ | ||
{ | ||
id: 1, | ||
value: 'toto', | ||
}, | ||
]); | ||
}); | ||
|
||
test('creates a new record', () => { | ||
const data = [{ id: 1 }, { id: 3 }]; | ||
createMany(data)(null, { data: [{ value: 'foo' }] }); | ||
expect(data).toEqual([{ id: 1 }, { id: 3 }, { id: 4, value: 'foo' }]); | ||
}); | ||
|
||
test('creates multiple new records', () => { | ||
const data = [{ id: 1 }, { id: 3 }]; | ||
createMany(data)(null, { | ||
data: [{ value: 'foo' }, { value: 'bar' }, { value: 'baz' }], | ||
}); | ||
expect(data).toEqual([ | ||
{ id: 1 }, | ||
{ id: 3 }, | ||
{ id: 4, value: 'foo' }, | ||
{ id: 5, value: 'bar' }, | ||
{ id: 6, value: 'baz' }, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters