Skip to content

Commit e0ef8c5

Browse files
author
dmelnik
committed
Add upsertMany tests for both sorted and unsorted state adapters
1 parent 85a662f commit e0ef8c5

File tree

3 files changed

+44
-53
lines changed

3 files changed

+44
-53
lines changed

packages/toolkit/src/entities/tests/sorted_state_adapter.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,28 @@ describe('Sorted State Adapter', () => {
509509
})
510510
})
511511

512+
it('should let you add a new entity then apply changes to it', () => {
513+
const firstChange = { author: TheHobbit.author }
514+
const secondChange = { title: 'Zack' }
515+
const withMany = adapter.setAll(state, [AClockworkOrange])
516+
517+
const withUpserts = adapter.upsertMany(withMany, [
518+
{...TheGreatGatsby}, { ...TheGreatGatsby, ...firstChange }, {...TheGreatGatsby, ...secondChange}
519+
])
520+
521+
expect(withUpserts).toEqual({
522+
ids: [AClockworkOrange.id, TheGreatGatsby.id],
523+
entities: {
524+
[TheGreatGatsby.id]: {
525+
...TheGreatGatsby,
526+
...firstChange,
527+
...secondChange,
528+
},
529+
[AClockworkOrange.id]: AClockworkOrange,
530+
},
531+
})
532+
})
533+
512534
it('should let you add a new entity in the state with setOne() and keep the sorting', () => {
513535
const withMany = adapter.setAll(state, [AnimalFarm, TheHobbit])
514536
const withOneMore = adapter.setOne(withMany, TheGreatGatsby)

packages/toolkit/src/entities/tests/unsorted_state_adapter.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,28 @@ describe('Unsorted State Adapter', () => {
355355
})
356356
})
357357

358+
it('should let you add a new entity then apply changes to it', () => {
359+
const firstChange = { author: TheHobbit.author }
360+
const secondChange = { title: 'Zack' }
361+
const withMany = adapter.setAll(state, [TheGreatGatsby])
362+
363+
const withUpserts = adapter.upsertMany(withMany, [
364+
{...AClockworkOrange}, { ...AClockworkOrange, ...firstChange }, {...AClockworkOrange, ...secondChange}
365+
])
366+
367+
expect(withUpserts).toEqual({
368+
ids: [TheGreatGatsby.id, AClockworkOrange.id],
369+
entities: {
370+
[TheGreatGatsby.id]: TheGreatGatsby,
371+
[AClockworkOrange.id]: {
372+
...AClockworkOrange,
373+
...firstChange,
374+
...secondChange,
375+
},
376+
},
377+
})
378+
})
379+
358380
it('should let you add a new entity in the state with setOne()', () => {
359381
const withOne = adapter.setOne(state, TheGreatGatsby)
360382
expect(withOne).toEqual({

packages/toolkit/src/tests/createEntityAdapter.test.ts

-53
This file was deleted.

0 commit comments

Comments
 (0)