Created
November 15, 2020 13:45
-
-
Save javierfernandes/063be06a432810501ab7dcf31fe13fe6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const doTest = ({ objects, changes, expectedObjects }) => { | |
const state = { | |
project: { masterBranch: { objects } } | |
} | |
const changeSet = { description: 'A test changeset', project: 'my-project', changes } | |
expect(project(state, receiveObjectChangeSet(changeSet))).toEqual({ | |
project: { | |
masterBranch: { | |
objects: expectedObjects | |
} | |
}, | |
// ALSO SETS THIS ! | |
lastChangeSet: changeSet, | |
history: [changeSet] | |
}) | |
} | |
describe('ADDED', () => { | |
it('should add a new object for a single ADDED change', () => { | |
doTest({ | |
objects: { | |
A: { id: 'A', name: 'A' }, | |
B: { id: 'B', name: 'B' }, | |
}, | |
changes: [ | |
{ added: { id: 'NEW', sys: 'marker', data: { children: [] }, project: 'my-project' } } | |
], | |
expectedObjects: { | |
A: { id: 'A', name: 'A' }, | |
B: { id: 'B', name: 'B' }, | |
NEW: { id: 'NEW', sys: 'marker', data: { children: [] }, project: 'my-project' } | |
} | |
}) | |
}) | |
}) | |
describe('DELETED', () => { | |
it('should remove an object for a single DELETED change', () => doTest({ | |
objects: { | |
A: { id: 'A', name: 'A' }, | |
B: { id: 'B', name: 'B' }, | |
C: { id: 'C', name: 'C' } | |
}, | |
changes: [ | |
{ deleted: { id: 'B' } } | |
], | |
expectedObjects: { | |
A: { id: 'A', name: 'A' }, | |
C: { id: 'C', name: 'C' } | |
} | |
})) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment