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')
|
|
|
|
const chai = require('chai')
|
|
|
|
chai.should()
|
|
|
|
const { expect } = chai
|
|
|
|
const mongojs = require('../../../app/js/mongojs')
|
|
|
|
const { db } = mongojs
|
|
|
|
const { ObjectId } = mongojs
|
|
|
|
const Settings = require('settings-sharelatex')
|
2014-03-04 10:27:03 -05: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-04 10:27:03 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('Getting a diff', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-17 12:35:59 -05:00
|
|
|
sinon.spy(MockDocUpdaterApi, 'getDoc')
|
2018-05-24 07:02:27 -04:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
this.now = Date.now()
|
|
|
|
this.from = this.now - 100000000
|
|
|
|
this.to = this.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-04 10:27:03 -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-04 10:27:03 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
const twoMinutes = 2 * 60 * 1000
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
this.updates = [
|
|
|
|
{
|
|
|
|
op: [{ i: 'one ', p: 0 }],
|
|
|
|
meta: { ts: this.from - twoMinutes, user_id: this.user_id },
|
|
|
|
v: 3
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: [{ i: 'two ', p: 4 }],
|
|
|
|
meta: { ts: this.from + twoMinutes, user_id: this.user_id },
|
|
|
|
v: (this.fromVersion = 4)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: [{ i: 'three ', p: 8 }],
|
|
|
|
meta: { ts: this.to - twoMinutes, user_id: this.user_id },
|
|
|
|
v: (this.toVersion = 5)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: [{ i: 'four', p: 14 }],
|
|
|
|
meta: { ts: this.to + twoMinutes, user_id: this.user_id },
|
|
|
|
v: 6
|
|
|
|
}
|
|
|
|
]
|
|
|
|
this.lines = ['one two three four']
|
|
|
|
this.expected_diff = [
|
|
|
|
{ u: 'one ' },
|
|
|
|
{
|
|
|
|
i: 'two three ',
|
|
|
|
meta: {
|
|
|
|
start_ts: this.from + twoMinutes,
|
|
|
|
end_ts: this.to - twoMinutes,
|
|
|
|
user: this.user
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2014-03-04 10:27:03 -05:00
|
|
|
|
2020-02-17 12:35:59 -05:00
|
|
|
MockDocUpdaterApi.docs[this.doc_id] = {
|
|
|
|
lines: this.lines,
|
|
|
|
version: 7
|
|
|
|
}
|
|
|
|
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 TrackChangesClient.getDiff(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.fromVersion,
|
|
|
|
this.toVersion,
|
|
|
|
(error, diff) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
this.diff = diff.diff
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
return null
|
|
|
|
})
|
2014-03-04 10:27:03 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
afterEach(function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
MockDocUpdaterApi.getDoc.restore()
|
|
|
|
MockWebApi.getUserInfo.restore()
|
|
|
|
return null
|
|
|
|
})
|
2014-03-04 10:27:03 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should return the diff', function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
return expect(this.diff).to.deep.equal(this.expected_diff)
|
|
|
|
})
|
2014-03-04 10:27:03 -05:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should get the doc from the doc updater', function () {
|
2020-02-17 12:35:59 -05:00
|
|
|
MockDocUpdaterApi.getDoc
|
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
})
|