|
|
@@ -1,6 +1,6 @@
|
|
|
const sinon = require('sinon')
|
|
|
const { expect } = require('chai')
|
|
|
-const async = require('async')
|
|
|
+const { setTimeout } = require('node:timers/promises')
|
|
|
|
|
|
const { db, ObjectId } = require('../../../app/js/mongodb')
|
|
|
const MockWebApi = require('./helpers/MockWebApi')
|
|
|
@@ -11,12 +11,12 @@ const RangesManager = require('../../../app/js/RangesManager')
|
|
|
const sandbox = sinon.createSandbox()
|
|
|
|
|
|
describe('Ranges', function () {
|
|
|
- before(function (done) {
|
|
|
- DocUpdaterApp.ensureRunning(done)
|
|
|
+ before(async function () {
|
|
|
+ await DocUpdaterApp.ensureRunning()
|
|
|
})
|
|
|
|
|
|
describe('tracking changes from ops', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
this.id_seed = '587357bd35e64f6157'
|
|
|
@@ -48,59 +48,27 @@ describe('Ranges', function () {
|
|
|
lines: this.doc.lines,
|
|
|
version: 0,
|
|
|
})
|
|
|
- const jobs = []
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
for (const update of this.updates) {
|
|
|
- jobs.push(callback =>
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- update,
|
|
|
- callback
|
|
|
- )
|
|
|
- )
|
|
|
+ await DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update)
|
|
|
}
|
|
|
-
|
|
|
- DocUpdaterApp.ensureRunning(error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- async.series(jobs, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- done()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
- it('should update the ranges', function (done) {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { ranges } = data
|
|
|
- const change = ranges.changes[0]
|
|
|
- change.op.should.deep.equal({ i: '456', p: 3 })
|
|
|
- change.id.should.equal(this.id_seed + '000001')
|
|
|
- change.metadata.user_id.should.equal(this.user_id)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should update the ranges', async function () {
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ const { ranges } = doc
|
|
|
+ const change = ranges.changes[0]
|
|
|
+ change.op.should.deep.equal({ i: '456', p: 3 })
|
|
|
+ change.id.should.equal(this.id_seed + '000001')
|
|
|
+ change.metadata.user_id.should.equal(this.user_id)
|
|
|
})
|
|
|
|
|
|
describe('Adding comments', function () {
|
|
|
describe('standalone', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
+ this.tid = DocUpdaterClient.randomId()
|
|
|
this.doc = {
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
lines: ['foo bar baz'],
|
|
|
@@ -108,9 +76,7 @@ describe('Ranges', function () {
|
|
|
this.updates = [
|
|
|
{
|
|
|
doc: this.doc.id,
|
|
|
- op: [
|
|
|
- { c: 'bar', p: 4, t: (this.tid = DocUpdaterClient.randomId()) },
|
|
|
- ],
|
|
|
+ op: [{ c: 'bar', p: 4, t: this.tid }],
|
|
|
v: 0,
|
|
|
},
|
|
|
]
|
|
|
@@ -118,52 +84,34 @@ describe('Ranges', function () {
|
|
|
lines: this.doc.lines,
|
|
|
version: 0,
|
|
|
})
|
|
|
- const jobs = []
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
for (const update of this.updates) {
|
|
|
- jobs.push(callback =>
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- update,
|
|
|
- callback
|
|
|
- )
|
|
|
+ await DocUpdaterClient.sendUpdate(
|
|
|
+ this.project_id,
|
|
|
+ this.doc.id,
|
|
|
+ update
|
|
|
)
|
|
|
}
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- async.series(jobs, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(done, 200)
|
|
|
- })
|
|
|
- })
|
|
|
+ await setTimeout(200)
|
|
|
})
|
|
|
|
|
|
- it('should update the ranges', function (done) {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
+ it('should update the ranges', async function () {
|
|
|
+ const doc = await DocUpdaterClient.getDoc(
|
|
|
this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { ranges } = data
|
|
|
- const comment = ranges.comments[0]
|
|
|
- comment.op.should.deep.equal({ c: 'bar', p: 4, t: this.tid })
|
|
|
- comment.id.should.equal(this.tid)
|
|
|
- done()
|
|
|
- }
|
|
|
+ this.doc.id
|
|
|
)
|
|
|
+ const { ranges } = doc
|
|
|
+ const comment = ranges.comments[0]
|
|
|
+ comment.op.should.deep.equal({ c: 'bar', p: 4, t: this.tid })
|
|
|
+ comment.id.should.equal(this.tid)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('with conflicting ops needing OT', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
+ this.tid = DocUpdaterClient.randomId()
|
|
|
this.doc = {
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
lines: ['foo bar baz'],
|
|
|
@@ -177,9 +125,7 @@ describe('Ranges', function () {
|
|
|
},
|
|
|
{
|
|
|
doc: this.doc.id,
|
|
|
- op: [
|
|
|
- { c: 'bar', p: 4, t: (this.tid = DocUpdaterClient.randomId()) },
|
|
|
- ],
|
|
|
+ op: [{ c: 'bar', p: 4, t: this.tid }],
|
|
|
v: 0,
|
|
|
},
|
|
|
]
|
|
|
@@ -187,51 +133,32 @@ describe('Ranges', function () {
|
|
|
lines: this.doc.lines,
|
|
|
version: 0,
|
|
|
})
|
|
|
- const jobs = []
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
for (const update of this.updates) {
|
|
|
- jobs.push(callback =>
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- update,
|
|
|
- callback
|
|
|
- )
|
|
|
+ await DocUpdaterClient.sendUpdate(
|
|
|
+ this.project_id,
|
|
|
+ this.doc.id,
|
|
|
+ update
|
|
|
)
|
|
|
}
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- async.series(jobs, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(done, 200)
|
|
|
- })
|
|
|
- })
|
|
|
+ await setTimeout(200)
|
|
|
})
|
|
|
|
|
|
- it('should update the comments with the OT shifted comment', function (done) {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
+ it('should update the comments with the OT shifted comment', async function () {
|
|
|
+ const doc = await DocUpdaterClient.getDoc(
|
|
|
this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { ranges } = data
|
|
|
- const comment = ranges.comments[0]
|
|
|
- comment.op.should.deep.equal({ c: 'bar', p: 7, t: this.tid })
|
|
|
- done()
|
|
|
- }
|
|
|
+ this.doc.id
|
|
|
)
|
|
|
+ const { ranges } = doc
|
|
|
+ const comment = ranges.comments[0]
|
|
|
+ comment.op.should.deep.equal({ c: 'bar', p: 7, t: this.tid })
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('Loading ranges from persistence layer', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
this.id_seed = '587357bd35e64f6157'
|
|
|
@@ -260,58 +187,41 @@ describe('Ranges', function () {
|
|
|
],
|
|
|
},
|
|
|
})
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- this.update,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(done, 200)
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should have preloaded the existing ranges', function (done) {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
+ await DocUpdaterClient.sendUpdate(
|
|
|
this.project_id,
|
|
|
this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { changes } = data.ranges
|
|
|
- changes[0].op.should.deep.equal({ i: '123', p: 1 })
|
|
|
- changes[1].op.should.deep.equal({ i: '456', p: 5 })
|
|
|
- done()
|
|
|
- }
|
|
|
+ this.update
|
|
|
)
|
|
|
+ await setTimeout(200)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should have preloaded the existing ranges', async function () {
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ const { changes } = doc.ranges
|
|
|
+ changes[0].op.should.deep.equal({ i: '123', p: 1 })
|
|
|
+ changes[1].op.should.deep.equal({ i: '456', p: 5 })
|
|
|
})
|
|
|
|
|
|
- it('should flush the ranges to the persistence layer again', function (done) {
|
|
|
- DocUpdaterClient.flushDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
+ it('should flush the ranges to the persistence layer again', async function () {
|
|
|
+ await DocUpdaterClient.flushDoc(this.project_id, this.doc.id)
|
|
|
+ const doc = await new Promise((resolve, reject) => {
|
|
|
MockWebApi.getDocument(this.project_id, this.doc.id, (error, doc) => {
|
|
|
- if (error) return done(error)
|
|
|
- const { changes } = doc.ranges
|
|
|
- changes[0].op.should.deep.equal({ i: '123', p: 1 })
|
|
|
- changes[1].op.should.deep.equal({ i: '456', p: 5 })
|
|
|
- done()
|
|
|
+ if (error) {
|
|
|
+ reject(error)
|
|
|
+ } else {
|
|
|
+ resolve(doc)
|
|
|
+ }
|
|
|
})
|
|
|
})
|
|
|
+ const { changes } = doc.ranges
|
|
|
+ changes[0].op.should.deep.equal({ i: '123', p: 1 })
|
|
|
+ changes[1].op.should.deep.equal({ i: '456', p: 5 })
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('accepting a change', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
+ beforeEach(async function () {
|
|
|
sandbox.spy(MockWebApi, 'setDocument')
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
@@ -330,105 +240,53 @@ describe('Ranges', function () {
|
|
|
lines: this.doc.lines,
|
|
|
version: 0,
|
|
|
})
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- this.update,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(() => {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { ranges } = data
|
|
|
- const change = ranges.changes[0]
|
|
|
- change.op.should.deep.equal({ i: '456', p: 1 })
|
|
|
- change.id.should.equal(this.id_seed + '000001')
|
|
|
- change.metadata.user_id.should.equal(this.user_id)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- }, 200)
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
+ await DocUpdaterClient.sendUpdate(
|
|
|
+ this.project_id,
|
|
|
+ this.doc.id,
|
|
|
+ this.update
|
|
|
+ )
|
|
|
+ await setTimeout(200)
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ const { ranges } = doc
|
|
|
+ const change = ranges.changes[0]
|
|
|
+ change.op.should.deep.equal({ i: '456', p: 1 })
|
|
|
+ change.id.should.equal(this.id_seed + '000001')
|
|
|
+ change.metadata.user_id.should.equal(this.user_id)
|
|
|
})
|
|
|
afterEach(function () {
|
|
|
sandbox.restore()
|
|
|
})
|
|
|
|
|
|
- it('should remove the change after accepting', function (done) {
|
|
|
- DocUpdaterClient.acceptChange(
|
|
|
+ it('should remove the change after accepting', async function () {
|
|
|
+ await DocUpdaterClient.acceptChange(
|
|
|
this.project_id,
|
|
|
this.doc.id,
|
|
|
- this.id_seed + '000001',
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(data.ranges.changes).to.be.undefined
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
+ this.id_seed + '000001'
|
|
|
)
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ expect(doc.ranges.changes).to.be.undefined
|
|
|
})
|
|
|
|
|
|
- it('should persist the ranges after accepting', function (done) {
|
|
|
- DocUpdaterClient.flushDoc(this.project_id, this.doc.id, err => {
|
|
|
- if (err) return done(err)
|
|
|
- DocUpdaterClient.acceptChange(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- this.id_seed + '000001',
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
-
|
|
|
- DocUpdaterClient.flushDoc(this.project_id, this.doc.id, err => {
|
|
|
- if (err) return done(err)
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(data.ranges.changes).to.be.undefined
|
|
|
-
|
|
|
- MockWebApi.setDocument
|
|
|
- .calledWith(this.project_id, this.doc.id, ['a456aa'], 1, {})
|
|
|
- .should.equal(true)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
+ it('should persist the ranges after accepting', async function () {
|
|
|
+ await DocUpdaterClient.flushDoc(this.project_id, this.doc.id)
|
|
|
+ await DocUpdaterClient.acceptChange(
|
|
|
+ this.project_id,
|
|
|
+ this.doc.id,
|
|
|
+ this.id_seed + '000001'
|
|
|
+ )
|
|
|
+ await DocUpdaterClient.flushDoc(this.project_id, this.doc.id)
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ expect(doc.ranges.changes).to.be.undefined
|
|
|
+
|
|
|
+ MockWebApi.setDocument
|
|
|
+ .calledWith(this.project_id, this.doc.id, ['a456aa'], 1, {})
|
|
|
+ .should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('accepting multiple changes', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
+ beforeEach(async function () {
|
|
|
this.getHistoryUpdatesSpy = sandbox.spy(
|
|
|
RangesManager,
|
|
|
'getHistoryUpdatesForAcceptedChanges'
|
|
|
@@ -446,199 +304,156 @@ describe('Ranges', function () {
|
|
|
version: 0,
|
|
|
historyRangesSupport: true,
|
|
|
})
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
+ this.id_seed_1 = 'tc_1'
|
|
|
+ this.id_seed_2 = 'tc_2'
|
|
|
+ this.id_seed_3 = 'tc_3'
|
|
|
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
-
|
|
|
- this.id_seed_1 = 'tc_1'
|
|
|
- this.id_seed_2 = 'tc_2'
|
|
|
- this.id_seed_3 = 'tc_3'
|
|
|
-
|
|
|
- this.updates = [
|
|
|
- {
|
|
|
- doc: this.doc.id,
|
|
|
- op: [{ d: 'bbb', p: 4 }],
|
|
|
- v: 0,
|
|
|
- meta: {
|
|
|
- user_id: this.user_id,
|
|
|
- tc: this.id_seed_1,
|
|
|
- },
|
|
|
+ this.updates = [
|
|
|
+ {
|
|
|
+ doc: this.doc.id,
|
|
|
+ op: [{ d: 'bbb', p: 4 }],
|
|
|
+ v: 0,
|
|
|
+ meta: {
|
|
|
+ user_id: this.user_id,
|
|
|
+ tc: this.id_seed_1,
|
|
|
},
|
|
|
- {
|
|
|
- doc: this.doc.id,
|
|
|
- op: [{ d: 'ccc', p: 5 }],
|
|
|
- v: 1,
|
|
|
- meta: {
|
|
|
- user_id: this.user_id,
|
|
|
- tc: this.id_seed_2,
|
|
|
- },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ doc: this.doc.id,
|
|
|
+ op: [{ d: 'ccc', p: 5 }],
|
|
|
+ v: 1,
|
|
|
+ meta: {
|
|
|
+ user_id: this.user_id,
|
|
|
+ tc: this.id_seed_2,
|
|
|
},
|
|
|
- {
|
|
|
- doc: this.doc.id,
|
|
|
- op: [{ d: 'ddd', p: 6 }],
|
|
|
- v: 2,
|
|
|
- meta: {
|
|
|
- user_id: this.user_id,
|
|
|
- tc: this.id_seed_3,
|
|
|
- },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ doc: this.doc.id,
|
|
|
+ op: [{ d: 'ddd', p: 6 }],
|
|
|
+ v: 2,
|
|
|
+ meta: {
|
|
|
+ user_id: this.user_id,
|
|
|
+ tc: this.id_seed_3,
|
|
|
},
|
|
|
- ]
|
|
|
-
|
|
|
- DocUpdaterClient.sendUpdates(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- this.updates,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(() => {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { ranges } = data
|
|
|
- const changeOps = ranges.changes
|
|
|
- .map(change => change.op)
|
|
|
- .flat()
|
|
|
- changeOps.should.deep.equal([
|
|
|
- { d: 'bbb', p: 4 },
|
|
|
- { d: 'ccc', p: 5 },
|
|
|
- { d: 'ddd', p: 6 },
|
|
|
- ])
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- }, 200)
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
+ },
|
|
|
+ ]
|
|
|
+
|
|
|
+ await DocUpdaterClient.sendUpdates(
|
|
|
+ this.project_id,
|
|
|
+ this.doc.id,
|
|
|
+ this.updates
|
|
|
+ )
|
|
|
+
|
|
|
+ await setTimeout(200)
|
|
|
+
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ const { ranges } = doc
|
|
|
+ const changeOps = ranges.changes.map(change => change.op).flat()
|
|
|
+ changeOps.should.deep.equal([
|
|
|
+ { d: 'bbb', p: 4 },
|
|
|
+ { d: 'ccc', p: 5 },
|
|
|
+ { d: 'ddd', p: 6 },
|
|
|
+ ])
|
|
|
})
|
|
|
|
|
|
afterEach(function () {
|
|
|
sandbox.restore()
|
|
|
})
|
|
|
|
|
|
- it('accepting changes in order', function (done) {
|
|
|
- DocUpdaterClient.acceptChanges(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- [
|
|
|
- this.id_seed_1 + '000001',
|
|
|
- this.id_seed_2 + '000001',
|
|
|
- this.id_seed_3 + '000001',
|
|
|
- ],
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
-
|
|
|
- const historyUpdates = this.getHistoryUpdatesSpy.returnValues[0]
|
|
|
- expect(historyUpdates[0]).to.deep.equal({
|
|
|
- doc: this.doc.id,
|
|
|
- meta: {
|
|
|
- pathname: '/a/b/c.tex',
|
|
|
- doc_length: 10,
|
|
|
- history_doc_length: 19,
|
|
|
- ts: historyUpdates[0].meta.ts,
|
|
|
- user_id: this.user_id,
|
|
|
- },
|
|
|
- op: [{ p: 4, d: 'bbb' }],
|
|
|
- })
|
|
|
+ it('accepting changes in order', async function () {
|
|
|
+ await DocUpdaterClient.acceptChanges(this.project_id, this.doc.id, [
|
|
|
+ this.id_seed_1 + '000001',
|
|
|
+ this.id_seed_2 + '000001',
|
|
|
+ this.id_seed_3 + '000001',
|
|
|
+ ])
|
|
|
|
|
|
- expect(historyUpdates[1]).to.deep.equal({
|
|
|
- doc: this.doc.id,
|
|
|
- meta: {
|
|
|
- pathname: '/a/b/c.tex',
|
|
|
- doc_length: 10,
|
|
|
- history_doc_length: 16,
|
|
|
- ts: historyUpdates[1].meta.ts,
|
|
|
- user_id: this.user_id,
|
|
|
- },
|
|
|
- op: [{ p: 5, d: 'ccc' }],
|
|
|
- })
|
|
|
+ const historyUpdates = this.getHistoryUpdatesSpy.returnValues[0]
|
|
|
+ expect(historyUpdates[0]).to.deep.equal({
|
|
|
+ doc: this.doc.id,
|
|
|
+ meta: {
|
|
|
+ pathname: '/a/b/c.tex',
|
|
|
+ doc_length: 10,
|
|
|
+ history_doc_length: 19,
|
|
|
+ ts: historyUpdates[0].meta.ts,
|
|
|
+ user_id: this.user_id,
|
|
|
+ },
|
|
|
+ op: [{ p: 4, d: 'bbb' }],
|
|
|
+ })
|
|
|
|
|
|
- expect(historyUpdates[2]).to.deep.equal({
|
|
|
- doc: this.doc.id,
|
|
|
- meta: {
|
|
|
- pathname: '/a/b/c.tex',
|
|
|
- doc_length: 10,
|
|
|
- history_doc_length: 13,
|
|
|
- ts: historyUpdates[2].meta.ts,
|
|
|
- user_id: this.user_id,
|
|
|
- },
|
|
|
- op: [{ p: 6, d: 'ddd' }],
|
|
|
- })
|
|
|
+ expect(historyUpdates[1]).to.deep.equal({
|
|
|
+ doc: this.doc.id,
|
|
|
+ meta: {
|
|
|
+ pathname: '/a/b/c.tex',
|
|
|
+ doc_length: 10,
|
|
|
+ history_doc_length: 16,
|
|
|
+ ts: historyUpdates[1].meta.ts,
|
|
|
+ user_id: this.user_id,
|
|
|
+ },
|
|
|
+ op: [{ p: 5, d: 'ccc' }],
|
|
|
+ })
|
|
|
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ expect(historyUpdates[2]).to.deep.equal({
|
|
|
+ doc: this.doc.id,
|
|
|
+ meta: {
|
|
|
+ pathname: '/a/b/c.tex',
|
|
|
+ doc_length: 10,
|
|
|
+ history_doc_length: 13,
|
|
|
+ ts: historyUpdates[2].meta.ts,
|
|
|
+ user_id: this.user_id,
|
|
|
+ },
|
|
|
+ op: [{ p: 6, d: 'ddd' }],
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
- it('accepting changes in reverse order', function (done) {
|
|
|
- DocUpdaterClient.acceptChanges(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- [
|
|
|
- this.id_seed_3 + '000001',
|
|
|
- this.id_seed_2 + '000001',
|
|
|
- this.id_seed_1 + '000001',
|
|
|
- ],
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
-
|
|
|
- const historyUpdates = this.getHistoryUpdatesSpy.returnValues[0]
|
|
|
- expect(historyUpdates[0]).to.deep.equal({
|
|
|
- doc: this.doc.id,
|
|
|
- meta: {
|
|
|
- pathname: '/a/b/c.tex',
|
|
|
- doc_length: 10,
|
|
|
- history_doc_length: 19,
|
|
|
- ts: historyUpdates[0].meta.ts,
|
|
|
- user_id: this.user_id,
|
|
|
- },
|
|
|
- op: [{ p: 4, d: 'bbb' }],
|
|
|
- })
|
|
|
+ it('accepting changes in reverse order', async function () {
|
|
|
+ await DocUpdaterClient.acceptChanges(this.project_id, this.doc.id, [
|
|
|
+ this.id_seed_3 + '000001',
|
|
|
+ this.id_seed_2 + '000001',
|
|
|
+ this.id_seed_1 + '000001',
|
|
|
+ ])
|
|
|
|
|
|
- expect(historyUpdates[1]).to.deep.equal({
|
|
|
- doc: this.doc.id,
|
|
|
- meta: {
|
|
|
- pathname: '/a/b/c.tex',
|
|
|
- doc_length: 10,
|
|
|
- history_doc_length: 16,
|
|
|
- ts: historyUpdates[1].meta.ts,
|
|
|
- user_id: this.user_id,
|
|
|
- },
|
|
|
- op: [{ p: 5, d: 'ccc' }],
|
|
|
- })
|
|
|
+ const historyUpdates = this.getHistoryUpdatesSpy.returnValues[0]
|
|
|
+ expect(historyUpdates[0]).to.deep.equal({
|
|
|
+ doc: this.doc.id,
|
|
|
+ meta: {
|
|
|
+ pathname: '/a/b/c.tex',
|
|
|
+ doc_length: 10,
|
|
|
+ history_doc_length: 19,
|
|
|
+ ts: historyUpdates[0].meta.ts,
|
|
|
+ user_id: this.user_id,
|
|
|
+ },
|
|
|
+ op: [{ p: 4, d: 'bbb' }],
|
|
|
+ })
|
|
|
|
|
|
- expect(historyUpdates[2]).to.deep.equal({
|
|
|
- doc: this.doc.id,
|
|
|
- meta: {
|
|
|
- pathname: '/a/b/c.tex',
|
|
|
- doc_length: 10,
|
|
|
- history_doc_length: 13,
|
|
|
- ts: historyUpdates[2].meta.ts,
|
|
|
- user_id: this.user_id,
|
|
|
- },
|
|
|
- op: [{ p: 6, d: 'ddd' }],
|
|
|
- })
|
|
|
+ expect(historyUpdates[1]).to.deep.equal({
|
|
|
+ doc: this.doc.id,
|
|
|
+ meta: {
|
|
|
+ pathname: '/a/b/c.tex',
|
|
|
+ doc_length: 10,
|
|
|
+ history_doc_length: 16,
|
|
|
+ ts: historyUpdates[1].meta.ts,
|
|
|
+ user_id: this.user_id,
|
|
|
+ },
|
|
|
+ op: [{ p: 5, d: 'ccc' }],
|
|
|
+ })
|
|
|
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ expect(historyUpdates[2]).to.deep.equal({
|
|
|
+ doc: this.doc.id,
|
|
|
+ meta: {
|
|
|
+ pathname: '/a/b/c.tex',
|
|
|
+ doc_length: 10,
|
|
|
+ history_doc_length: 13,
|
|
|
+ ts: historyUpdates[2].meta.ts,
|
|
|
+ user_id: this.user_id,
|
|
|
+ },
|
|
|
+ op: [{ p: 6, d: 'ddd' }],
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('deleting a comment range', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
this.doc = {
|
|
|
@@ -654,67 +469,33 @@ describe('Ranges', function () {
|
|
|
lines: this.doc.lines,
|
|
|
version: 0,
|
|
|
})
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- this.update,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(() => {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { ranges } = data
|
|
|
- const change = ranges.comments[0]
|
|
|
- change.op.should.deep.equal({ c: 'bar', p: 4, t: this.tid })
|
|
|
- change.id.should.equal(this.tid)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- }, 200)
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
+ await DocUpdaterClient.sendUpdate(
|
|
|
+ this.project_id,
|
|
|
+ this.doc.id,
|
|
|
+ this.update
|
|
|
+ )
|
|
|
+ await setTimeout(200)
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ const { ranges } = doc
|
|
|
+ const change = ranges.comments[0]
|
|
|
+ change.op.should.deep.equal({ c: 'bar', p: 4, t: this.tid })
|
|
|
+ change.id.should.equal(this.tid)
|
|
|
})
|
|
|
|
|
|
- it('should remove the comment range', function (done) {
|
|
|
- DocUpdaterClient.removeComment(
|
|
|
+ it('should remove the comment range', async function () {
|
|
|
+ await DocUpdaterClient.removeComment(
|
|
|
this.project_id,
|
|
|
this.doc.id,
|
|
|
- this.tid,
|
|
|
- (error, res) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(res.statusCode).to.equal(204)
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(data.ranges.comments).to.be.undefined
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
+ this.tid
|
|
|
)
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ expect(doc.ranges.comments).to.be.undefined
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('tripping range size limit', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
this.id_seed = DocUpdaterClient.randomId()
|
|
|
@@ -735,48 +516,21 @@ describe('Ranges', function () {
|
|
|
lines: this.doc.lines,
|
|
|
version: 0,
|
|
|
})
|
|
|
- const jobs = []
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc.id)
|
|
|
for (const update of this.updates) {
|
|
|
- jobs.push(callback =>
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- update,
|
|
|
- callback
|
|
|
- )
|
|
|
- )
|
|
|
+ await DocUpdaterClient.sendUpdate(this.project_id, this.doc.id, update)
|
|
|
}
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc.id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- async.series(jobs, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(done, 200)
|
|
|
- })
|
|
|
- })
|
|
|
+ await setTimeout(200)
|
|
|
})
|
|
|
|
|
|
- it('should not update the ranges', function (done) {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc.id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- const { ranges } = data
|
|
|
- expect(ranges.changes).to.be.undefined
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should not update the ranges', async function () {
|
|
|
+ const doc = await DocUpdaterClient.getDoc(this.project_id, this.doc.id)
|
|
|
+ expect(doc.ranges.changes).to.be.undefined
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('deleting text surrounding a comment', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
|
|
@@ -813,70 +567,30 @@ describe('Ranges', function () {
|
|
|
meta: { user_id: this.user_id },
|
|
|
},
|
|
|
]
|
|
|
- const jobs = []
|
|
|
+ await DocUpdaterClient.preloadDoc(this.project_id, this.doc_id)
|
|
|
for (const update of this.updates) {
|
|
|
- jobs.push(callback =>
|
|
|
- DocUpdaterClient.sendUpdate(
|
|
|
- this.project_id,
|
|
|
- this.doc_id,
|
|
|
- update,
|
|
|
- callback
|
|
|
- )
|
|
|
- )
|
|
|
+ await DocUpdaterClient.sendUpdate(this.project_id, this.doc_id, update)
|
|
|
}
|
|
|
- DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- async.series(jobs, function (error) {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- setTimeout(() => {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc_id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- }, 200)
|
|
|
- })
|
|
|
- })
|
|
|
+ await setTimeout(200)
|
|
|
+ await DocUpdaterClient.getDoc(this.project_id, this.doc_id)
|
|
|
})
|
|
|
|
|
|
- it('should write a snapshot from before the destructive change', function (done) {
|
|
|
- DocUpdaterClient.getDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc_id,
|
|
|
- (error, res, data) => {
|
|
|
- if (error != null) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- db.docSnapshots
|
|
|
- .find({
|
|
|
- project_id: new ObjectId(this.project_id),
|
|
|
- doc_id: new ObjectId(this.doc_id),
|
|
|
- })
|
|
|
- .toArray((error, docSnapshots) => {
|
|
|
- if (error != null) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- expect(docSnapshots.length).to.equal(1)
|
|
|
- expect(docSnapshots[0].version).to.equal(1)
|
|
|
- expect(docSnapshots[0].lines).to.deep.equal(['bar baz'])
|
|
|
- expect(docSnapshots[0].ranges.comments[0].op).to.deep.equal({
|
|
|
- c: 'a',
|
|
|
- p: 1,
|
|
|
- tid: this.tid,
|
|
|
- })
|
|
|
- done()
|
|
|
- })
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should write a snapshot from before the destructive change', async function () {
|
|
|
+ await DocUpdaterClient.getDoc(this.project_id, this.doc_id)
|
|
|
+ const docSnapshots = await db.docSnapshots
|
|
|
+ .find({
|
|
|
+ project_id: new ObjectId(this.project_id),
|
|
|
+ doc_id: new ObjectId(this.doc_id),
|
|
|
+ })
|
|
|
+ .toArray()
|
|
|
+ expect(docSnapshots.length).to.equal(1)
|
|
|
+ expect(docSnapshots[0].version).to.equal(1)
|
|
|
+ expect(docSnapshots[0].lines).to.deep.equal(['bar baz'])
|
|
|
+ expect(docSnapshots[0].ranges.comments[0].op).to.deep.equal({
|
|
|
+ c: 'a',
|
|
|
+ p: 1,
|
|
|
+ tid: this.tid,
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
})
|