Skip to content

Commit

Permalink
Added test case for entity merging
Browse files Browse the repository at this point in the history
  • Loading branch information
skoging committed Mar 11, 2019
1 parent 7653102 commit f2d735c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/state/__tests__/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe('reducer', () => {
expiresAt: 5000500000,
},
};
const partialResultAction: ReceiveAction = {
...action,
payload: { id, title: 'hello', content: undefined },
};
const iniState = {
entities: {},
results: {},
Expand All @@ -33,6 +37,21 @@ describe('reducer', () => {
expect(nextEntity).not.toBe(prevEntity);
expect(nextEntity).toBeDefined();
})
it('should merge partial entity with existing entity', () => {
const getEntity = (state: any): ArticleResource => state.entities[ArticleResource.getKey()][`${ArticleResource.pk(action.payload)}`]
const prevEntity = getEntity(newState);
expect(prevEntity).toBeDefined();
const nextState = reducer(newState, partialResultAction);
const nextEntity = getEntity(nextState);
expect(nextEntity).not.toBe(prevEntity);
expect(nextEntity).toBeDefined();

expect(nextEntity.title).not.toBe(prevEntity.title);
expect(nextEntity.title).toBe(partialResultAction.payload.title);

expect(nextEntity.content).toBe(prevEntity.content);
expect(nextEntity.content).not.toBe(partialResultAction.payload.content);
})
});
it('mutate should never change results', () => {
const id = 20;
Expand Down

0 comments on commit f2d735c

Please sign in to comment.