2020-02-17 12:35:50 -05:00
|
|
|
/* eslint-disable
|
|
|
|
chai-friendly/no-unused-expressions,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:35:39 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-17 12:35:59 -05:00
|
|
|
const sinon = require('sinon')
|
2021-03-23 15:08:32 -04:00
|
|
|
const { expect } = require('chai')
|
2020-09-10 11:48:09 -04:00
|
|
|
const { ObjectId } = require('../../../app/js/mongodb')
|
2020-02-17 12:35:59 -05:00
|
|
|
const Settings = require('settings-sharelatex')
|
2014-03-05 10:59:40 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
const TrackChangesApp = require('./helpers/TrackChangesApp')
|
|
|
|
const TrackChangesClient = require('./helpers/TrackChangesClient')
|
|
|
|
const MockWebApi = require('./helpers/MockWebApi')
|
2014-03-05 10:59:40 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('Getting updates', function () {
|
|
|
|
before(function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
this.now = Date.now()
|
|
|
|
this.to = this.now
|
|
|
|
this.user_id = ObjectId().toString()
|
|
|
|
this.deleted_user_id = 'deleted_user'
|
|
|
|
this.doc_id = ObjectId().toString()
|
|
|
|
this.project_id = ObjectId().toString()
|
2014-03-05 10:59:40 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
this.minutes = 60 * 1000
|
|
|
|
this.hours = 60 * this.minutes
|
2014-03-28 12:01:34 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
MockWebApi.projects[this.project_id] = {
|
|
|
|
features: {
|
|
|
|
versioning: true
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 10:59:40 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
MockWebApi.users[this.user_id] = this.user = {
|
|
|
|
email: 'user@sharelatex.com',
|
|
|
|
first_name: 'Leo',
|
|
|
|
last_name: 'Lion',
|
|
|
|
id: this.user_id
|
|
|
|
}
|
|
|
|
sinon.spy(MockWebApi, 'getUserInfo')
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
this.updates = []
|
|
|
|
for (let i = 0; i <= 9; i++) {
|
|
|
|
this.updates.push({
|
|
|
|
op: [{ i: 'a', p: 0 }],
|
|
|
|
meta: {
|
|
|
|
ts: this.now - (9 - i) * this.hours - 2 * this.minutes,
|
|
|
|
user_id: this.user_id
|
|
|
|
},
|
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.updates[0].meta.user_id = this.deleted_user_id
|
2019-06-21 10:32:47 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
TrackChangesApp.ensureRunning(() => {
|
|
|
|
return TrackChangesClient.pushRawUpdates(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.updates,
|
2020-06-04 04:24:21 -04:00
|
|
|
(error) => {
|
2020-02-17 12:35:59 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
;({
|
|
|
|
after() {
|
|
|
|
MockWebApi.getUserInfo.restore()
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
})
|
2014-03-05 10:59:40 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('getting updates up to the limit', function () {
|
|
|
|
before(function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
TrackChangesClient.getUpdates(
|
|
|
|
this.project_id,
|
|
|
|
{ before: this.to + 1, min_count: 3 },
|
|
|
|
(error, body) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
this.updates = body.updates
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
})
|
2014-03-05 10:59:40 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should fetch the user details from the web api', function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
return MockWebApi.getUserInfo.calledWith(this.user_id).should.equal(true)
|
|
|
|
})
|
2014-03-11 13:39:40 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should return at least the min_count number of summarized updates', function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
const docs1 = {}
|
|
|
|
docs1[this.doc_id] = { toV: 20, fromV: 19 }
|
|
|
|
const docs2 = {}
|
|
|
|
docs2[this.doc_id] = { toV: 18, fromV: 17 }
|
|
|
|
const docs3 = {}
|
|
|
|
docs3[this.doc_id] = { toV: 16, fromV: 15 }
|
|
|
|
return expect(this.updates.slice(0, 3)).to.deep.equal([
|
|
|
|
{
|
|
|
|
docs: docs1,
|
|
|
|
meta: {
|
|
|
|
start_ts: this.to - 2 * this.minutes,
|
|
|
|
end_ts: this.to,
|
|
|
|
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]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
docs: docs3,
|
|
|
|
meta: {
|
|
|
|
start_ts: this.to - 2 * this.hours - 2 * this.minutes,
|
|
|
|
end_ts: this.to - 2 * this.hours,
|
|
|
|
users: [this.user]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|
2014-03-11 13:39:40 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return describe('getting updates beyond the end of the database', function () {
|
|
|
|
before(function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
TrackChangesClient.getUpdates(
|
|
|
|
this.project_id,
|
|
|
|
{ before: this.to - 8 * this.hours + 1, min_count: 30 },
|
|
|
|
(error, body) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
this.updates = body.updates
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
})
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should return as many updates as it can', function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
const docs1 = {}
|
|
|
|
docs1[this.doc_id] = { toV: 4, fromV: 3 }
|
|
|
|
const docs2 = {}
|
|
|
|
docs2[this.doc_id] = { toV: 2, fromV: 1 }
|
|
|
|
return expect(this.updates).to.deep.equal([
|
|
|
|
{
|
|
|
|
docs: docs1,
|
|
|
|
meta: {
|
|
|
|
start_ts: this.to - 8 * this.hours - 2 * this.minutes,
|
|
|
|
end_ts: this.to - 8 * this.hours,
|
|
|
|
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]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|