2020-05-06 06:12:47 -04:00
|
|
|
const sinon = require('sinon')
|
2021-07-12 12:47:15 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-11-10 06:32:04 -05:00
|
|
|
const rclientProjectHistory = require('@overleaf/redis-wrapper').createClient(
|
2020-05-06 06:12:47 -04:00
|
|
|
Settings.redis.project_history
|
|
|
|
)
|
|
|
|
const ProjectHistoryKeys = Settings.redis.project_history.key_schema
|
|
|
|
|
|
|
|
const MockProjectHistoryApi = require('./helpers/MockProjectHistoryApi')
|
|
|
|
const MockWebApi = require('./helpers/MockWebApi')
|
|
|
|
const DocUpdaterClient = require('./helpers/DocUpdaterClient')
|
|
|
|
const DocUpdaterApp = require('./helpers/DocUpdaterApp')
|
|
|
|
|
|
|
|
describe("Applying updates to a project's structure", function () {
|
|
|
|
before(function () {
|
|
|
|
this.user_id = 'user-id-123'
|
2020-05-20 15:32:57 -04:00
|
|
|
this.version = 1234
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('renaming a file', function () {
|
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.fileUpdate = {
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'rename-file',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/file-path',
|
2021-07-13 07:04:42 -04:00
|
|
|
newPathname: '/new-file-path',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates = [this.fileUpdate]
|
2021-07-13 07:04:42 -04:00
|
|
|
DocUpdaterApp.ensureRunning(error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
2020-05-06 06:12:47 -04:00
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates,
|
2020-05-06 06:12:47 -04:00
|
|
|
this.version,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should push the applied file renames to the project history api', function (done) {
|
2020-05-20 15:35:12 -04:00
|
|
|
rclientProjectHistory.lrange(
|
2020-05-06 06:12:47 -04:00
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
(error, updates) => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
|
|
update.file.should.equal(this.fileUpdate.id)
|
|
|
|
update.pathname.should.equal('/file-path')
|
|
|
|
update.new_pathname.should.equal('/new-file-path')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renaming a document', function () {
|
|
|
|
before(function () {
|
2020-05-20 16:26:22 -04:00
|
|
|
this.update = {
|
|
|
|
type: 'rename-doc',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/doc-path',
|
2021-07-13 07:04:42 -04:00
|
|
|
newPathname: '/new-doc-path',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates = [this.update]
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the document is not loaded', function () {
|
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates,
|
2020-05-06 06:12:47 -04:00
|
|
|
this.version,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should push the applied doc renames to the project history api', function (done) {
|
2020-05-20 15:35:12 -04:00
|
|
|
rclientProjectHistory.lrange(
|
2020-05-06 06:12:47 -04:00
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
(error, updates) => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
2020-05-20 16:26:22 -04:00
|
|
|
update.doc.should.equal(this.update.id)
|
2020-05-06 06:12:47 -04:00
|
|
|
update.pathname.should.equal('/doc-path')
|
|
|
|
update.new_pathname.should.equal('/new-doc-path')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
describe('when the document is loaded', function () {
|
2020-05-06 06:12:47 -04:00
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
2020-05-20 16:26:22 -04:00
|
|
|
MockWebApi.insertDoc(this.project_id, this.update.id, {})
|
2021-07-13 07:04:42 -04:00
|
|
|
DocUpdaterClient.preloadDoc(this.project_id, this.update.id, error => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2021-07-13 07:04:42 -04:00
|
|
|
sinon.spy(MockWebApi, 'getDocument')
|
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.updates,
|
|
|
|
this.version,
|
|
|
|
error => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
setTimeout(done, 200)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-20 15:32:57 -04:00
|
|
|
MockWebApi.getDocument.restore()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should update the doc', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
2020-05-20 16:26:22 -04:00
|
|
|
this.update.id,
|
2020-05-06 06:12:47 -04:00
|
|
|
(error, res, doc) => {
|
2020-05-20 15:34:28 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-20 16:26:22 -04:00
|
|
|
doc.pathname.should.equal(this.update.newPathname)
|
2020-05-20 15:32:57 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should push the applied doc renames to the project history api', function (done) {
|
2020-05-20 15:35:12 -04:00
|
|
|
rclientProjectHistory.lrange(
|
2020-05-06 06:12:47 -04:00
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
(error, updates) => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
2020-05-20 16:26:22 -04:00
|
|
|
update.doc.should.equal(this.update.id)
|
2020-05-06 06:12:47 -04:00
|
|
|
update.pathname.should.equal('/doc-path')
|
|
|
|
update.new_pathname.should.equal('/new-doc-path')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renaming multiple documents and files', function () {
|
|
|
|
before(function () {
|
|
|
|
this.docUpdate0 = {
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'rename-doc',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/doc-path0',
|
2021-07-13 07:04:42 -04:00
|
|
|
newPathname: '/new-doc-path0',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
this.docUpdate1 = {
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'rename-doc',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/doc-path1',
|
2021-07-13 07:04:42 -04:00
|
|
|
newPathname: '/new-doc-path1',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
this.fileUpdate0 = {
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'rename-file',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/file-path0',
|
2021-07-13 07:04:42 -04:00
|
|
|
newPathname: '/new-file-path0',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
this.fileUpdate1 = {
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'rename-file',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/file-path1',
|
2021-07-13 07:04:42 -04:00
|
|
|
newPathname: '/new-file-path1',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates = [
|
|
|
|
this.docUpdate0,
|
|
|
|
this.docUpdate1,
|
|
|
|
this.fileUpdate0,
|
2021-07-13 07:04:42 -04:00
|
|
|
this.fileUpdate1,
|
2020-05-20 16:26:22 -04:00
|
|
|
]
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
describe('when the documents are not loaded', function () {
|
2020-05-06 06:12:47 -04:00
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates,
|
2020-05-06 06:12:47 -04:00
|
|
|
this.version,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should push the applied doc renames to the project history api', function (done) {
|
2020-05-20 15:35:12 -04:00
|
|
|
rclientProjectHistory.lrange(
|
2020-05-06 06:12:47 -04:00
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
(error, updates) => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let update = JSON.parse(updates[0])
|
|
|
|
update.doc.should.equal(this.docUpdate0.id)
|
|
|
|
update.pathname.should.equal('/doc-path0')
|
|
|
|
update.new_pathname.should.equal('/new-doc-path0')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
|
|
|
update = JSON.parse(updates[1])
|
|
|
|
update.doc.should.equal(this.docUpdate1.id)
|
|
|
|
update.pathname.should.equal('/doc-path1')
|
|
|
|
update.new_pathname.should.equal('/new-doc-path1')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.1`)
|
|
|
|
|
|
|
|
update = JSON.parse(updates[2])
|
|
|
|
update.file.should.equal(this.fileUpdate0.id)
|
|
|
|
update.pathname.should.equal('/file-path0')
|
|
|
|
update.new_pathname.should.equal('/new-file-path0')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.2`)
|
|
|
|
|
|
|
|
update = JSON.parse(updates[3])
|
|
|
|
update.file.should.equal(this.fileUpdate1.id)
|
|
|
|
update.pathname.should.equal('/file-path1')
|
|
|
|
update.new_pathname.should.equal('/new-file-path1')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.3`)
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('adding a file', function () {
|
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.fileUpdate = {
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'add-file',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/file-path',
|
2021-07-13 07:04:42 -04:00
|
|
|
url: 'filestore.example.com',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates = [this.fileUpdate]
|
2020-05-06 06:12:47 -04:00
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates,
|
2020-05-06 06:12:47 -04:00
|
|
|
this.version,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should push the file addition to the project history api', function (done) {
|
2020-05-20 15:35:12 -04:00
|
|
|
rclientProjectHistory.lrange(
|
2020-05-06 06:12:47 -04:00
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
(error, updates) => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
|
|
update.file.should.equal(this.fileUpdate.id)
|
|
|
|
update.pathname.should.equal('/file-path')
|
|
|
|
update.url.should.equal('filestore.example.com')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('adding a doc', function () {
|
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.docUpdate = {
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'add-doc',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/file-path',
|
2021-07-13 07:04:42 -04:00
|
|
|
docLines: 'a\nb',
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates = [this.docUpdate]
|
2020-05-06 06:12:47 -04:00
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
2020-05-20 16:26:22 -04:00
|
|
|
this.updates,
|
2020-05-06 06:12:47 -04:00
|
|
|
this.version,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should push the doc addition to the project history api', function (done) {
|
2020-05-20 15:35:12 -04:00
|
|
|
rclientProjectHistory.lrange(
|
2020-05-06 06:12:47 -04:00
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
(error, updates) => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
|
|
update.doc.should.equal(this.docUpdate.id)
|
|
|
|
update.pathname.should.equal('/file-path')
|
|
|
|
update.docLines.should.equal('a\nb')
|
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
|
update.meta.ts.should.be.a('string')
|
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with enough updates to flush to the history service', function () {
|
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
|
this.version0 = 12345
|
|
|
|
this.version1 = this.version0 + 1
|
|
|
|
const updates = []
|
|
|
|
for (let v = 0; v <= 599; v++) {
|
|
|
|
// Should flush after 500 ops
|
|
|
|
updates.push({
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'add-doc',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/file-' + v,
|
2021-07-13 07:04:42 -04:00
|
|
|
docLines: 'a\nb',
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
sinon.spy(MockProjectHistoryApi, 'flushProject')
|
|
|
|
|
|
|
|
// Send updates in chunks to causes multiple flushes
|
|
|
|
const projectId = this.project_id
|
|
|
|
const userId = this.project_id
|
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
|
projectId,
|
|
|
|
userId,
|
|
|
|
updates.slice(0, 250),
|
|
|
|
this.version0,
|
|
|
|
function (error) {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
2020-05-06 06:12:47 -04:00
|
|
|
projectId,
|
|
|
|
userId,
|
|
|
|
updates.slice(250),
|
|
|
|
this.version1,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
setTimeout(done, 2000)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-20 15:32:57 -04:00
|
|
|
MockProjectHistoryApi.flushProject.restore()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should flush project history', function () {
|
|
|
|
MockProjectHistoryApi.flushProject
|
2020-05-06 06:12:47 -04:00
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
describe('with too few updates to flush to the history service', function () {
|
2020-05-06 06:12:47 -04:00
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
|
|
this.version0 = 12345
|
|
|
|
this.version1 = this.version0 + 1
|
|
|
|
|
|
|
|
const updates = []
|
|
|
|
for (let v = 0; v <= 42; v++) {
|
|
|
|
// Should flush after 500 ops
|
|
|
|
updates.push({
|
2020-05-20 16:26:22 -04:00
|
|
|
type: 'add-doc',
|
2020-05-06 06:12:47 -04:00
|
|
|
id: DocUpdaterClient.randomId(),
|
|
|
|
pathname: '/file-' + v,
|
2021-07-13 07:04:42 -04:00
|
|
|
docLines: 'a\nb',
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
sinon.spy(MockProjectHistoryApi, 'flushProject')
|
|
|
|
|
|
|
|
// Send updates in chunks
|
|
|
|
const projectId = this.project_id
|
|
|
|
const userId = this.project_id
|
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
|
projectId,
|
|
|
|
userId,
|
|
|
|
updates.slice(0, 10),
|
|
|
|
this.version0,
|
|
|
|
function (error) {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
2020-05-06 06:12:47 -04:00
|
|
|
projectId,
|
|
|
|
userId,
|
|
|
|
updates.slice(10),
|
|
|
|
this.version1,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-20 15:31:41 -04:00
|
|
|
if (error) {
|
2020-05-20 15:34:28 -04:00
|
|
|
return done(error)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-20 15:32:57 -04:00
|
|
|
setTimeout(done, 2000)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-20 15:32:57 -04:00
|
|
|
MockProjectHistoryApi.flushProject.restore()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-20 15:32:57 -04:00
|
|
|
it('should not flush project history', function () {
|
|
|
|
MockProjectHistoryApi.flushProject
|
2020-05-06 06:12:47 -04:00
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|