2020-05-06 06:12:47 -04:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const { expect } = require('chai')
|
2021-07-12 12:47:15 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-11-10 06:32:04 -05:00
|
|
|
const docUpdaterRedis = require('@overleaf/redis-wrapper').createClient(
|
2020-05-06 06:12:47 -04:00
|
|
|
Settings.redis.documentupdater
|
|
|
|
)
|
|
|
|
const Keys = Settings.redis.documentupdater.key_schema
|
|
|
|
|
|
|
|
const MockProjectHistoryApi = require('./helpers/MockProjectHistoryApi')
|
|
|
|
const MockWebApi = require('./helpers/MockWebApi')
|
|
|
|
const DocUpdaterClient = require('./helpers/DocUpdaterClient')
|
|
|
|
const DocUpdaterApp = require('./helpers/DocUpdaterApp')
|
|
|
|
|
|
|
|
describe('Setting a document', function () {
|
2022-11-03 06:20:18 -04:00
|
|
|
let numberOfReceivedUpdates = 0
|
2020-05-06 06:12:47 -04:00
|
|
|
before(function (done) {
|
2022-11-03 06:20:18 -04:00
|
|
|
DocUpdaterClient.subscribeToAppliedOps(() => {
|
|
|
|
numberOfReceivedUpdates++
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
this.lines = ['one', 'two', 'three']
|
|
|
|
this.version = 42
|
|
|
|
this.update = {
|
|
|
|
doc: this.doc_id,
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
i: 'one and a half\n',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 4,
|
|
|
|
},
|
2020-05-06 06:12:47 -04:00
|
|
|
],
|
2021-07-13 07:04:42 -04:00
|
|
|
v: this.version,
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
this.result = ['one', 'one and a half', 'two', 'three']
|
|
|
|
this.newLines = ['these', 'are', 'the', 'new', 'lines']
|
|
|
|
this.source = 'dropbox'
|
|
|
|
this.user_id = 'user-id-123'
|
|
|
|
|
|
|
|
sinon.spy(MockProjectHistoryApi, 'flushProject')
|
|
|
|
sinon.spy(MockWebApi, 'setDocument')
|
2020-05-08 12:03:54 -04:00
|
|
|
DocUpdaterApp.ensureRunning(done)
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
MockProjectHistoryApi.flushProject.restore()
|
2020-05-08 12:03:54 -04:00
|
|
|
MockWebApi.setDocument.restore()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the updated doc exists in the doc updater', function () {
|
|
|
|
before(function (done) {
|
2022-11-03 06:20:18 -04:00
|
|
|
numberOfReceivedUpdates = 0
|
2020-05-08 12:01:25 -04:00
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
2020-05-06 06:12:47 -04:00
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 07:04:42 -04:00
|
|
|
version: this.version,
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
2021-07-13 07:04:42 -04:00
|
|
|
DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
2020-05-08 12:03:54 -04:00
|
|
|
DocUpdaterClient.sendUpdate(
|
2020-05-06 06:12:47 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.update,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
2020-05-08 12:03:54 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
DocUpdaterClient.setDocLines(
|
2020-05-06 06:12:47 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.newLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
(error, res, body) => {
|
2020-05-08 14:08:31 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
this.statusCode = res.statusCode
|
2022-09-21 08:01:32 -04:00
|
|
|
this.body = body
|
2020-05-08 12:03:54 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}, 200)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-15 14:29:49 -04:00
|
|
|
MockProjectHistoryApi.flushProject.resetHistory()
|
|
|
|
MockWebApi.setDocument.resetHistory()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2022-09-21 08:01:32 -04:00
|
|
|
it('should return a 200 status code', function () {
|
|
|
|
this.statusCode.should.equal(200)
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2022-11-03 06:20:18 -04:00
|
|
|
it('should emit two updates (from sendUpdate and setDocLines)', function () {
|
|
|
|
expect(numberOfReceivedUpdates).to.equal(2)
|
|
|
|
})
|
|
|
|
|
2020-05-06 06:12:47 -04:00
|
|
|
it('should send the updated doc lines and version to the web api', function () {
|
2020-05-08 12:03:54 -04:00
|
|
|
MockWebApi.setDocument
|
2020-05-06 06:12:47 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id, this.newLines)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should update the lines in the doc updater', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, doc) => {
|
2020-05-08 14:08:31 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
doc.lines.should.deep.equal(this.newLines)
|
2020-05-08 12:03:54 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should bump the version in the doc updater', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, doc) => {
|
2020-05-08 14:08:31 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
doc.version.should.equal(this.version + 2)
|
2020-05-08 12:03:54 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-08 12:03:54 -04:00
|
|
|
it('should leave the document in redis', function (done) {
|
2020-05-08 14:09:54 -04:00
|
|
|
docUpdaterRedis.get(
|
|
|
|
Keys.docLines({ doc_id: this.doc_id }),
|
|
|
|
(error, lines) => {
|
|
|
|
if (error) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
expect(JSON.parse(lines)).to.deep.equal(this.newLines)
|
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-08 14:09:54 -04:00
|
|
|
)
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
2022-09-21 08:01:32 -04:00
|
|
|
|
|
|
|
it('should return the mongo rev in the json response', function () {
|
|
|
|
this.body.should.deep.equal({ rev: '123' })
|
|
|
|
})
|
2022-11-03 06:20:18 -04:00
|
|
|
|
|
|
|
describe('when doc has the same contents', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
numberOfReceivedUpdates = 0
|
|
|
|
DocUpdaterClient.setDocLines(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.newLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
(error, res, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
this.statusCode = res.statusCode
|
|
|
|
this.body = body
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not bump the version in doc updater', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, doc) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
doc.version.should.equal(this.version + 2)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not emit any updates', function (done) {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(numberOfReceivedUpdates).to.equal(0)
|
|
|
|
done()
|
|
|
|
}, 100) // delay by 100ms: make sure we do not check too early!
|
|
|
|
})
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the updated doc does not exist in the doc updater', function () {
|
|
|
|
before(function (done) {
|
2020-05-08 12:01:25 -04:00
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
2022-11-03 06:20:18 -04:00
|
|
|
numberOfReceivedUpdates = 0
|
2020-05-06 06:12:47 -04:00
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 07:04:42 -04:00
|
|
|
version: this.version,
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
DocUpdaterClient.setDocLines(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.newLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
(error, res, body) => {
|
2020-05-08 14:08:31 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
this.statusCode = res.statusCode
|
2022-09-21 08:01:32 -04:00
|
|
|
this.body = body
|
2020-05-08 12:03:54 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-15 14:29:49 -04:00
|
|
|
MockProjectHistoryApi.flushProject.resetHistory()
|
|
|
|
MockWebApi.setDocument.resetHistory()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2022-09-21 08:01:32 -04:00
|
|
|
it('should return a 200 status code', function () {
|
|
|
|
this.statusCode.should.equal(200)
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2022-11-03 06:20:18 -04:00
|
|
|
it('should emit an update', function () {
|
|
|
|
expect(numberOfReceivedUpdates).to.equal(1)
|
|
|
|
})
|
|
|
|
|
2020-05-06 06:12:47 -04:00
|
|
|
it('should send the updated doc lines to the web api', function () {
|
2020-05-08 12:03:54 -04:00
|
|
|
MockWebApi.setDocument
|
2020-05-06 06:12:47 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id, this.newLines)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should flush project history', function () {
|
2020-05-08 12:03:54 -04:00
|
|
|
MockProjectHistoryApi.flushProject
|
2020-05-06 06:12:47 -04:00
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-08 12:03:54 -04:00
|
|
|
it('should remove the document from redis', function (done) {
|
2020-05-08 14:09:54 -04:00
|
|
|
docUpdaterRedis.get(
|
|
|
|
Keys.docLines({ doc_id: this.doc_id }),
|
|
|
|
(error, lines) => {
|
|
|
|
if (error) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
expect(lines).to.not.exist
|
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-08 14:09:54 -04:00
|
|
|
)
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
2022-09-21 08:01:32 -04:00
|
|
|
|
|
|
|
it('should return the mongo rev in the json response', function () {
|
|
|
|
this.body.should.deep.equal({ rev: '123' })
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-11 10:41:32 -04:00
|
|
|
const DOC_TOO_LARGE_TEST_CASES = [
|
|
|
|
{
|
|
|
|
desc: 'when the updated doc is too large for the body parser',
|
|
|
|
size: Settings.maxJsonRequestSize,
|
2021-07-13 07:04:42 -04:00
|
|
|
expectedStatusCode: 413,
|
2020-05-11 10:41:32 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'when the updated doc is larger than the HTTP controller limit',
|
|
|
|
size: Settings.max_doc_length,
|
2021-07-13 07:04:42 -04:00
|
|
|
expectedStatusCode: 406,
|
|
|
|
},
|
2020-05-11 10:41:32 -04:00
|
|
|
]
|
|
|
|
|
2021-07-13 07:04:42 -04:00
|
|
|
DOC_TOO_LARGE_TEST_CASES.forEach(testCase => {
|
2020-05-11 10:41:32 -04:00
|
|
|
describe(testCase.desc, function () {
|
|
|
|
before(function (done) {
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 07:04:42 -04:00
|
|
|
version: this.version,
|
2020-05-11 10:41:32 -04:00
|
|
|
})
|
|
|
|
this.newLines = []
|
|
|
|
while (JSON.stringify(this.newLines).length <= testCase.size) {
|
|
|
|
this.newLines.push('(a long line of text)'.repeat(10000))
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
2020-05-11 10:41:32 -04:00
|
|
|
DocUpdaterClient.setDocLines(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.newLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
(error, res, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
this.statusCode = res.statusCode
|
|
|
|
setTimeout(done, 200)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
|
2020-05-11 10:41:32 -04:00
|
|
|
after(function () {
|
2020-05-15 14:29:49 -04:00
|
|
|
MockProjectHistoryApi.flushProject.resetHistory()
|
|
|
|
MockWebApi.setDocument.resetHistory()
|
2020-05-11 10:41:32 -04:00
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
|
2020-05-11 10:41:32 -04:00
|
|
|
it(`should return a ${testCase.expectedStatusCode} status code`, function () {
|
|
|
|
this.statusCode.should.equal(testCase.expectedStatusCode)
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
|
2020-05-11 10:41:32 -04:00
|
|
|
it('should not send the updated doc lines to the web api', function () {
|
|
|
|
MockWebApi.setDocument.called.should.equal(false)
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
|
2020-05-11 10:41:32 -04:00
|
|
|
it('should not flush project history', function () {
|
|
|
|
MockProjectHistoryApi.flushProject.called.should.equal(false)
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the updated doc is large but under the bodyParser and HTTPController size limit', function () {
|
|
|
|
before(function (done) {
|
2020-05-08 12:01:25 -04:00
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
2020-05-06 06:12:47 -04:00
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 07:04:42 -04:00
|
|
|
version: this.version,
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
this.newLines = []
|
|
|
|
while (JSON.stringify(this.newLines).length < 2 * 1024 * 1024) {
|
|
|
|
// limit in HTTPController
|
|
|
|
this.newLines.push('(a long line of text)'.repeat(10000))
|
|
|
|
}
|
|
|
|
this.newLines.pop() // remove the line which took it over the limit
|
|
|
|
DocUpdaterClient.setDocLines(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.newLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
(error, res, body) => {
|
2020-05-08 14:08:31 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
this.statusCode = res.statusCode
|
2022-09-21 08:01:32 -04:00
|
|
|
this.body = body
|
2020-05-08 12:03:54 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-15 14:29:49 -04:00
|
|
|
MockProjectHistoryApi.flushProject.resetHistory()
|
|
|
|
MockWebApi.setDocument.resetHistory()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2022-09-21 08:01:32 -04:00
|
|
|
it('should return a 200 status code', function () {
|
|
|
|
this.statusCode.should.equal(200)
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-08 12:03:54 -04:00
|
|
|
it('should send the updated doc lines to the web api', function () {
|
|
|
|
MockWebApi.setDocument
|
2020-05-06 06:12:47 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id, this.newLines)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2022-09-21 08:01:32 -04:00
|
|
|
|
|
|
|
it('should return the mongo rev in the json response', function () {
|
|
|
|
this.body.should.deep.equal({ rev: '123' })
|
|
|
|
})
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-08 12:03:54 -04:00
|
|
|
describe('with track changes', function () {
|
2020-05-06 06:12:47 -04:00
|
|
|
before(function () {
|
|
|
|
this.lines = ['one', 'one and a half', 'two', 'three']
|
|
|
|
this.id_seed = '587357bd35e64f6157'
|
2020-05-08 12:03:54 -04:00
|
|
|
this.update = {
|
2020-05-06 06:12:47 -04:00
|
|
|
doc: this.doc_id,
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
d: 'one and a half\n',
|
2021-07-13 07:04:42 -04:00
|
|
|
p: 4,
|
|
|
|
},
|
2020-05-06 06:12:47 -04:00
|
|
|
],
|
|
|
|
meta: {
|
|
|
|
tc: this.id_seed,
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
2020-05-06 06:12:47 -04:00
|
|
|
},
|
2021-07-13 07:04:42 -04:00
|
|
|
v: this.version,
|
2020-05-08 12:03:54 -04:00
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the undo flag', function () {
|
|
|
|
before(function (done) {
|
2020-05-08 12:01:25 -04:00
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
2020-05-06 06:12:47 -04:00
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 07:04:42 -04:00
|
|
|
version: this.version,
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
2021-07-13 07:04:42 -04:00
|
|
|
DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
2020-05-08 12:03:54 -04:00
|
|
|
DocUpdaterClient.sendUpdate(
|
2020-05-06 06:12:47 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.update,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
// Go back to old lines, with undo flag
|
2020-05-08 12:03:54 -04:00
|
|
|
DocUpdaterClient.setDocLines(
|
2020-05-06 06:12:47 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
true,
|
|
|
|
(error, res, body) => {
|
2020-05-08 14:08:31 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
this.statusCode = res.statusCode
|
2020-05-08 12:03:54 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-15 14:29:49 -04:00
|
|
|
MockProjectHistoryApi.flushProject.resetHistory()
|
|
|
|
MockWebApi.setDocument.resetHistory()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-08 12:03:54 -04:00
|
|
|
it('should undo the tracked changes', function (done) {
|
2020-05-06 06:12:47 -04:00
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, data) => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
const { ranges } = data
|
|
|
|
expect(ranges.changes).to.be.undefined
|
2020-05-08 12:03:54 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-08 12:03:54 -04:00
|
|
|
describe('without the undo flag', function () {
|
2020-05-06 06:12:47 -04:00
|
|
|
before(function (done) {
|
2020-05-08 12:01:25 -04:00
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
2020-05-06 06:12:47 -04:00
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 07:04:42 -04:00
|
|
|
version: this.version,
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
2021-07-13 07:04:42 -04:00
|
|
|
DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, error => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
2020-05-08 12:03:54 -04:00
|
|
|
DocUpdaterClient.sendUpdate(
|
2020-05-06 06:12:47 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.update,
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
// Go back to old lines, without undo flag
|
2020-05-08 12:03:54 -04:00
|
|
|
DocUpdaterClient.setDocLines(
|
2020-05-06 06:12:47 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
(error, res, body) => {
|
2020-05-08 14:08:31 -04:00
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
2020-05-06 06:12:47 -04:00
|
|
|
this.statusCode = res.statusCode
|
2020-05-08 12:03:54 -04:00
|
|
|
setTimeout(done, 200)
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
2020-05-15 14:29:49 -04:00
|
|
|
MockProjectHistoryApi.flushProject.resetHistory()
|
|
|
|
MockWebApi.setDocument.resetHistory()
|
2020-05-06 06:12:47 -04:00
|
|
|
})
|
|
|
|
|
2020-05-08 12:03:54 -04:00
|
|
|
it('should not undo the tracked changes', function (done) {
|
2020-05-06 06:12:47 -04:00
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, data) => {
|
2020-05-08 14:06:25 -04:00
|
|
|
if (error) {
|
2020-05-06 06:12:47 -04:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
const { ranges } = data
|
|
|
|
expect(ranges.changes.length).to.equal(1)
|
2020-05-08 12:03:54 -04:00
|
|
|
done()
|
2020-05-06 06:12:47 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|