Skip to content

Instantly share code, notes, and snippets.

@javierfernandes
Last active November 15, 2020 13:17
Show Gist options
  • Save javierfernandes/5430e4677dd9df49c6ebbfef9c287dfc to your computer and use it in GitHub Desktop.
Save javierfernandes/5430e4677dd9df49c6ebbfef9c287dfc to your computer and use it in GitHub Desktop.
RTT-doTest-before
describe('receiveObjectChangeSet()', () => {
describe('ADDED', () => {
it('should add a new object for a single ADDED change', () => {
const state = {
project: {
masterBranch: {
objects: {
A: { id: 'A', name: 'A' },
B: { id: 'B', name: 'B' },
}
}
}
}
const changeSet = {
description: 'Adding simple object',
project: 'my-project',
changes: [
{ added: { id: 'NEW', sys: 'marker', data: { children: [] }, project: 'my-project' } }
]
}
expect(project(state, receiveObjectChangeSet(changeSet))).toEqual({
project: {
masterBranch: {
objects: {
...state.project.masterBranch.objects,
NEW: changeSet.changes[0].added
}
}
},
// ALSO SETS THIS !
lastChangeSet: changeSet,
history: [changeSet]
})
})
})
describe('DELETED', () => {
it('should remove an object for a single DELETED change', () => {
const state = {
project: {
masterBranch: {
objects: {
A: { id: 'A', name: 'A' },
B: { id: 'B', name: 'B' },
C: { id: 'C', name: 'C' }
}
}
}
}
const changeSet = {
description: 'Adding simple object',
project: 'my-project',
changes: [
{ deleted: { id: 'B' } }
]
}
expect(project(state, receiveObjectChangeSet(changeSet))).toEqual({
project: {
masterBranch: {
objects: {
A: state.project.masterBranch.objects.A,
C: state.project.masterBranch.objects.C,
}
}
},
lastChangeSet: changeSet,
history: [changeSet],
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment