2020-02-17 12:35:50 -05:00
|
|
|
/* eslint-disable
|
|
|
|
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')
|
2021-07-12 12:47:16 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
const TrackChangesApp = require('./helpers/TrackChangesApp')
|
|
|
|
const TrackChangesClient = require('./helpers/TrackChangesClient')
|
|
|
|
const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi')
|
|
|
|
const MockWebApi = require('./helpers/MockWebApi')
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('Restoring a version', function () {
|
|
|
|
before(function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
sinon.spy(MockDocUpdaterApi, 'setDoc')
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
this.now = Date.now()
|
|
|
|
this.user_id = ObjectId().toString()
|
|
|
|
this.doc_id = ObjectId().toString()
|
|
|
|
this.project_id = ObjectId().toString()
|
|
|
|
MockWebApi.projects[this.project_id] = { features: { versioning: true } }
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
const minutes = 60 * 1000
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
op: [{ i: 'one ', p: 0 }],
|
|
|
|
meta: { ts: this.now - 6 * minutes, user_id: this.user_id },
|
2021-07-13 07:04:43 -04:00
|
|
|
v: 3,
|
2020-02-17 12:35:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
op: [{ i: 'two ', p: 4 }],
|
|
|
|
meta: { ts: this.now - 4 * minutes, user_id: this.user_id },
|
2021-07-13 07:04:43 -04:00
|
|
|
v: 4,
|
2020-02-17 12:35:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
op: [{ i: 'three ', p: 8 }],
|
|
|
|
meta: { ts: this.now - 2 * minutes, user_id: this.user_id },
|
2021-07-13 07:04:43 -04:00
|
|
|
v: 5,
|
2020-02-17 12:35:59 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
op: [{ i: 'four', p: 14 }],
|
|
|
|
meta: { ts: this.now, user_id: this.user_id },
|
2021-07-13 07:04:43 -04:00
|
|
|
v: 6,
|
|
|
|
},
|
2020-02-17 12:35:59 -05:00
|
|
|
]
|
|
|
|
this.lines = ['one two three four']
|
|
|
|
this.restored_lines = ['one two ']
|
|
|
|
this.beforeVersion = 5
|
2015-09-16 18:33:23 -04: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',
|
2021-07-13 07:04:43 -04:00
|
|
|
id: this.user_id,
|
2020-02-17 12:35:59 -05:00
|
|
|
}
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
MockDocUpdaterApi.docs[this.doc_id] = {
|
|
|
|
lines: this.lines,
|
2021-07-13 07:04:43 -04:00
|
|
|
version: 7,
|
2020-02-17 12:35:59 -05:00
|
|
|
}
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
TrackChangesApp.ensureRunning(() => {
|
|
|
|
return TrackChangesClient.pushRawUpdates(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.updates,
|
2021-07-13 07:04:43 -04:00
|
|
|
error => {
|
2020-02-17 12:35:59 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return TrackChangesClient.restoreDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.beforeVersion,
|
|
|
|
this.user_id,
|
2021-07-13 07:04:43 -04:00
|
|
|
error => {
|
2020-02-17 12:35:59 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
return null
|
|
|
|
})
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
after(function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
MockDocUpdaterApi.setDoc.restore()
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should set the doc in the doc updater', function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
MockDocUpdaterApi.setDoc
|
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.restored_lines,
|
|
|
|
this.user_id,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
})
|