Skip to content

Instantly share code, notes, and snippets.

@javierfernandes
Created November 15, 2020 13:45
Show Gist options
  • Save javierfernandes/063be06a432810501ab7dcf31fe13fe6 to your computer and use it in GitHub Desktop.
Save javierfernandes/063be06a432810501ab7dcf31fe13fe6 to your computer and use it in GitHub Desktop.
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