2021-05-06 17:11:52 +00:00
|
|
|
const { expect } = require('chai')
|
2021-07-12 16:47:15 +00:00
|
|
|
const Settings = require('@overleaf/settings')
|
2021-05-06 17:11:52 +00:00
|
|
|
|
|
|
|
const MockWebApi = require('./helpers/MockWebApi')
|
|
|
|
const DocUpdaterClient = require('./helpers/DocUpdaterClient')
|
|
|
|
const DocUpdaterApp = require('./helpers/DocUpdaterApp')
|
|
|
|
|
|
|
|
describe('SizeChecks', function () {
|
|
|
|
before(function (done) {
|
|
|
|
DocUpdaterApp.ensureRunning(done)
|
|
|
|
})
|
|
|
|
beforeEach(function () {
|
|
|
|
this.version = 0
|
|
|
|
this.update = {
|
|
|
|
doc: this.doc_id,
|
|
|
|
op: [
|
|
|
|
{
|
|
|
|
i: 'insert some more lines that will bring it above the limit\n',
|
2021-07-13 11:04:42 +00:00
|
|
|
p: 42,
|
|
|
|
},
|
2021-05-06 17:11:52 +00:00
|
|
|
],
|
2021-07-13 11:04:42 +00:00
|
|
|
v: this.version,
|
2021-05-06 17:11:52 +00:00
|
|
|
}
|
|
|
|
this.project_id = DocUpdaterClient.randomId()
|
|
|
|
this.doc_id = DocUpdaterClient.randomId()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when a doc is above the doc size limit already', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.lines = ['0123456789'.repeat(Settings.max_doc_length / 10 + 1)]
|
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 11:04:42 +00:00
|
|
|
v: this.version,
|
2021-05-06 17:11:52 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should error when fetching the doc', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(res.statusCode).to.equal(500)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when trying to update', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const update = {
|
|
|
|
doc: this.doc_id,
|
|
|
|
op: this.update.op,
|
2021-07-13 11:04:42 +00:00
|
|
|
v: this.version,
|
2021-05-06 17:11:52 +00:00
|
|
|
}
|
|
|
|
DocUpdaterClient.sendUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
update,
|
2021-07-13 11:04:42 +00:00
|
|
|
error => {
|
2021-05-06 17:11:52 +00:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
setTimeout(done, 200)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should still error when fetching the doc', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(this.project_id, this.doc_id, (error, res) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(res.statusCode).to.equal(500)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when a doc is just below the doc size limit', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.lines = ['0123456789'.repeat(Settings.max_doc_length / 10 - 1)]
|
|
|
|
MockWebApi.insertDoc(this.project_id, this.doc_id, {
|
|
|
|
lines: this.lines,
|
2021-07-13 11:04:42 +00:00
|
|
|
v: this.version,
|
2021-05-06 17:11:52 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should be able to fetch the doc', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, doc) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(doc.lines).to.deep.equal(this.lines)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when trying to update', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const update = {
|
|
|
|
doc: this.doc_id,
|
|
|
|
op: this.update.op,
|
2021-07-13 11:04:42 +00:00
|
|
|
v: this.version,
|
2021-05-06 17:11:52 +00:00
|
|
|
}
|
|
|
|
DocUpdaterClient.sendUpdate(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
update,
|
2021-07-13 11:04:42 +00:00
|
|
|
error => {
|
2021-05-06 17:11:52 +00:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
setTimeout(done, 200)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not update the doc', function (done) {
|
|
|
|
DocUpdaterClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
(error, res, doc) => {
|
|
|
|
if (error) return done(error)
|
|
|
|
expect(doc.lines).to.deep.equal(this.lines)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|