|
@@ -1,21 +1,8 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- camelcase,
|
|
|
|
|
- handle-callback-err,
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
-*/
|
|
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
|
|
-/*
|
|
|
|
|
- * decaffeinate suggestions:
|
|
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
- * DS207: Consider shorter variations of null checks
|
|
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
|
- */
|
|
|
|
|
const sinon = require('sinon')
|
|
const sinon = require('sinon')
|
|
|
const chai = require('chai')
|
|
const chai = require('chai')
|
|
|
chai.should()
|
|
chai.should()
|
|
|
const Settings = require('settings-sharelatex')
|
|
const Settings = require('settings-sharelatex')
|
|
|
-const rclient_project_history = require('redis-sharelatex').createClient(
|
|
|
|
|
|
|
+const rclientProjectHistory = require('redis-sharelatex').createClient(
|
|
|
Settings.redis.project_history
|
|
Settings.redis.project_history
|
|
|
)
|
|
)
|
|
|
const ProjectHistoryKeys = Settings.redis.project_history.key_schema
|
|
const ProjectHistoryKeys = Settings.redis.project_history.key_schema
|
|
@@ -28,46 +15,46 @@ const DocUpdaterApp = require('./helpers/DocUpdaterApp')
|
|
|
describe("Applying updates to a project's structure", function () {
|
|
describe("Applying updates to a project's structure", function () {
|
|
|
before(function () {
|
|
before(function () {
|
|
|
this.user_id = 'user-id-123'
|
|
this.user_id = 'user-id-123'
|
|
|
- return (this.version = 1234)
|
|
|
|
|
|
|
+ this.version = 1234
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('renaming a file', function () {
|
|
describe('renaming a file', function () {
|
|
|
before(function (done) {
|
|
before(function (done) {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.fileUpdate = {
|
|
this.fileUpdate = {
|
|
|
|
|
+ type: 'rename-file',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/file-path',
|
|
pathname: '/file-path',
|
|
|
newPathname: '/new-file-path'
|
|
newPathname: '/new-file-path'
|
|
|
}
|
|
}
|
|
|
- this.fileUpdates = [this.fileUpdate]
|
|
|
|
|
- return DocUpdaterApp.ensureRunning((error) => {
|
|
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ this.updates = [this.fileUpdate]
|
|
|
|
|
+ DocUpdaterApp.ensureRunning((error) => {
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return DocUpdaterClient.sendProjectUpdate(
|
|
|
|
|
|
|
+ DocUpdaterClient.sendProjectUpdate(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- [],
|
|
|
|
|
- this.fileUpdates,
|
|
|
|
|
|
|
+ this.updates,
|
|
|
this.version,
|
|
this.version,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 200)
|
|
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should push the applied file renames to the project history api', function (done) {
|
|
|
|
|
- rclient_project_history.lrange(
|
|
|
|
|
|
|
+ it('should push the applied file renames to the project history api', function (done) {
|
|
|
|
|
+ rclientProjectHistory.lrange(
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
0,
|
|
0,
|
|
|
-1,
|
|
-1,
|
|
|
(error, updates) => {
|
|
(error, updates) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
const update = JSON.parse(updates[0])
|
|
@@ -78,21 +65,21 @@ describe("Applying updates to a project's structure", function () {
|
|
|
update.meta.ts.should.be.a('string')
|
|
update.meta.ts.should.be.a('string')
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('renaming a document', function () {
|
|
describe('renaming a document', function () {
|
|
|
before(function () {
|
|
before(function () {
|
|
|
- this.docUpdate = {
|
|
|
|
|
|
|
+ this.update = {
|
|
|
|
|
+ type: 'rename-doc',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/doc-path',
|
|
pathname: '/doc-path',
|
|
|
newPathname: '/new-doc-path'
|
|
newPathname: '/new-doc-path'
|
|
|
}
|
|
}
|
|
|
- return (this.docUpdates = [this.docUpdate])
|
|
|
|
|
|
|
+ this.updates = [this.update]
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('when the document is not loaded', function () {
|
|
describe('when the document is not loaded', function () {
|
|
@@ -101,112 +88,108 @@ describe("Applying updates to a project's structure", function () {
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- this.docUpdates,
|
|
|
|
|
- [],
|
|
|
|
|
|
|
+ this.updates,
|
|
|
this.version,
|
|
this.version,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 200)
|
|
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should push the applied doc renames to the project history api', function (done) {
|
|
|
|
|
- rclient_project_history.lrange(
|
|
|
|
|
|
|
+ it('should push the applied doc renames to the project history api', function (done) {
|
|
|
|
|
+ rclientProjectHistory.lrange(
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
0,
|
|
0,
|
|
|
-1,
|
|
-1,
|
|
|
(error, updates) => {
|
|
(error, updates) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
const update = JSON.parse(updates[0])
|
|
|
- update.doc.should.equal(this.docUpdate.id)
|
|
|
|
|
|
|
+ update.doc.should.equal(this.update.id)
|
|
|
update.pathname.should.equal('/doc-path')
|
|
update.pathname.should.equal('/doc-path')
|
|
|
update.new_pathname.should.equal('/new-doc-path')
|
|
update.new_pathname.should.equal('/new-doc-path')
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
update.meta.ts.should.be.a('string')
|
|
update.meta.ts.should.be.a('string')
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('when the document is loaded', function () {
|
|
|
|
|
|
|
+ describe('when the document is loaded', function () {
|
|
|
before(function (done) {
|
|
before(function (done) {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
- MockWebApi.insertDoc(this.project_id, this.docUpdate.id, {})
|
|
|
|
|
|
|
+ MockWebApi.insertDoc(this.project_id, this.update.id, {})
|
|
|
DocUpdaterClient.preloadDoc(
|
|
DocUpdaterClient.preloadDoc(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
- this.docUpdate.id,
|
|
|
|
|
|
|
+ this.update.id,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
sinon.spy(MockWebApi, 'getDocument')
|
|
sinon.spy(MockWebApi, 'getDocument')
|
|
|
- return DocUpdaterClient.sendProjectUpdate(
|
|
|
|
|
|
|
+ DocUpdaterClient.sendProjectUpdate(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- this.docUpdates,
|
|
|
|
|
- [],
|
|
|
|
|
|
|
+ this.updates,
|
|
|
this.version,
|
|
this.version,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 200)
|
|
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
|
after(function () {
|
|
|
- return MockWebApi.getDocument.restore()
|
|
|
|
|
|
|
+ MockWebApi.getDocument.restore()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should update the doc', function (done) {
|
|
it('should update the doc', function (done) {
|
|
|
DocUpdaterClient.getDoc(
|
|
DocUpdaterClient.getDoc(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
- this.docUpdate.id,
|
|
|
|
|
|
|
+ this.update.id,
|
|
|
(error, res, doc) => {
|
|
(error, res, doc) => {
|
|
|
- doc.pathname.should.equal(this.docUpdate.newPathname)
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
|
|
+ }
|
|
|
|
|
+ doc.pathname.should.equal(this.update.newPathname)
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should push the applied doc renames to the project history api', function (done) {
|
|
|
|
|
- rclient_project_history.lrange(
|
|
|
|
|
|
|
+ it('should push the applied doc renames to the project history api', function (done) {
|
|
|
|
|
+ rclientProjectHistory.lrange(
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
0,
|
|
0,
|
|
|
-1,
|
|
-1,
|
|
|
(error, updates) => {
|
|
(error, updates) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
const update = JSON.parse(updates[0])
|
|
|
- update.doc.should.equal(this.docUpdate.id)
|
|
|
|
|
|
|
+ update.doc.should.equal(this.update.id)
|
|
|
update.pathname.should.equal('/doc-path')
|
|
update.pathname.should.equal('/doc-path')
|
|
|
update.new_pathname.should.equal('/new-doc-path')
|
|
update.new_pathname.should.equal('/new-doc-path')
|
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
update.meta.user_id.should.equal(this.user_id)
|
|
|
update.meta.ts.should.be.a('string')
|
|
update.meta.ts.should.be.a('string')
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -214,56 +197,62 @@ describe("Applying updates to a project's structure", function () {
|
|
|
describe('renaming multiple documents and files', function () {
|
|
describe('renaming multiple documents and files', function () {
|
|
|
before(function () {
|
|
before(function () {
|
|
|
this.docUpdate0 = {
|
|
this.docUpdate0 = {
|
|
|
|
|
+ type: 'rename-doc',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/doc-path0',
|
|
pathname: '/doc-path0',
|
|
|
newPathname: '/new-doc-path0'
|
|
newPathname: '/new-doc-path0'
|
|
|
}
|
|
}
|
|
|
this.docUpdate1 = {
|
|
this.docUpdate1 = {
|
|
|
|
|
+ type: 'rename-doc',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/doc-path1',
|
|
pathname: '/doc-path1',
|
|
|
newPathname: '/new-doc-path1'
|
|
newPathname: '/new-doc-path1'
|
|
|
}
|
|
}
|
|
|
- this.docUpdates = [this.docUpdate0, this.docUpdate1]
|
|
|
|
|
this.fileUpdate0 = {
|
|
this.fileUpdate0 = {
|
|
|
|
|
+ type: 'rename-file',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/file-path0',
|
|
pathname: '/file-path0',
|
|
|
newPathname: '/new-file-path0'
|
|
newPathname: '/new-file-path0'
|
|
|
}
|
|
}
|
|
|
this.fileUpdate1 = {
|
|
this.fileUpdate1 = {
|
|
|
|
|
+ type: 'rename-file',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/file-path1',
|
|
pathname: '/file-path1',
|
|
|
newPathname: '/new-file-path1'
|
|
newPathname: '/new-file-path1'
|
|
|
}
|
|
}
|
|
|
- return (this.fileUpdates = [this.fileUpdate0, this.fileUpdate1])
|
|
|
|
|
|
|
+ this.updates = [
|
|
|
|
|
+ this.docUpdate0,
|
|
|
|
|
+ this.docUpdate1,
|
|
|
|
|
+ this.fileUpdate0,
|
|
|
|
|
+ this.fileUpdate1
|
|
|
|
|
+ ]
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('when the documents are not loaded', function () {
|
|
|
|
|
|
|
+ describe('when the documents are not loaded', function () {
|
|
|
before(function (done) {
|
|
before(function (done) {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- this.docUpdates,
|
|
|
|
|
- this.fileUpdates,
|
|
|
|
|
|
|
+ this.updates,
|
|
|
this.version,
|
|
this.version,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 200)
|
|
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should push the applied doc renames to the project history api', function (done) {
|
|
|
|
|
- rclient_project_history.lrange(
|
|
|
|
|
|
|
+ it('should push the applied doc renames to the project history api', function (done) {
|
|
|
|
|
+ rclientProjectHistory.lrange(
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
0,
|
|
0,
|
|
|
-1,
|
|
-1,
|
|
|
(error, updates) => {
|
|
(error, updates) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let update = JSON.parse(updates[0])
|
|
let update = JSON.parse(updates[0])
|
|
@@ -298,10 +287,9 @@ describe("Applying updates to a project's structure", function () {
|
|
|
update.meta.ts.should.be.a('string')
|
|
update.meta.ts.should.be.a('string')
|
|
|
update.version.should.equal(`${this.version}.3`)
|
|
update.version.should.equal(`${this.version}.3`)
|
|
|
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -310,35 +298,34 @@ describe("Applying updates to a project's structure", function () {
|
|
|
before(function (done) {
|
|
before(function (done) {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.fileUpdate = {
|
|
this.fileUpdate = {
|
|
|
|
|
+ type: 'add-file',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/file-path',
|
|
pathname: '/file-path',
|
|
|
url: 'filestore.example.com'
|
|
url: 'filestore.example.com'
|
|
|
}
|
|
}
|
|
|
- this.fileUpdates = [this.fileUpdate]
|
|
|
|
|
|
|
+ this.updates = [this.fileUpdate]
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- [],
|
|
|
|
|
- this.fileUpdates,
|
|
|
|
|
|
|
+ this.updates,
|
|
|
this.version,
|
|
this.version,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 200)
|
|
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should push the file addition to the project history api', function (done) {
|
|
|
|
|
- rclient_project_history.lrange(
|
|
|
|
|
|
|
+ it('should push the file addition to the project history api', function (done) {
|
|
|
|
|
+ rclientProjectHistory.lrange(
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
0,
|
|
0,
|
|
|
-1,
|
|
-1,
|
|
|
(error, updates) => {
|
|
(error, updates) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
const update = JSON.parse(updates[0])
|
|
@@ -349,10 +336,9 @@ describe("Applying updates to a project's structure", function () {
|
|
|
update.meta.ts.should.be.a('string')
|
|
update.meta.ts.should.be.a('string')
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -360,35 +346,34 @@ describe("Applying updates to a project's structure", function () {
|
|
|
before(function (done) {
|
|
before(function (done) {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.docUpdate = {
|
|
this.docUpdate = {
|
|
|
|
|
+ type: 'add-doc',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/file-path',
|
|
pathname: '/file-path',
|
|
|
docLines: 'a\nb'
|
|
docLines: 'a\nb'
|
|
|
}
|
|
}
|
|
|
- this.docUpdates = [this.docUpdate]
|
|
|
|
|
|
|
+ this.updates = [this.docUpdate]
|
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
DocUpdaterClient.sendProjectUpdate(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- this.docUpdates,
|
|
|
|
|
- [],
|
|
|
|
|
|
|
+ this.updates,
|
|
|
this.version,
|
|
this.version,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 200)
|
|
|
|
|
|
|
+ setTimeout(done, 200)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should push the doc addition to the project history api', function (done) {
|
|
|
|
|
- rclient_project_history.lrange(
|
|
|
|
|
|
|
+ it('should push the doc addition to the project history api', function (done) {
|
|
|
|
|
+ rclientProjectHistory.lrange(
|
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
ProjectHistoryKeys.projectHistoryOps({ project_id: this.project_id }),
|
|
|
0,
|
|
0,
|
|
|
-1,
|
|
-1,
|
|
|
(error, updates) => {
|
|
(error, updates) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const update = JSON.parse(updates[0])
|
|
const update = JSON.parse(updates[0])
|
|
@@ -399,10 +384,9 @@ describe("Applying updates to a project's structure", function () {
|
|
|
update.meta.ts.should.be.a('string')
|
|
update.meta.ts.should.be.a('string')
|
|
|
update.version.should.equal(`${this.version}.0`)
|
|
update.version.should.equal(`${this.version}.0`)
|
|
|
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -416,6 +400,7 @@ describe("Applying updates to a project's structure", function () {
|
|
|
for (let v = 0; v <= 599; v++) {
|
|
for (let v = 0; v <= 599; v++) {
|
|
|
// Should flush after 500 ops
|
|
// Should flush after 500 ops
|
|
|
updates.push({
|
|
updates.push({
|
|
|
|
|
+ type: 'add-doc',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/file-' + v,
|
|
pathname: '/file-' + v,
|
|
|
docLines: 'a\nb'
|
|
docLines: 'a\nb'
|
|
@@ -431,42 +416,39 @@ describe("Applying updates to a project's structure", function () {
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
updates.slice(0, 250),
|
|
updates.slice(0, 250),
|
|
|
- [],
|
|
|
|
|
this.version0,
|
|
this.version0,
|
|
|
function (error) {
|
|
function (error) {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return DocUpdaterClient.sendProjectUpdate(
|
|
|
|
|
|
|
+ DocUpdaterClient.sendProjectUpdate(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
updates.slice(250),
|
|
updates.slice(250),
|
|
|
- [],
|
|
|
|
|
this.version1,
|
|
this.version1,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 2000)
|
|
|
|
|
|
|
+ setTimeout(done, 2000)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
|
after(function () {
|
|
|
- return MockProjectHistoryApi.flushProject.restore()
|
|
|
|
|
|
|
+ MockProjectHistoryApi.flushProject.restore()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should flush project history', function () {
|
|
|
|
|
- return MockProjectHistoryApi.flushProject
|
|
|
|
|
|
|
+ it('should flush project history', function () {
|
|
|
|
|
+ MockProjectHistoryApi.flushProject
|
|
|
.calledWith(this.project_id)
|
|
.calledWith(this.project_id)
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('with too few updates to flush to the history service', function () {
|
|
|
|
|
|
|
+ describe('with too few updates to flush to the history service', function () {
|
|
|
before(function (done) {
|
|
before(function (done) {
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
this.user_id = DocUpdaterClient.randomId()
|
|
@@ -477,6 +459,7 @@ describe("Applying updates to a project's structure", function () {
|
|
|
for (let v = 0; v <= 42; v++) {
|
|
for (let v = 0; v <= 42; v++) {
|
|
|
// Should flush after 500 ops
|
|
// Should flush after 500 ops
|
|
|
updates.push({
|
|
updates.push({
|
|
|
|
|
+ type: 'add-doc',
|
|
|
id: DocUpdaterClient.randomId(),
|
|
id: DocUpdaterClient.randomId(),
|
|
|
pathname: '/file-' + v,
|
|
pathname: '/file-' + v,
|
|
|
docLines: 'a\nb'
|
|
docLines: 'a\nb'
|
|
@@ -492,36 +475,33 @@ describe("Applying updates to a project's structure", function () {
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
updates.slice(0, 10),
|
|
updates.slice(0, 10),
|
|
|
- [],
|
|
|
|
|
this.version0,
|
|
this.version0,
|
|
|
function (error) {
|
|
function (error) {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return DocUpdaterClient.sendProjectUpdate(
|
|
|
|
|
|
|
+ DocUpdaterClient.sendProjectUpdate(
|
|
|
projectId,
|
|
projectId,
|
|
|
userId,
|
|
userId,
|
|
|
updates.slice(10),
|
|
updates.slice(10),
|
|
|
- [],
|
|
|
|
|
this.version1,
|
|
this.version1,
|
|
|
(error) => {
|
|
(error) => {
|
|
|
- if (error != null) {
|
|
|
|
|
- throw error
|
|
|
|
|
|
|
+ if (error) {
|
|
|
|
|
+ return done(error)
|
|
|
}
|
|
}
|
|
|
- return setTimeout(done, 2000)
|
|
|
|
|
|
|
+ setTimeout(done, 2000)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
- return null
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
|
after(function () {
|
|
|
- return MockProjectHistoryApi.flushProject.restore()
|
|
|
|
|
|
|
+ MockProjectHistoryApi.flushProject.restore()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should not flush project history', function () {
|
|
|
|
|
- return MockProjectHistoryApi.flushProject
|
|
|
|
|
|
|
+ it('should not flush project history', function () {
|
|
|
|
|
+ MockProjectHistoryApi.flushProject
|
|
|
.calledWith(this.project_id)
|
|
.calledWith(this.project_id)
|
|
|
.should.equal(false)
|
|
.should.equal(false)
|
|
|
})
|
|
})
|