mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import * as Automerge from 'automerge'
|
|
|
|
interface TestDoc {
|
|
_id: string
|
|
status: string
|
|
}
|
|
|
|
describe('old state error replication', () => {
|
|
const clientDocSet = new Automerge.DocSet()
|
|
const serverDocSet = new Automerge.DocSet()
|
|
|
|
const docId = 'test'
|
|
let clientDoc = Automerge.from<TestDoc>({
|
|
_id: docId,
|
|
status: 'Unstarted'
|
|
})
|
|
let serverDoc = Automerge.from<TestDoc>({
|
|
_id: docId,
|
|
status: 'Unstarted'
|
|
})
|
|
|
|
it('replicate old state error', () => {
|
|
clientDocSet.setDoc(docId, clientDoc)
|
|
serverDocSet.setDoc(docId, serverDoc)
|
|
|
|
let clientMessages: string[] = []
|
|
const clientConnection = new Automerge.Connection(clientDocSet, msg => {
|
|
clientMessages.push(JSON.stringify(msg))
|
|
})
|
|
clientConnection.open()
|
|
let serverMessages: string[] = []
|
|
const serverConnection = new Automerge.Connection(serverDocSet, msg => {
|
|
serverMessages.push(JSON.stringify(msg))
|
|
})
|
|
serverConnection.open()
|
|
|
|
let oldClientDoc = clientDoc
|
|
clientDoc = Automerge.change(clientDoc, newClientDoc => {
|
|
newClientDoc.status = 'In progress'
|
|
})
|
|
clientDocSet.setDoc(docId, clientDoc)
|
|
|
|
expect(clientMessages.length).toEqual(2)
|
|
expect(serverMessages.length).toEqual(1)
|
|
|
|
expect(() => {
|
|
clientDocSet.setDoc(docId, oldClientDoc)
|
|
}).toThrow()
|
|
})
|
|
})
|