[misc] run format_fix and lint:fix

This commit is contained in:
Jakob Ackermann
2021-07-13 12:04:43 +01:00
parent 1e577e24b1
commit 9178394dd6
48 changed files with 1742 additions and 1718 deletions
@@ -39,20 +39,20 @@ describe('Appending doc ops to the history', function () {
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
v: 3,
},
{
op: [{ i: 'o', p: 4 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 4
v: 4,
},
{
op: [{ i: 'o', p: 5 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 5
}
v: 5,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -76,8 +76,8 @@ describe('Appending doc ops to the history', function () {
return expect(this.updates[0].pack[0].op).to.deep.equal([
{
p: 3,
i: 'foo'
}
i: 'foo',
},
])
})
@@ -121,20 +121,20 @@ describe('Appending doc ops to the history', function () {
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
v: 3,
},
{
op: [{ i: 'o', p: 4 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 4
v: 4,
},
{
op: [{ i: 'o', p: 5 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 5
}
v: 5,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -162,20 +162,20 @@ describe('Appending doc ops to the history', function () {
{
op: [{ i: 'b', p: 6 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 6
v: 6,
},
{
op: [{ i: 'a', p: 7 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 7
v: 7,
},
{
op: [{ i: 'r', p: 8 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 8
}
v: 8,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -199,8 +199,8 @@ describe('Appending doc ops to the history', function () {
return expect(this.updates[0].pack[1].op).to.deep.equal([
{
p: 6,
i: 'bar'
}
i: 'bar',
},
])
})
@@ -219,20 +219,20 @@ describe('Appending doc ops to the history', function () {
{
op: [{ i: 'b', p: 6 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 6
v: 6,
},
{
op: [{ i: 'a', p: 7 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 7
v: 7,
},
{
op: [{ i: 'r', p: 8 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 8
}
v: 8,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -256,14 +256,14 @@ describe('Appending doc ops to the history', function () {
expect(this.updates[0].pack[0].op).to.deep.equal([
{
p: 3,
i: 'foo'
}
i: 'foo',
},
])
return expect(this.updates[0].pack[1].op).to.deep.equal([
{
p: 6,
i: 'bar'
}
i: 'bar',
},
])
})
})
@@ -281,7 +281,7 @@ describe('Appending doc ops to the history', function () {
updates.push({
op: [{ i: 'a', p: 0 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: i
v: i,
})
this.expectedOp[0].i = `a${this.expectedOp[0].i}`
}
@@ -290,7 +290,7 @@ describe('Appending doc ops to the history', function () {
this.project_id,
this.doc_id,
updates,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -334,22 +334,22 @@ describe('Appending doc ops to the history', function () {
op: [
{ i: 'f', p: 3 },
{ i: 'o', p: 4 },
{ i: 'o', p: 5 }
{ i: 'o', p: 5 },
],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
v: 3,
},
{
op: [
{ i: 'b', p: 6 },
{ i: 'a', p: 7 },
{ i: 'r', p: 8 }
{ i: 'r', p: 8 },
],
meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 4
}
v: 4,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -373,14 +373,14 @@ describe('Appending doc ops to the history', function () {
expect(this.updates[0].pack[0].op).to.deep.equal([
{
p: 3,
i: 'foo'
}
i: 'foo',
},
])
return expect(this.updates[0].pack[1].op).to.deep.equal([
{
p: 6,
i: 'bar'
}
i: 'bar',
},
])
})
@@ -404,15 +404,15 @@ describe('Appending doc ops to the history', function () {
{
op: [],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
v: 3,
},
{
op: [{ i: 'foo', p: 3 }],
meta: { ts: Date.now() + oneDay, user_id: this.user_id },
v: 4
}
v: 4,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -440,8 +440,8 @@ describe('Appending doc ops to the history', function () {
return expect(this.updates[0].pack[1].op).to.deep.equal([
{
p: 3,
i: 'foo'
}
i: 'foo',
},
])
})
@@ -464,13 +464,13 @@ describe('Appending doc ops to the history', function () {
{
op: [
{ c: 'foo', p: 3 },
{ d: 'bar', p: 6 }
{ d: 'bar', p: 6 },
],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
}
v: 3,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -492,7 +492,7 @@ describe('Appending doc ops to the history', function () {
it('should ignore the comment op', function () {
return expect(this.updates[0].pack[0].op).to.deep.equal([
{ d: 'bar', p: 6 }
{ d: 'bar', p: 6 },
])
})
@@ -515,10 +515,10 @@ describe('Appending doc ops to the history', function () {
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
}
v: 3,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -557,10 +557,10 @@ describe('Appending doc ops to the history', function () {
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
}
v: 3,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
@@ -32,9 +32,9 @@ describe('Archiving updates', function () {
__guard__(
__guard__(
Settings != null ? Settings.trackchanges : undefined,
(x1) => x1.s3
x1 => x1.s3
),
(x) => x.key.length
x => x.key.length
) < 1
) {
const message = new Error('s3 keys not setup, this test setup will fail')
@@ -57,8 +57,8 @@ describe('Archiving updates', function () {
MockWebApi.projects[this.project_id] = {
features: {
versioning: true
}
versioning: true,
},
}
sinon.spy(MockWebApi, 'getProjectDetails')
@@ -66,13 +66,13 @@ describe('Archiving updates', function () {
email: 'user@sharelatex.com',
first_name: 'Leo',
last_name: 'Lion',
id: this.user_id
id: this.user_id,
}
sinon.spy(MockWebApi, 'getUserInfo')
MockDocStoreApi.docs[this.doc_id] = this.doc = {
_id: this.doc_id,
project_id: this.project_id
project_id: this.project_id,
}
sinon.spy(MockDocStoreApi, 'getAllDoc')
@@ -85,15 +85,15 @@ describe('Archiving updates', function () {
this.updates.push({
op: [{ i: 'a', p: 0 }],
meta: { ts: this.now + (i - 2048) * this.hours, user_id: this.user_id },
v: 2 * i + 1
v: 2 * i + 1,
})
this.updates.push({
op: [{ i: 'b', p: 0 }],
meta: {
ts: this.now + (i - 2048) * this.hours + 10 * this.minutes,
user_id: this.user_id_2
user_id: this.user_id_2,
},
v: 2 * i + 2
v: 2 * i + 2,
})
}
TrackChangesApp.ensureRunning(() => {
@@ -101,14 +101,14 @@ describe('Archiving updates', function () {
this.project_id,
this.doc_id,
this.updates,
(error) => {
error => {
if (error != null) {
throw error
}
return TrackChangesClient.flushDoc(
this.project_id,
this.doc_id,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -163,7 +163,7 @@ describe('Archiving updates', function () {
const expectedExportedUpdates = this.updates
.slice()
.reverse()
.map((update) => {
.map(update => {
// clone object, updates are created once in before handler
const exportedUpdate = Object.assign({}, update)
exportedUpdate.meta = Object.assign({}, update.meta)
@@ -180,7 +180,7 @@ describe('Archiving updates', function () {
expect(this.exportedUpdates).to.deep.equal(expectedExportedUpdates)
expect(this.exportedUserIds).to.deep.equal([
this.user_id,
this.user_id_2
this.user_id_2,
])
})
})
@@ -192,16 +192,12 @@ describe('Archiving updates', function () {
describe("archiving a doc's updates", function () {
before(function (done) {
TrackChangesClient.pushDocHistory(
this.project_id,
this.doc_id,
(error) => {
if (error != null) {
throw error
}
return done()
TrackChangesClient.pushDocHistory(this.project_id, this.doc_id, error => {
if (error != null) {
throw error
}
)
return done()
})
return null
})
@@ -222,7 +218,7 @@ describe('Archiving updates', function () {
return db.docHistory.deleteMany(
{
doc_id: ObjectId(this.doc_id),
expiresAt: { $exists: true }
expiresAt: { $exists: true },
},
(err, result) => {
if (typeof error !== 'undefined' && error !== null) {
@@ -295,16 +291,12 @@ describe('Archiving updates', function () {
return describe("unarchiving a doc's updates", function () {
before(function (done) {
TrackChangesClient.pullDocHistory(
this.project_id,
this.doc_id,
(error) => {
if (error != null) {
throw error
}
return done()
TrackChangesClient.pullDocHistory(this.project_id, this.doc_id, error => {
if (error != null) {
throw error
}
)
return done()
})
return null
})
@@ -40,17 +40,17 @@ describe('Flushing updates', function () {
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
}
v: 3,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
return TrackChangesClient.flushDoc(
this.project_id,
this.doc_id,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -67,8 +67,8 @@ describe('Flushing updates', function () {
expect(updates[0].pack[0].op).to.deep.equal([
{
p: 3,
i: 'f'
}
i: 'f',
},
])
return done()
})
@@ -87,8 +87,8 @@ describe('Flushing updates', function () {
MockWebApi.projects[this.project_id] = {
features: {
versioning: true
}
versioning: true,
},
}
TrackChangesClient.pushRawUpdates(
@@ -98,19 +98,19 @@ describe('Flushing updates', function () {
{
op: [{ i: 'g', p: 2 }],
meta: { ts: Date.now() - 2 * this.weeks, user_id: this.user_id },
v: 2
v: 2,
},
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
}
v: 3,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
return TrackChangesClient.flushProject(this.project_id, (error) => {
return TrackChangesClient.flushProject(this.project_id, error => {
if (error != null) {
throw error
}
@@ -154,8 +154,8 @@ describe('Flushing updates', function () {
MockWebApi.projects[this.project_id] = {
features: {
versioning: false
}
versioning: false,
},
}
TrackChangesClient.pushRawUpdates(
@@ -165,19 +165,19 @@ describe('Flushing updates', function () {
{
op: [{ i: 'g', p: 2 }],
meta: { ts: Date.now() - 2 * this.weeks, user_id: this.user_id },
v: 2
v: 2,
},
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
}
v: 3,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
return TrackChangesClient.flushProject(this.project_id, (error) => {
return TrackChangesClient.flushProject(this.project_id, error => {
if (error != null) {
throw error
}
@@ -210,13 +210,13 @@ describe('Flushing updates', function () {
MockWebApi.projects[this.project_id] = {
features: {
versioning: false
}
versioning: false,
},
}
TrackChangesClient.setPreserveHistoryForProject(
this.project_id,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -228,23 +228,23 @@ describe('Flushing updates', function () {
op: [{ i: 'g', p: 2 }],
meta: {
ts: Date.now() - 2 * this.weeks,
user_id: this.user_id
user_id: this.user_id,
},
v: 2
v: 2,
},
{
op: [{ i: 'f', p: 3 }],
meta: { ts: Date.now(), user_id: this.user_id },
v: 3
}
v: 3,
},
],
(error) => {
error => {
if (error != null) {
throw error
}
return TrackChangesClient.flushProject(
this.project_id,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -35,7 +35,7 @@ describe('Getting a diff', function () {
email: 'user@sharelatex.com',
first_name: 'Leo',
last_name: 'Lion',
id: this.user_id
id: this.user_id,
}
sinon.spy(MockWebApi, 'getUserInfo')
@@ -45,23 +45,23 @@ describe('Getting a diff', function () {
{
op: [{ i: 'one ', p: 0 }],
meta: { ts: this.from - twoMinutes, user_id: this.user_id },
v: 3
v: 3,
},
{
op: [{ i: 'two ', p: 4 }],
meta: { ts: this.from + twoMinutes, user_id: this.user_id },
v: (this.fromVersion = 4)
v: (this.fromVersion = 4),
},
{
op: [{ i: 'three ', p: 8 }],
meta: { ts: this.to - twoMinutes, user_id: this.user_id },
v: (this.toVersion = 5)
v: (this.toVersion = 5),
},
{
op: [{ i: 'four', p: 14 }],
meta: { ts: this.to + twoMinutes, user_id: this.user_id },
v: 6
}
v: 6,
},
]
this.lines = ['one two three four']
this.expected_diff = [
@@ -71,21 +71,21 @@ describe('Getting a diff', function () {
meta: {
start_ts: this.from + twoMinutes,
end_ts: this.to - twoMinutes,
user: this.user
}
}
user: this.user,
},
},
]
MockDocUpdaterApi.docs[this.doc_id] = {
lines: this.lines,
version: 7
version: 7,
}
TrackChangesApp.ensureRunning(() => {
return TrackChangesClient.pushRawUpdates(
this.project_id,
this.doc_id,
this.updates,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -33,15 +33,15 @@ describe('Getting updates', function () {
MockWebApi.projects[this.project_id] = {
features: {
versioning: true
}
versioning: true,
},
}
MockWebApi.users[this.user_id] = this.user = {
email: 'user@sharelatex.com',
first_name: 'Leo',
last_name: 'Lion',
id: this.user_id
id: this.user_id,
}
sinon.spy(MockWebApi, 'getUserInfo')
@@ -51,14 +51,14 @@ describe('Getting updates', function () {
op: [{ i: 'a', p: 0 }],
meta: {
ts: this.now - (9 - i) * this.hours - 2 * this.minutes,
user_id: this.user_id
user_id: this.user_id,
},
v: 2 * i + 1
v: 2 * i + 1,
})
this.updates.push({
op: [{ i: 'b', p: 0 }],
meta: { ts: this.now - (9 - i) * this.hours, user_id: this.user_id },
v: 2 * i + 2
v: 2 * i + 2,
})
}
this.updates[0].meta.user_id = this.deleted_user_id
@@ -68,7 +68,7 @@ describe('Getting updates', function () {
this.project_id,
this.doc_id,
this.updates,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -82,7 +82,7 @@ describe('Getting updates', function () {
after() {
MockWebApi.getUserInfo.restore()
return null
}
},
})
describe('getting updates up to the limit', function () {
@@ -118,25 +118,25 @@ describe('Getting updates', function () {
meta: {
start_ts: this.to - 2 * this.minutes,
end_ts: this.to,
users: [this.user]
}
users: [this.user],
},
},
{
docs: docs2,
meta: {
start_ts: this.to - 1 * this.hours - 2 * this.minutes,
end_ts: this.to - 1 * this.hours,
users: [this.user]
}
users: [this.user],
},
},
{
docs: docs3,
meta: {
start_ts: this.to - 2 * this.hours - 2 * this.minutes,
end_ts: this.to - 2 * this.hours,
users: [this.user]
}
}
users: [this.user],
},
},
])
})
})
@@ -168,17 +168,17 @@ describe('Getting updates', function () {
meta: {
start_ts: this.to - 8 * this.hours - 2 * this.minutes,
end_ts: this.to - 8 * this.hours,
users: [this.user]
}
users: [this.user],
},
},
{
docs: docs2,
meta: {
start_ts: this.to - 9 * this.hours - 2 * this.minutes,
end_ts: this.to - 9 * this.hours,
users: [this.user, null]
}
}
users: [this.user, null],
},
},
])
})
})
@@ -27,24 +27,24 @@ describe('Locking document', function () {
LockManager.LOCK_TTL = 1 // second
LockManager.runWithLock(
'doc123',
(releaseA) => {
releaseA => {
// we create a lock A and allow it to expire in redis
return setTimeout(
() =>
// now we create a new lock B and try to release A
LockManager.runWithLock(
'doc123',
(releaseB) => {
releaseB => {
return releaseA()
}, // try to release lock A to see if it wipes out lock B
(error) => {}
error => {}
),
// we never release lock B so nothing should happen here
1500
)
}, // enough time to wait until the lock has expired
(error) =>
error =>
// we get here after trying to release lock A
done()
)
@@ -35,23 +35,23 @@ describe('Restoring a version', function () {
{
op: [{ i: 'one ', p: 0 }],
meta: { ts: this.now - 6 * minutes, user_id: this.user_id },
v: 3
v: 3,
},
{
op: [{ i: 'two ', p: 4 }],
meta: { ts: this.now - 4 * minutes, user_id: this.user_id },
v: 4
v: 4,
},
{
op: [{ i: 'three ', p: 8 }],
meta: { ts: this.now - 2 * minutes, user_id: this.user_id },
v: 5
v: 5,
},
{
op: [{ i: 'four', p: 14 }],
meta: { ts: this.now, user_id: this.user_id },
v: 6
}
v: 6,
},
]
this.lines = ['one two three four']
this.restored_lines = ['one two ']
@@ -61,12 +61,12 @@ describe('Restoring a version', function () {
email: 'user@sharelatex.com',
first_name: 'Leo',
last_name: 'Lion',
id: this.user_id
id: this.user_id,
}
MockDocUpdaterApi.docs[this.doc_id] = {
lines: this.lines,
version: 7
version: 7,
}
TrackChangesApp.ensureRunning(() => {
@@ -74,7 +74,7 @@ describe('Restoring a version', function () {
this.project_id,
this.doc_id,
this.updates,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -83,7 +83,7 @@ describe('Restoring a version', function () {
this.doc_id,
this.beforeVersion,
this.user_id,
(error) => {
error => {
if (error != null) {
throw error
}
@@ -39,16 +39,16 @@ module.exports = MockDocUpdaterApi = {
})
return app
.listen(3016, (error) => {
.listen(3016, error => {
if (error != null) {
throw error
}
})
.on('error', (error) => {
.on('error', error => {
console.error('error starting MockDocStoreApi:', error.message)
return process.exit(1)
})
}
},
}
MockDocUpdaterApi.run()
@@ -74,16 +74,16 @@ module.exports = MockDocUpdaterApi = {
})
return app
.listen(3003, (error) => {
.listen(3003, error => {
if (error != null) {
throw error
}
})
.on('error', (error) => {
.on('error', error => {
console.error('error starting MockDocUpdaterApi:', error.message)
return process.exit(1)
})
}
},
}
MockDocUpdaterApi.run()
@@ -61,16 +61,16 @@ module.exports = MockWebApi = {
})
return app
.listen(3000, (error) => {
.listen(3000, error => {
if (error != null) {
throw error
}
})
.on('error', (error) => {
.on('error', error => {
console.error('error starting MockWebApiServer:', error.message)
return process.exit(1)
})
}
},
}
MockWebApi.run()
@@ -38,10 +38,10 @@ module.exports = {
Settings.internal != null
? Settings.internal.trackchanges
: undefined,
(x) => x.port
x => x.port
),
'localhost',
(error) => {
error => {
if (error != null) {
throw error
}
@@ -58,7 +58,7 @@ module.exports = {
}
)
})
}
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
@@ -28,7 +28,7 @@ const s3 = new aws.S3({
accessKeyId: Settings.trackchanges.s3.key,
secretAccessKey: Settings.trackchanges.s3.secret,
endpoint: Settings.trackchanges.s3.endpoint,
s3ForcePathStyle: Settings.trackchanges.s3.pathStyle
s3ForcePathStyle: Settings.trackchanges.s3.pathStyle,
})
const S3_BUCKET = Settings.trackchanges.stores.doc_history
@@ -37,7 +37,7 @@ module.exports = TrackChangesClient = {
if (callback == null) {
callback = function (error, updates) {}
}
return TrackChangesClient.flushDoc(project_id, doc_id, (error) => {
return TrackChangesClient.flushDoc(project_id, doc_id, error => {
if (error != null) {
return callback(error)
}
@@ -51,7 +51,7 @@ module.exports = TrackChangesClient = {
}
return request.post(
{
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/flush`
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/flush`,
},
(error, response, body) => {
response.statusCode.should.equal(204)
@@ -66,7 +66,7 @@ module.exports = TrackChangesClient = {
}
return request.post(
{
url: `http://localhost:3015/project/${project_id}/flush`
url: `http://localhost:3015/project/${project_id}/flush`,
},
(error, response, body) => {
response.statusCode.should.equal(204)
@@ -91,7 +91,7 @@ module.exports = TrackChangesClient = {
}
return db.projectHistoryMetaData.findOne(
{
project_id: ObjectId(project_id)
project_id: ObjectId(project_id),
},
callback
)
@@ -103,13 +103,13 @@ module.exports = TrackChangesClient = {
}
return db.projectHistoryMetaData.updateOne(
{
project_id: ObjectId(project_id)
project_id: ObjectId(project_id),
},
{
$set: { preserveHistory: true }
$set: { preserveHistory: true },
},
{
upsert: true
upsert: true,
},
callback
)
@@ -122,13 +122,13 @@ module.exports = TrackChangesClient = {
return rclient.sadd(
Keys.docsWithHistoryOps({ project_id }),
doc_id,
(error) => {
error => {
if (error != null) {
return callback(error)
}
return rclient.rpush(
Keys.uncompressedHistoryOps({ doc_id }),
...Array.from(Array.from(updates).map((u) => JSON.stringify(u))),
...Array.from(Array.from(updates).map(u => JSON.stringify(u))),
callback
)
}
@@ -141,7 +141,7 @@ module.exports = TrackChangesClient = {
}
return request.get(
{
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/diff?from=${from}&to=${to}`
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/diff?from=${from}&to=${to}`,
},
(error, response, body) => {
response.statusCode.should.equal(200)
@@ -156,7 +156,7 @@ module.exports = TrackChangesClient = {
}
return request.get(
{
url: `http://localhost:3015/project/${project_id}/updates?before=${options.before}&min_count=${options.min_count}`
url: `http://localhost:3015/project/${project_id}/updates?before=${options.before}&min_count=${options.min_count}`,
},
(error, response, body) => {
response.statusCode.should.equal(200)
@@ -184,8 +184,8 @@ module.exports = TrackChangesClient = {
{
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/version/${version}/restore`,
headers: {
'X-User-Id': user_id
}
'X-User-Id': user_id,
},
},
(error, response, body) => {
response.statusCode.should.equal(204)
@@ -200,7 +200,7 @@ module.exports = TrackChangesClient = {
}
return request.post(
{
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/push`
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/push`,
},
(error, response, body) => {
response.statusCode.should.equal(204)
@@ -215,7 +215,7 @@ module.exports = TrackChangesClient = {
}
return request.post(
{
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/pull`
url: `http://localhost:3015/project/${project_id}/doc/${doc_id}/pull`,
},
(error, response, body) => {
response.statusCode.should.equal(204)
@@ -254,7 +254,7 @@ module.exports = TrackChangesClient = {
}
const params = {
Bucket: S3_BUCKET,
Key: `${project_id}/changes-${doc_id}/pack-${pack_id}`
Key: `${project_id}/changes-${doc_id}/pack-${pack_id}`,
}
return s3.getObject(params, (error, data) => {
@@ -280,7 +280,7 @@ module.exports = TrackChangesClient = {
}
let params = {
Bucket: S3_BUCKET,
Prefix: `${project_id}/changes-${doc_id}`
Prefix: `${project_id}/changes-${doc_id}`,
}
return s3.listObjects(params, (error, data) => {
@@ -291,11 +291,11 @@ module.exports = TrackChangesClient = {
params = {
Bucket: S3_BUCKET,
Delete: {
Objects: data.Contents.map((s3object) => ({ Key: s3object.Key }))
}
Objects: data.Contents.map(s3object => ({ Key: s3object.Key })),
},
}
return s3.deleteObjects(params, callback)
})
}
},
}
+3 -3
View File
@@ -14,8 +14,8 @@ SandboxedModule.configure({
warn() {},
err() {},
error() {},
fatal() {}
}
fatal() {},
},
},
globals: { Buffer, JSON, console, process }
globals: { Buffer, JSON, console, process },
})
@@ -24,7 +24,7 @@ describe('DiffGenerator', function () {
return (this.meta = {
start_ts: this.ts,
end_ts: this.ts,
user_id: this.user_id
user_id: this.user_id,
})
})
@@ -34,7 +34,7 @@ describe('DiffGenerator', function () {
const content = 'hello world'
const rewoundContent = this.DiffGenerator.rewindOp(content, {
p: 6,
i: 'wo'
i: 'wo',
})
return rewoundContent.should.equal('hello rld')
})
@@ -45,7 +45,7 @@ describe('DiffGenerator', function () {
const content = 'hello rld'
const rewoundContent = this.DiffGenerator.rewindOp(content, {
p: 6,
d: 'wo'
d: 'wo',
})
return rewoundContent.should.equal('hello world')
})
@@ -65,7 +65,7 @@ describe('DiffGenerator', function () {
const content = 'foobar'
const rewoundContent = this.DiffGenerator.rewindOp(content, {
p: 4,
i: 'bar'
i: 'bar',
})
return rewoundContent.should.equal('foo')
})
@@ -78,8 +78,8 @@ describe('DiffGenerator', function () {
const update = {
op: [
{ p: 3, i: 'bbb' },
{ p: 6, i: 'ccc' }
]
{ p: 6, i: 'ccc' },
],
}
const rewoundContent = this.DiffGenerator.rewindUpdate(content, update)
return rewoundContent.should.equal('aaa')
@@ -91,7 +91,7 @@ describe('DiffGenerator', function () {
const content = 'aaabbbccc'
const updates = [
{ op: [{ p: 3, i: 'bbb' }] },
{ op: [{ p: 6, i: 'ccc' }] }
{ op: [{ p: 6, i: 'ccc' }] },
]
const rewoundContent = this.DiffGenerator.rewindUpdates(content, updates)
return rewoundContent.should.equal('aaa')
@@ -105,7 +105,7 @@ describe('DiffGenerator', function () {
this.updates = [
{ i: 'mock-update-1' },
{ i: 'mock-update-2' },
{ i: 'mock-update-3' }
{ i: 'mock-update-3' },
]
this.DiffGenerator.applyUpdateToDiff = sinon.stub().returns(this.diff)
this.DiffGenerator.compressDiff = sinon.stub().returns(this.diff)
@@ -124,8 +124,8 @@ describe('DiffGenerator', function () {
.calledWith(
[
{
u: this.content
}
u: this.content,
},
],
this.updates[0]
)
@@ -133,7 +133,7 @@ describe('DiffGenerator', function () {
})
it('should apply each update', function () {
return Array.from(this.updates).map((update) =>
return Array.from(this.updates).map(update =>
this.DiffGenerator.applyUpdateToDiff
.calledWith(sinon.match.any, update)
.should.equal(true)
@@ -153,18 +153,18 @@ describe('DiffGenerator', function () {
const diff = this.DiffGenerator.compressDiff([
{
i: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } }
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
},
{
i: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } }
}
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } },
},
])
return expect(diff).to.deep.equal([
{
i: 'foobar',
meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } }
}
meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } },
},
])
})
})
@@ -174,12 +174,12 @@ describe('DiffGenerator', function () {
const input = [
{
i: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } }
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
},
{
i: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } }
}
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } },
},
]
const output = this.DiffGenerator.compressDiff(input)
return expect(output).to.deep.equal(input)
@@ -191,18 +191,18 @@ describe('DiffGenerator', function () {
const diff = this.DiffGenerator.compressDiff([
{
d: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } }
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
},
{
d: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } }
}
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id } },
},
])
return expect(diff).to.deep.equal([
{
d: 'foobar',
meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } }
}
meta: { start_ts: 5, end_ts: 20, user: { id: this.user_id } },
},
])
})
})
@@ -212,12 +212,12 @@ describe('DiffGenerator', function () {
const input = [
{
d: 'foo',
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } }
meta: { start_ts: 10, end_ts: 20, user: { id: this.user_id } },
},
{
d: 'bar',
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } }
}
meta: { start_ts: 5, end_ts: 15, user: { id: this.user_id_2 } },
},
]
const output = this.DiffGenerator.compressDiff(input)
return expect(output).to.deep.equal(input)
@@ -230,34 +230,34 @@ describe('DiffGenerator', function () {
it('should insert into the middle of (u)nchanged text', function () {
const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
op: [{ p: 3, i: 'baz' }],
meta: this.meta
meta: this.meta,
})
return expect(diff).to.deep.equal([
{ u: 'foo' },
{ i: 'baz', meta: this.meta },
{ u: 'bar' }
{ u: 'bar' },
])
})
it('should insert into the start of (u)changed text', function () {
const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
op: [{ p: 0, i: 'baz' }],
meta: this.meta
meta: this.meta,
})
return expect(diff).to.deep.equal([
{ i: 'baz', meta: this.meta },
{ u: 'foobar' }
{ u: 'foobar' },
])
})
it('should insert into the end of (u)changed text', function () {
const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
op: [{ p: 6, i: 'baz' }],
meta: this.meta
meta: this.meta,
})
return expect(diff).to.deep.equal([
{ u: 'foobar' },
{ i: 'baz', meta: this.meta }
{ i: 'baz', meta: this.meta },
])
})
@@ -269,7 +269,7 @@ describe('DiffGenerator', function () {
return expect(diff).to.deep.equal([
{ i: 'foo', meta: this.meta },
{ i: 'baz', meta: this.meta },
{ i: 'bar', meta: this.meta }
{ i: 'bar', meta: this.meta },
])
})
@@ -282,7 +282,7 @@ describe('DiffGenerator', function () {
{ d: 'deleted', meta: this.meta },
{ u: 'foo' },
{ i: 'baz', meta: this.meta },
{ u: 'bar' }
{ u: 'bar' },
])
})
})
@@ -297,7 +297,7 @@ describe('DiffGenerator', function () {
return expect(diff).to.deep.equal([
{ u: 'foo' },
{ d: 'baz', meta: this.meta },
{ u: 'bar' }
{ u: 'bar' },
])
})
@@ -308,7 +308,7 @@ describe('DiffGenerator', function () {
)
return expect(diff).to.deep.equal([
{ d: 'foo', meta: this.meta },
{ u: 'bazbar' }
{ u: 'bazbar' },
])
})
@@ -319,7 +319,7 @@ describe('DiffGenerator', function () {
)
return expect(diff).to.deep.equal([
{ u: 'foobaz' },
{ d: 'bar', meta: this.meta }
{ d: 'bar', meta: this.meta },
])
})
@@ -333,7 +333,7 @@ describe('DiffGenerator', function () {
{ d: 'o', meta: this.meta },
{ d: 'baz', meta: this.meta },
{ d: 'b', meta: this.meta },
{ u: 'ar' }
{ u: 'ar' },
])
})
})
@@ -346,7 +346,7 @@ describe('DiffGenerator', function () {
)
return expect(diff).to.deep.equal([
{ i: 'foo', meta: this.meta },
{ i: 'bar', meta: this.meta }
{ i: 'bar', meta: this.meta },
])
})
@@ -375,7 +375,7 @@ describe('DiffGenerator', function () {
{ u: 'fo' },
{ d: 'o', meta: this.meta },
{ d: 'b', meta: this.meta },
{ u: 'ar' }
{ u: 'ar' },
])
})
})
@@ -391,7 +391,7 @@ describe('DiffGenerator', function () {
{ d: 'o', meta: this.meta },
{ d: 'baz', meta: this.meta },
{ d: 'b', meta: this.meta },
{ u: 'ar' }
{ u: 'ar' },
])
})
})
@@ -401,7 +401,7 @@ describe('DiffGenerator', function () {
return expect(() =>
this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
op: [{ p: 3, d: 'xxx' }],
meta: this.meta
meta: this.meta,
})
).to.throw(this.DiffGenerator.ConsistencyError)
})
@@ -410,7 +410,7 @@ describe('DiffGenerator', function () {
return expect(() =>
this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
op: [{ p: 0, d: 'xxx' }],
meta: this.meta
meta: this.meta,
})
).to.throw(this.DiffGenerator.ConsistencyError)
})
@@ -419,7 +419,7 @@ describe('DiffGenerator', function () {
return expect(() =>
this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
op: [{ p: 6, d: 'xxx' }],
meta: this.meta
meta: this.meta,
})
).to.throw(this.DiffGenerator.ConsistencyError)
})
@@ -434,7 +434,7 @@ describe('DiffGenerator', function () {
return expect(diff).to.deep.equal([
{ u: 'foo' },
{ i: 'baz', meta: this.meta },
{ d: 'bar', meta: this.meta }
{ d: 'bar', meta: this.meta },
])
})
})
@@ -447,7 +447,7 @@ describe('DiffGenerator', function () {
)
return expect(diff).to.deep.equal([
{ d: 'bar', meta: this.meta },
{ i: 'baz', meta: this.meta }
{ i: 'baz', meta: this.meta },
])
})
})
@@ -21,8 +21,8 @@ describe('DiffManager', function () {
requires: {
'./UpdatesManager': (this.UpdatesManager = {}),
'./DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
'./DiffGenerator': (this.DiffGenerator = {})
}
'./DiffGenerator': (this.DiffGenerator = {}),
},
})
this.callback = sinon.stub()
this.from = new Date()
@@ -114,23 +114,23 @@ describe('DiffManager', function () {
{
op: 'mock-4',
v: 42,
meta: { start_ts: new Date(this.to.getTime() + 20) }
meta: { start_ts: new Date(this.to.getTime() + 20) },
},
{
op: 'mock-3',
v: 41,
meta: { start_ts: new Date(this.to.getTime() + 10) }
meta: { start_ts: new Date(this.to.getTime() + 10) },
},
{
op: 'mock-2',
v: 40,
meta: { start_ts: new Date(this.to.getTime() - 10) }
meta: { start_ts: new Date(this.to.getTime() - 10) },
},
{
op: 'mock-1',
v: 39,
meta: { start_ts: new Date(this.to.getTime() - 20) }
}
meta: { start_ts: new Date(this.to.getTime() - 20) },
},
]
this.fromVersion = 39
this.toVersion = 40
@@ -333,23 +333,23 @@ describe('DiffManager', function () {
{
op: 'mock-4',
v: 42,
meta: { start_ts: new Date(this.to.getTime() + 20) }
meta: { start_ts: new Date(this.to.getTime() + 20) },
},
{
op: 'mock-3',
v: 41,
meta: { start_ts: new Date(this.to.getTime() + 10) }
meta: { start_ts: new Date(this.to.getTime() + 10) },
},
{
op: 'mock-2',
v: 40,
meta: { start_ts: new Date(this.to.getTime() - 10) }
meta: { start_ts: new Date(this.to.getTime() - 10) },
},
{
op: 'mock-1',
v: 39,
meta: { start_ts: new Date(this.to.getTime() - 20) }
}
meta: { start_ts: new Date(this.to.getTime() - 20) },
},
]
this.fromVersion = 39
this.rewound_content = 'rewound-content'
@@ -400,7 +400,7 @@ describe('DiffManager', function () {
this.version = 50
this.updates = [
{ op: 'mock-1', v: 40 },
{ op: 'mock-1', v: 39 }
{ op: 'mock-1', v: 39 },
]
this.DiffManager.getLatestDocAndUpdates = sinon
.stub()
@@ -25,12 +25,12 @@ describe('MongoAWS', function () {
trackchanges: {
s3: {
secret: 's3-secret',
key: 's3-key'
key: 's3-key',
},
stores: {
doc_history: 's3-bucket'
}
}
doc_history: 's3-bucket',
},
},
}),
child_process: (this.child_process = {}),
'mongo-uri': (this.mongouri = {}),
@@ -40,8 +40,8 @@ describe('MongoAWS', function () {
'./mongodb': { db: (this.db = {}), ObjectId },
JSONStream: (this.JSONStream = {}),
'readline-stream': (this.readline = sinon.stub()),
'@overleaf/metrics': { inc() {} }
}
'@overleaf/metrics': { inc() {} },
},
})
this.project_id = ObjectId().toString()
@@ -20,9 +20,9 @@ describe('DocumentUpdaterManager', function () {
requires: {
request: (this.request = {}),
'@overleaf/settings': (this.settings = {
apis: { documentupdater: { url: 'http://example.com' } }
})
}
apis: { documentupdater: { url: 'http://example.com' } },
}),
},
})
this.callback = sinon.stub()
this.lines = ['one', 'two', 'three']
@@ -35,7 +35,7 @@ describe('DocumentUpdaterManager', function () {
this.body = JSON.stringify({
lines: this.lines,
version: this.version,
ops: []
ops: [],
})
this.request.get = sinon
.stub()
@@ -135,8 +135,8 @@ describe('DocumentUpdaterManager', function () {
lines: this.content.split('\n'),
source: 'restore',
user_id: this.user_id,
undoing: true
}
undoing: true,
},
})
.should.equal(true)
})
@@ -24,8 +24,8 @@ describe('HttpController', function () {
'./RestoreManager': (this.RestoreManager = {}),
'./PackManager': (this.PackManager = {}),
'./DocArchiveManager': (this.DocArchiveManager = {}),
'./HealthChecker': (this.HealthChecker = {})
}
'./HealthChecker': (this.HealthChecker = {}),
},
})
this.doc_id = 'doc-id-123'
this.project_id = 'project-id-123'
@@ -39,8 +39,8 @@ describe('HttpController', function () {
this.req = {
params: {
doc_id: this.doc_id,
project_id: this.project_id
}
project_id: this.project_id,
},
}
this.res = { sendStatus: sinon.stub() }
this.UpdatesManager.processUncompressedUpdatesWithLock = sinon
@@ -64,8 +64,8 @@ describe('HttpController', function () {
beforeEach(function () {
this.req = {
params: {
project_id: this.project_id
}
project_id: this.project_id,
},
}
this.res = { sendStatus: sinon.stub() }
this.UpdatesManager.processUncompressedUpdatesForProject = sinon
@@ -92,12 +92,12 @@ describe('HttpController', function () {
this.req = {
params: {
doc_id: this.doc_id,
project_id: this.project_id
project_id: this.project_id,
},
query: {
from: this.from.toString(),
to: this.to.toString()
}
to: this.to.toString(),
},
}
this.res = { json: sinon.stub() }
this.diff = [{ u: 'mock-diff' }]
@@ -128,12 +128,12 @@ describe('HttpController', function () {
this.min_count = 10
this.req = {
params: {
project_id: this.project_id
project_id: this.project_id,
},
query: {
before: this.before.toString(),
min_count: this.min_count.toString()
}
min_count: this.min_count.toString(),
},
}
this.res = { json: sinon.stub() }
this.updates = ['mock-summarized-updates']
@@ -147,7 +147,7 @@ describe('HttpController', function () {
return this.UpdatesManager.getSummarizedProjectUpdates
.calledWith(this.project_id, {
before: this.before,
min_count: this.min_count
min_count: this.min_count,
})
.should.equal(true)
})
@@ -156,7 +156,7 @@ describe('HttpController', function () {
return this.res.json
.calledWith({
updates: this.updates,
nextBeforeTimestamp: this.nextBeforeTimestamp
nextBeforeTimestamp: this.nextBeforeTimestamp,
})
.should.equal(true)
})
@@ -169,11 +169,11 @@ describe('HttpController', function () {
params: {
doc_id: this.doc_id,
project_id: this.project_id,
version: this.version
version: this.version,
},
headers: {
'x-user-id': this.user_id
}
'x-user-id': this.user_id,
},
}
this.res = { sendStatus: sinon.stub() }
@@ -24,18 +24,18 @@ describe('LockManager', function () {
beforeEach(function () {
this.Settings = {
redis: {
lock: {}
}
lock: {},
},
}
this.LockManager = SandboxedModule.require(modulePath, {
requires: {
'@overleaf/redis-wrapper': {
createClient: () => {
return (this.rclient = { auth: sinon.stub() })
}
},
},
'@overleaf/settings': this.Settings
}
'@overleaf/settings': this.Settings,
},
})
this.key = 'lock-key'
@@ -240,7 +240,7 @@ describe('LockManager', function () {
describe('when the runner function returns an error', function () {
beforeEach(function () {
this.error = new Error('oops')
this.runner = (releaseLock) => {
this.runner = releaseLock => {
if (releaseLock == null) {
releaseLock = function (error) {}
}
@@ -24,8 +24,8 @@ describe('MongoManager', function () {
requires: {
'./mongodb': { db: (this.db = {}), ObjectId },
'./PackManager': (this.PackManager = {}),
'@overleaf/metrics': { timeAsyncMethod() {} }
}
'@overleaf/metrics': { timeAsyncMethod() {} },
},
})
this.callback = sinon.stub()
this.doc_id = ObjectId().toString()
@@ -166,10 +166,10 @@ describe('MongoManager', function () {
.calledWith(
{
doc_id: ObjectId(this.doc_id),
project_id: { $exists: false }
project_id: { $exists: false },
},
{
$set: { project_id: ObjectId(this.project_id) }
$set: { project_id: ObjectId(this.project_id) },
}
)
.should.equal(true)
@@ -184,7 +184,7 @@ describe('MongoManager', function () {
beforeEach(function () {
this.metadata = { mock: 'metadata' }
this.db.projectHistoryMetaData = {
findOne: sinon.stub().callsArgWith(1, null, this.metadata)
findOne: sinon.stub().callsArgWith(1, null, this.metadata),
}
return this.MongoManager.getProjectMetaData(
this.project_id,
@@ -207,7 +207,7 @@ describe('MongoManager', function () {
beforeEach(function () {
this.metadata = { mock: 'metadata' }
this.db.projectHistoryMetaData = {
updateOne: sinon.stub().yields()
updateOne: sinon.stub().yields(),
}
return this.MongoManager.setProjectMetaData(
this.project_id,
@@ -220,13 +220,13 @@ describe('MongoManager', function () {
return this.db.projectHistoryMetaData.updateOne
.calledWith(
{
project_id: ObjectId(this.project_id)
project_id: ObjectId(this.project_id),
},
{
$set: this.metadata
$set: this.metadata,
},
{
upsert: true
upsert: true,
}
)
.should.equal(true)
@@ -31,9 +31,9 @@ describe('PackManager', function () {
'@overleaf/metrics': { inc() {} },
'./ProjectIterator': require('../../../../app/js/ProjectIterator.js'), // Cache for speed
'@overleaf/settings': {
redis: { lock: { key_schema: {} } }
}
}
redis: { lock: { key_schema: {} } },
},
},
})
this.callback = sinon.stub()
this.doc_id = ObjectId().toString()
@@ -51,20 +51,20 @@ describe('PackManager', function () {
_id: '12345',
pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 }
{ op: 'op-2', meta: 'meta-2', v: 2 },
],
n: 2,
sz: 100
sz: 100,
}
this.newUpdates = [
{ op: 'op-3', meta: 'meta-3', v: 3 },
{ op: 'op-4', meta: 'meta-4', v: 4 }
{ op: 'op-4', meta: 'meta-4', v: 4 },
]
return (this.db.docHistory = {
insertOne: sinon.stub().yields(),
insert: sinon.stub().callsArg(1),
updateOne: sinon.stub().yields(),
findAndModify: sinon.stub().callsArg(1)
findAndModify: sinon.stub().callsArg(1),
})
})
@@ -95,10 +95,10 @@ describe('PackManager', function () {
return describe('for many small updates', function () {
beforeEach(function () {
this.newUpdates = __range__(0, 2048, true).map((i) => ({
this.newUpdates = __range__(0, 2048, true).map(i => ({
op: `op-${i}`,
meta: `meta-${i}`,
v: i
v: i,
}))
return this.PackManager.insertCompressedUpdates(
this.project_id,
@@ -209,10 +209,10 @@ describe('PackManager', function () {
describe('for many small updates', function () {
beforeEach(function () {
this.newUpdates = __range__(0, 2048, true).map((i) => ({
this.newUpdates = __range__(0, 2048, true).map(i => ({
op: `op-${i}`,
meta: `meta-${i}`,
v: i
v: i,
}))
return this.PackManager.insertCompressedUpdates(
this.project_id,
@@ -292,12 +292,12 @@ describe('PackManager', function () {
0.75 * this.PackManager.MAX_SIZE,
true
)
.map((j) => 'a')
.map(j => 'a')
.join('')
this.newUpdates = [0, 1, 2, 3, 4].map((i) => ({
this.newUpdates = [0, 1, 2, 3, 4].map(i => ({
op: `op-${i}-${longString}`,
meta: `meta-${i}`,
v: i
v: i,
}))
return this.PackManager.insertCompressedUpdates(
this.project_id,
@@ -393,7 +393,7 @@ describe('PackManager', function () {
doc_id: ObjectId(this.doc_id),
n: this.newUpdates.length,
v: this.newUpdates[0].v,
v_end: this.newUpdates[this.newUpdates.length - 1].v
v_end: this.newUpdates[this.newUpdates.length - 1].v,
})
.should.equal(true)
})
@@ -401,7 +401,7 @@ describe('PackManager', function () {
it('should set an expiry time in the future', function () {
return this.db.docHistory.insertOne
.calledWithMatch({
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000)
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000),
})
.should.equal(true)
})
@@ -419,12 +419,12 @@ describe('PackManager', function () {
_id: '12345',
pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 }
{ op: 'op-2', meta: 'meta-2', v: 2 },
],
n: 2,
sz: 100,
meta: { start_ts: Date.now() - 6 * 3600 * 1000 },
expiresAt: new Date(Date.now())
expiresAt: new Date(Date.now()),
}
return this.PackManager.flushCompressedUpdates(
@@ -444,7 +444,7 @@ describe('PackManager', function () {
{ _id: this.lastUpdate._id },
{
$push: { pack: { $each: this.newUpdates } },
$set: { v_end: this.newUpdates[this.newUpdates.length - 1].v }
$set: { v_end: this.newUpdates[this.newUpdates.length - 1].v },
}
)
.should.equal(true)
@@ -453,7 +453,7 @@ describe('PackManager', function () {
it('should set an expiry time in the future', function () {
return this.db.docHistory.updateOne
.calledWithMatch(sinon.match.any, {
$set: { expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) }
$set: { expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) },
})
.should.equal(true)
})
@@ -472,12 +472,12 @@ describe('PackManager', function () {
_id: '12345',
pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 }
{ op: 'op-2', meta: 'meta-2', v: 2 },
],
n: 2,
sz: 100,
meta: { start_ts: Date.now() - 6 * 3600 * 1000 },
expiresAt: new Date(Date.now())
expiresAt: new Date(Date.now()),
}
return this.PackManager.flushCompressedUpdates(
@@ -499,7 +499,7 @@ describe('PackManager', function () {
doc_id: ObjectId(this.doc_id),
n: this.newUpdates.length,
v: this.newUpdates[0].v,
v_end: this.newUpdates[this.newUpdates.length - 1].v
v_end: this.newUpdates[this.newUpdates.length - 1].v,
})
.should.equal(true)
})
@@ -522,12 +522,12 @@ describe('PackManager', function () {
_id: '12345',
pack: [
{ op: 'op-1', meta: 'meta-1', v: 1 },
{ op: 'op-2', meta: 'meta-2', v: 2 }
{ op: 'op-2', meta: 'meta-2', v: 2 },
],
n: 2,
sz: 100,
meta: { start_ts: Date.now() - 30 * 24 * 3600 * 1000 },
expiresAt: new Date(Date.now() - 30 * 24 * 3600 * 1000)
expiresAt: new Date(Date.now() - 30 * 24 * 3600 * 1000),
}
return this.PackManager.flushCompressedUpdates(
@@ -549,7 +549,7 @@ describe('PackManager', function () {
doc_id: ObjectId(this.doc_id),
n: this.newUpdates.length,
v: this.newUpdates[0].v,
v_end: this.newUpdates[this.newUpdates.length - 1].v
v_end: this.newUpdates[this.newUpdates.length - 1].v,
})
.should.equal(true)
})
@@ -557,7 +557,7 @@ describe('PackManager', function () {
it('should set an expiry time in the future', function () {
return this.db.docHistory.insertOne
.calledWithMatch({
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000)
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000),
})
.should.equal(true)
})
@@ -602,7 +602,7 @@ describe('PackManager', function () {
describe('when an archive is in progress', function () {
beforeEach(function () {
this.db.docHistoryIndex = {
findOne: sinon.stub().callsArgWith(2, null, { inS3: false })
findOne: sinon.stub().callsArgWith(2, null, { inS3: false }),
}
return this.PackManager.checkArchiveNotInProgress(
this.project_id,
@@ -624,7 +624,7 @@ describe('PackManager', function () {
describe('when an archive is completed', function () {
beforeEach(function () {
this.db.docHistoryIndex = {
findOne: sinon.stub().callsArgWith(2, null, { inS3: true })
findOne: sinon.stub().callsArgWith(2, null, { inS3: true }),
}
return this.PackManager.checkArchiveNotInProgress(
this.project_id,
@@ -646,7 +646,7 @@ describe('PackManager', function () {
return describe('when the archive has not started or completed', function () {
beforeEach(function () {
this.db.docHistoryIndex = {
findOne: sinon.stub().callsArgWith(2, null, {})
findOne: sinon.stub().callsArgWith(2, null, {}),
}
return this.PackManager.checkArchiveNotInProgress(
this.project_id,
@@ -24,9 +24,9 @@ describe('RedisManager', function () {
createClient: () => {
return (this.rclient = {
auth: sinon.stub(),
multi: () => this.rclient
multi: () => this.rclient,
})
}
},
},
'@overleaf/settings': {
redis: {
@@ -37,12 +37,12 @@ describe('RedisManager', function () {
},
docsWithHistoryOps({ project_id }) {
return `DocsWithHistoryOps:${project_id}`
}
}
}
}
}
}
},
},
},
},
},
},
})
this.doc_id = 'doc-id-123'
this.project_id = 'project-id-123'
@@ -54,9 +54,9 @@ describe('RedisManager', function () {
beforeEach(function () {
this.rawUpdates = [
{ v: 42, op: 'mock-op-42' },
{ v: 45, op: 'mock-op-45' }
{ v: 45, op: 'mock-op-45' },
]
this.jsonUpdates = Array.from(this.rawUpdates).map((update) =>
this.jsonUpdates = Array.from(this.rawUpdates).map(update =>
JSON.stringify(update)
)
this.rclient.lrange = sinon.stub().callsArgWith(3, null, this.jsonUpdates)
@@ -19,8 +19,8 @@ describe('RestoreManager', function () {
this.RestoreManager = SandboxedModule.require(modulePath, {
requires: {
'./DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
'./DiffManager': (this.DiffManager = {})
}
'./DiffManager': (this.DiffManager = {}),
},
})
this.callback = sinon.stub()
this.project_id = 'mock-project-id'
@@ -15,18 +15,18 @@ const modulePath = '../../../../app/js/UpdateCompressor.js'
const SandboxedModule = require('sandboxed-module')
const bigstring = __range__(0, 2 * 1024 * 1024, true)
.map((i) => 'a')
.map(i => 'a')
.join('')
const mediumstring = __range__(0, 1024 * 1024, true)
.map((j) => 'a')
.map(j => 'a')
.join('')
describe('UpdateCompressor', function () {
beforeEach(function () {
this.UpdateCompressor = SandboxedModule.require(modulePath, {
requires: {
'../lib/diff_match_patch': require('../../../../app/lib/diff_match_patch')
}
'../lib/diff_match_patch': require('../../../../app/lib/diff_match_patch'),
},
})
this.user_id = 'user-id-1'
this.other_user_id = 'user-id-2'
@@ -41,37 +41,37 @@ describe('UpdateCompressor', function () {
{
op: [
(this.op1 = { p: 0, i: 'Foo' }),
(this.op2 = { p: 6, i: 'bar' })
(this.op2 = { p: 6, i: 'bar' }),
],
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: [(this.op3 = { p: 10, i: 'baz' })],
meta: { ts: this.ts2, user_id: this.other_user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
op: this.op1,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: this.op2,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: this.op3,
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.other_user_id
user_id: this.other_user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -81,15 +81,15 @@ describe('UpdateCompressor', function () {
{
op: [],
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
}
v: 42,
},
])
).to.deep.equal([
{
op: this.UpdateCompressor.NOOP,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42
}
v: 42,
},
])
})
@@ -100,23 +100,23 @@ describe('UpdateCompressor', function () {
op: [
(this.op1 = { p: 0, i: 'Foo' }),
(this.op2 = { p: 9, c: 'baz' }),
(this.op3 = { p: 6, i: 'bar' })
(this.op3 = { p: 6, i: 'bar' }),
],
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
}
v: 42,
},
])
).to.deep.equal([
{
op: this.op1,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: this.op3,
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42
}
v: 42,
},
])
})
})
@@ -130,44 +130,44 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: (this.op2 = { p: 6, i: 'bar' }),
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: (this.op3 = { p: 10, i: 'baz' }),
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.other_user_id
user_id: this.other_user_id,
},
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
op: [this.op1, this.op2],
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: [this.op3],
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.other_user_id
user_id: this.other_user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -179,17 +179,17 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
}
v: 42,
},
])
).to.deep.equal([
{
op: [],
meta: { start_ts: this.ts1, end_ts: this.ts1, user_id: this.user_id },
v: 42
}
v: 42,
},
])
})
})
@@ -202,13 +202,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 6, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -216,10 +216,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -229,13 +229,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 5, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -243,10 +243,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -256,13 +256,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 9, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -270,19 +270,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 9, i: 'bar' },
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -292,13 +292,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 6, i: bigstring },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -306,19 +306,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 6, i: bigstring },
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -328,13 +328,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: bigstring },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 3 + bigstring.length, i: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -342,19 +342,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 3 + bigstring.length, i: 'bar' },
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -364,13 +364,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: mediumstring },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 3 + mediumstring.length, i: mediumstring },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -378,19 +378,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 3 + mediumstring.length, i: mediumstring },
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
})
@@ -402,13 +402,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, d: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 3, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -416,10 +416,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -429,13 +429,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, d: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 1, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -443,10 +443,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -456,13 +456,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, d: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 9, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -470,19 +470,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 9, d: 'bar' },
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
})
@@ -494,13 +494,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 5, d: 'o' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -508,10 +508,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -521,13 +521,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'fobaro' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 5, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -535,10 +535,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -548,13 +548,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 3, d: 'foo' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -562,10 +562,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -575,13 +575,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foo' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 9, d: 'bar' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -589,19 +589,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 9, d: 'bar' },
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -611,13 +611,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, i: 'foobar' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 6, d: 'bardle' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -625,19 +625,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 6, d: 'bardle' },
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
})
@@ -649,13 +649,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, d: 'one two three four five six seven eight' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 3, i: 'one 2 three four five six seven eight' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -663,19 +663,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
v: 43,
},
{
op: { p: 7, i: '2' },
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
@@ -685,13 +685,13 @@ describe('UpdateCompressor', function () {
{
op: { p: 3, d: 'one two three four five six seven eight' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 3, i: 'one two three four five six seven eight' },
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -699,10 +699,10 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
})
@@ -714,13 +714,13 @@ describe('UpdateCompressor', function () {
{
op: this.UpdateCompressor.NOOP,
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 6, i: 'bar' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -728,19 +728,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 6, i: 'bar' },
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
})
@@ -752,13 +752,13 @@ describe('UpdateCompressor', function () {
{
op: this.UpdateCompressor.NOOP,
meta: { ts: this.ts1, user_id: this.user_id },
v: 42
v: 42,
},
{
op: { p: 6, d: 'bar' },
meta: { ts: this.ts1, user_id: this.user_id },
v: 43
}
v: 43,
},
])
).to.deep.equal([
{
@@ -766,19 +766,19 @@ describe('UpdateCompressor', function () {
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: { p: 6, d: 'bar' },
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
})
@@ -792,45 +792,45 @@ describe('UpdateCompressor', function () {
{
op: [
{ p: 1000, d: 'hello' },
{ p: 1000, i: 'HELLO()' }
{ p: 1000, i: 'HELLO()' },
],
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
[
{
op: [{ p: 1006, i: 'WORLD' }],
meta: { ts: this.ts2, user_id: this.user_id },
v: 43
}
v: 43,
},
]
)
).to.deep.equal([
{
op: [
{ p: 1000, d: 'hello' },
{ p: 1000, i: 'HELLO()' }
{ p: 1000, i: 'HELLO()' },
],
meta: {
start_ts: this.ts1,
end_ts: this.ts1,
user_id: this.user_id
user_id: this.user_id,
},
v: 42
v: 42,
},
{
op: [{ p: 1006, i: 'WORLD' }],
meta: {
start_ts: this.ts2,
end_ts: this.ts2,
user_id: this.user_id
user_id: this.user_id,
},
v: 43
}
v: 43,
},
])
})
})
@@ -23,8 +23,8 @@ describe('UpdateTrimmer', function () {
this.UpdateTrimmer = SandboxedModule.require(modulePath, {
requires: {
'./WebApiManager': (this.WebApiManager = {}),
'./MongoManager': (this.MongoManager = {})
}
'./MongoManager': (this.MongoManager = {}),
},
})
this.callback = sinon.stub()
@@ -38,12 +38,12 @@ describe('UpdatesManager', function () {
key_schema: {
historyLock({ doc_id }) {
return `HistoryLock:${doc_id}`
}
}
}
}
}
}
},
},
},
},
},
},
})
this.doc_id = 'doc-id-123'
this.project_id = 'project-id-123'
@@ -79,7 +79,7 @@ describe('UpdatesManager', function () {
beforeEach(function () {
this.rawUpdates = [
{ v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' }
{ v: 13, op: 'mock-op-13' },
]
this.compressedUpdates = [{ v: 13, op: 'compressed-op-12' }]
@@ -127,7 +127,7 @@ describe('UpdatesManager', function () {
this.lastCompressedUpdate = { v: 11, op: 'compressed-op-11' }
this.compressedUpdates = [
{ v: 12, op: 'compressed-op-11+12' },
{ v: 13, op: 'compressed-op-12' }
{ v: 13, op: 'compressed-op-12' },
]
this.MongoManager.peekLastCompressedUpdate = sinon
@@ -148,7 +148,7 @@ describe('UpdatesManager', function () {
beforeEach(function () {
this.rawUpdates = [
{ v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' }
{ v: 13, op: 'mock-op-13' },
]
return this.UpdatesManager.compressAndSaveRawUpdates(
this.project_id,
@@ -192,11 +192,11 @@ describe('UpdatesManager', function () {
beforeEach(function () {
this.lastCompressedUpdate = {
pack: [{ v: 11, op: 'compressed-op-11' }],
v: 11
v: 11,
}
this.rawUpdates = [
{ v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' }
{ v: 13, op: 'mock-op-13' },
]
this.MongoManager.peekLastCompressedUpdate = sinon
.stub()
@@ -250,7 +250,7 @@ describe('UpdatesManager', function () {
{ v: 10, op: 'mock-op-10' },
{ v: 11, op: 'mock-op-11' },
{ v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' }
{ v: 13, op: 'mock-op-13' },
]
return this.UpdatesManager.compressAndSaveRawUpdates(
@@ -303,7 +303,7 @@ describe('UpdatesManager', function () {
beforeEach(function () {
this.rawUpdates = [
{ v: 13, op: 'mock-op-13' },
{ v: 12, op: 'mock-op-12' }
{ v: 12, op: 'mock-op-12' },
]
return this.UpdatesManager.compressAndSaveRawUpdates(
this.project_id,
@@ -347,7 +347,7 @@ describe('UpdatesManager', function () {
beforeEach(function () {
this.rawUpdates = [
{ v: 12, op: 'mock-op-12' },
{ v: 13, op: 'mock-op-13' }
{ v: 13, op: 'mock-op-13' },
]
return this.UpdatesManager.compressAndSaveRawUpdates(
this.project_id,
@@ -454,7 +454,7 @@ describe('UpdatesManager', function () {
'mock-update-1',
'mock-update-2',
'mock-update-3',
'mock-update-4'
'mock-update-4',
]
this.redisArray = this.updates.slice()
this.RedisManager.getOldestDocUpdates = (
@@ -673,7 +673,7 @@ describe('UpdatesManager', function () {
})
it('should process the doc ops for the each doc_id', function () {
return Array.from(this.doc_ids).map((doc_id) =>
return Array.from(this.doc_ids).map(doc_id =>
this.UpdatesManager._processUncompressedUpdatesForDocWithLock
.calledWith(this.project_id, doc_id, this.temporary)
.should.equal(true)
@@ -692,26 +692,26 @@ describe('UpdatesManager', function () {
doc_id: 123,
v: 456,
op: 'mock-updates',
meta: { user_id: 123, start_ts: 1233, end_ts: 1234 }
}
meta: { user_id: 123, start_ts: 1233, end_ts: 1234 },
},
]
this.options = { before: 'mock-before', limit: 'mock-limit' }
this.summarizedUpdates = [
{
meta: { user_ids: [123], start_ts: 1233, end_ts: 1234 },
docs: { '123': { fromV: 456, toV: 456 } }
}
docs: { 123: { fromV: 456, toV: 456 } },
},
]
this.updatesWithUserInfo = ['updates-with-user-info']
this.done_state = false
this.iterator = {
next: (cb) => {
next: cb => {
this.done_state = true
return cb(null, this.updates)
},
done: () => {
return this.done_state
}
},
}
this.PackManager.makeProjectIterator = sinon
.stub()
@@ -867,22 +867,22 @@ describe('UpdatesManager', function () {
this.updates = [
{
meta: {
user_id: this.user_id_1
user_id: this.user_id_1,
},
op: 'mock-op-1'
op: 'mock-op-1',
},
{
meta: {
user_id: this.user_id_1
user_id: this.user_id_1,
},
op: 'mock-op-2'
op: 'mock-op-2',
},
{
meta: {
user_id: this.user_id_2
user_id: this.user_id_2,
},
op: 'mock-op-3'
}
op: 'mock-op-3',
},
]
this.user_info = {}
this.user_info[this.user_id_1] = { email: 'user1@sharelatex.com' }
@@ -920,27 +920,27 @@ describe('UpdatesManager', function () {
{
meta: {
user: {
email: 'user1@sharelatex.com'
}
email: 'user1@sharelatex.com',
},
},
op: 'mock-op-1'
op: 'mock-op-1',
},
{
meta: {
user: {
email: 'user1@sharelatex.com'
}
email: 'user1@sharelatex.com',
},
},
op: 'mock-op-2'
op: 'mock-op-2',
},
{
meta: {
user: {
email: 'user2@sharelatex.com'
}
email: 'user2@sharelatex.com',
},
},
op: 'mock-op-3'
}
op: 'mock-op-3',
},
])
})
})
@@ -950,16 +950,16 @@ describe('UpdatesManager', function () {
this.updates = [
{
meta: {
user_id: null
user_id: null,
},
op: 'mock-op-1'
op: 'mock-op-1',
},
{
meta: {
user_id: 'anonymous-user'
user_id: 'anonymous-user',
},
op: 'mock-op-2'
}
op: 'mock-op-2',
},
]
this.WebApiManager.getUserInfo = (user_id, callback) => {
if (callback == null) {
@@ -986,12 +986,12 @@ describe('UpdatesManager', function () {
return expect(this.results).to.deep.equal([
{
meta: {},
op: 'mock-op-1'
op: 'mock-op-1',
},
{
meta: {},
op: 'mock-op-2'
}
op: 'mock-op-2',
},
])
})
})
@@ -1011,19 +1011,19 @@ describe('UpdatesManager', function () {
meta: {
user_id: this.user_1.id,
start_ts: this.now + 20,
end_ts: this.now + 30
end_ts: this.now + 30,
},
v: 5
v: 5,
},
{
doc_id: 'doc-id-1',
meta: {
user_id: this.user_2.id,
start_ts: this.now,
end_ts: this.now + 10
end_ts: this.now + 10,
},
v: 4
}
v: 4,
},
])
return expect(result).to.deep.equal([
@@ -1031,15 +1031,15 @@ describe('UpdatesManager', function () {
docs: {
'doc-id-1': {
fromV: 4,
toV: 5
}
toV: 5,
},
},
meta: {
user_ids: [this.user_1.id, this.user_2.id],
start_ts: this.now,
end_ts: this.now + 30
}
}
end_ts: this.now + 30,
},
},
])
})
@@ -1051,47 +1051,47 @@ describe('UpdatesManager', function () {
meta: {
user_id: this.user_2.id,
start_ts: this.now + oneDay,
end_ts: this.now + oneDay + 10
end_ts: this.now + oneDay + 10,
},
v: 5
v: 5,
},
{
doc_id: 'doc-id-1',
meta: {
user_id: this.user_1.id,
start_ts: this.now,
end_ts: this.now + 10
end_ts: this.now + 10,
},
v: 4
}
v: 4,
},
])
return expect(result).to.deep.equal([
{
docs: {
'doc-id-1': {
fromV: 5,
toV: 5
}
toV: 5,
},
},
meta: {
user_ids: [this.user_2.id],
start_ts: this.now + oneDay,
end_ts: this.now + oneDay + 10
}
end_ts: this.now + oneDay + 10,
},
},
{
docs: {
'doc-id-1': {
fromV: 4,
toV: 4
}
toV: 4,
},
},
meta: {
user_ids: [this.user_1.id],
start_ts: this.now,
end_ts: this.now + 10
}
}
end_ts: this.now + 10,
},
},
])
})
@@ -1103,34 +1103,34 @@ describe('UpdatesManager', function () {
meta: {
user_id: this.user_1.id,
start_ts: this.now + 20,
end_ts: this.now + 30
end_ts: this.now + 30,
},
v: 5
v: 5,
},
{
doc_id: 'doc-id-2',
meta: {
user_id: this.user_2.id,
start_ts: this.now,
end_ts: this.now + 10
end_ts: this.now + 10,
},
v: 4
}
v: 4,
},
],
[
{
docs: {
'doc-id-1': {
fromV: 6,
toV: 8
}
toV: 8,
},
},
meta: {
user_ids: [this.user_1.id],
start_ts: this.now + 40,
end_ts: this.now + 50
}
}
end_ts: this.now + 50,
},
},
]
)
return expect(result).to.deep.equal([
@@ -1138,19 +1138,19 @@ describe('UpdatesManager', function () {
docs: {
'doc-id-1': {
toV: 8,
fromV: 6
fromV: 6,
},
'doc-id-2': {
toV: 5,
fromV: 4
}
fromV: 4,
},
},
meta: {
user_ids: [this.user_1.id, this.user_2.id],
start_ts: this.now,
end_ts: this.now + 50
}
}
end_ts: this.now + 50,
},
},
])
})
@@ -1161,34 +1161,34 @@ describe('UpdatesManager', function () {
meta: {
user_id: this.user_1.id,
start_ts: this.now + 20,
end_ts: this.now + 30
end_ts: this.now + 30,
},
v: 5
v: 5,
},
{
doc_id: 'doc-id-1',
meta: {
user_id: null,
start_ts: this.now,
end_ts: this.now + 10
end_ts: this.now + 10,
},
v: 4
}
v: 4,
},
])
return expect(result).to.deep.equal([
{
docs: {
'doc-id-1': {
fromV: 4,
toV: 5
}
toV: 5,
},
},
meta: {
user_ids: [this.user_1.id, null],
start_ts: this.now,
end_ts: this.now + 30
}
}
end_ts: this.now + 30,
},
},
])
})
@@ -1199,34 +1199,34 @@ describe('UpdatesManager', function () {
meta: {
user_id: null,
start_ts: this.now,
end_ts: this.now + 10
end_ts: this.now + 10,
},
v: 4
v: 4,
},
{
doc_id: 'doc-id-1',
meta: {
user_id: this.user_1.id,
start_ts: this.now + 20,
end_ts: this.now + 30
end_ts: this.now + 30,
},
v: 5
}
v: 5,
},
])
return expect(result).to.deep.equal([
{
docs: {
'doc-id-1': {
fromV: 4,
toV: 5
}
toV: 5,
},
},
meta: {
user_ids: [null, this.user_1.id],
start_ts: this.now,
end_ts: this.now + 30
}
}
end_ts: this.now + 30,
},
},
])
})
@@ -1237,43 +1237,43 @@ describe('UpdatesManager', function () {
meta: {
user_id: this.user_1.id,
start_ts: this.now + 20,
end_ts: this.now + 30
end_ts: this.now + 30,
},
v: 5
v: 5,
},
{
doc_id: 'doc-id-1',
meta: {
user_id: null,
start_ts: this.now,
end_ts: this.now + 10
end_ts: this.now + 10,
},
v: 4
v: 4,
},
{
doc_id: 'doc-id-1',
meta: {
user_id: null,
start_ts: this.now + 2,
end_ts: this.now + 4
end_ts: this.now + 4,
},
v: 4
}
v: 4,
},
])
return expect(result).to.deep.equal([
{
docs: {
'doc-id-1': {
fromV: 4,
toV: 5
}
toV: 5,
},
},
meta: {
user_ids: [this.user_1.id, null],
start_ts: this.now,
end_ts: this.now + 30
}
}
end_ts: this.now + 30,
},
},
])
})
@@ -1285,19 +1285,19 @@ describe('UpdatesManager', function () {
meta: {
user_id: this.user_1.id,
start_ts: this.now + 20,
end_ts: this.now + 30
end_ts: this.now + 30,
},
v: 5
v: 5,
},
{
doc_id: 'doc-id-1',
meta: {
user_id: this.user_2.id,
start_ts: this.now,
end_ts: this.now + 10
end_ts: this.now + 10,
},
v: 4
}
v: 4,
},
])
return expect(result).to.deep.equal([
@@ -1305,28 +1305,28 @@ describe('UpdatesManager', function () {
docs: {
'doc-id-1': {
fromV: 5,
toV: 5
}
toV: 5,
},
},
meta: {
user_ids: [this.user_1.id],
start_ts: this.now + 20,
end_ts: this.now + 30
}
end_ts: this.now + 30,
},
},
{
docs: {
'doc-id-1': {
fromV: 4,
toV: 4
}
toV: 4,
},
},
meta: {
user_ids: [this.user_2.id],
start_ts: this.now,
end_ts: this.now + 10
}
}
end_ts: this.now + 10,
},
},
])
})
})
@@ -24,11 +24,11 @@ describe('WebApiManager', function () {
web: {
url: 'http://example.com',
user: 'sharelatex',
pass: 'password'
}
}
})
}
pass: 'password',
},
},
}),
},
})
this.callback = sinon.stub()
this.user_id = 'mock-user-id'
@@ -38,7 +38,7 @@ describe('WebApiManager', function () {
id: this.user_id,
first_name: 'Leo',
last_nane: 'Lion',
extra_param: 'blah'
extra_param: 'blah',
}
return (this.project = { features: 'mock-features' })
})
@@ -60,8 +60,8 @@ describe('WebApiManager', function () {
auth: {
user: this.settings.apis.web.user,
pass: this.settings.apis.web.pass,
sendImmediately: true
}
sendImmediately: true,
},
})
.should.equal(true)
})
@@ -72,7 +72,7 @@ describe('WebApiManager', function () {
id: this.user_id,
email: this.user_info.email,
first_name: this.user_info.first_name,
last_name: this.user_info.last_name
last_name: this.user_info.last_name,
})
.should.equal(true)
})
@@ -150,8 +150,8 @@ describe('WebApiManager', function () {
auth: {
user: this.settings.apis.web.user,
pass: this.settings.apis.web.pass,
sendImmediately: true
}
sendImmediately: true,
},
})
.should.equal(true)
})