2014-03-10 12:58:26 -04:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
mongojs = require "../../../app/js/mongojs"
|
|
|
|
db = mongojs.db
|
|
|
|
ObjectId = mongojs.ObjectId
|
|
|
|
Settings = require "settings-sharelatex"
|
|
|
|
|
2018-05-24 07:02:27 -04:00
|
|
|
TrackChangesApp = require "./helpers/TrackChangesApp"
|
2014-03-10 12:58:26 -04:00
|
|
|
TrackChangesClient = require "./helpers/TrackChangesClient"
|
|
|
|
MockDocUpdaterApi = require "./helpers/MockDocUpdaterApi"
|
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
|
|
|
|
|
|
|
describe "Restoring a version", ->
|
|
|
|
before (done) ->
|
|
|
|
sinon.spy MockDocUpdaterApi, "setDoc"
|
|
|
|
|
|
|
|
@now = Date.now()
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@project_id = ObjectId().toString()
|
2014-05-16 10:59:12 -04:00
|
|
|
MockWebApi.projects[@project_id] = features: versioning: true
|
2015-09-16 18:33:23 -04:00
|
|
|
|
2014-03-10 12:58:26 -04:00
|
|
|
minutes = 60 * 1000
|
|
|
|
|
|
|
|
@updates = [{
|
|
|
|
op: [{ i: "one ", p: 0 }]
|
|
|
|
meta: { ts: @now - 6 * minutes, user_id: @user_id }
|
|
|
|
v: 3
|
|
|
|
}, {
|
|
|
|
op: [{ i: "two ", p: 4 }]
|
|
|
|
meta: { ts: @now - 4 * minutes, user_id: @user_id }
|
|
|
|
v: 4
|
|
|
|
}, {
|
|
|
|
op: [{ i: "three ", p: 8 }]
|
|
|
|
meta: { ts: @now - 2 * minutes, user_id: @user_id }
|
|
|
|
v: 5
|
|
|
|
}, {
|
|
|
|
op: [{ i: "four", p: 14 }]
|
|
|
|
meta: { ts: @now, user_id: @user_id }
|
|
|
|
v: 6
|
|
|
|
}]
|
|
|
|
@lines = ["one two three four"]
|
|
|
|
@restored_lines = ["one two "]
|
|
|
|
@beforeVersion = 5
|
|
|
|
|
|
|
|
MockWebApi.users[@user_id] = @user =
|
|
|
|
email: "user@sharelatex.com"
|
|
|
|
first_name: "Leo"
|
|
|
|
last_name: "Lion"
|
|
|
|
id: @user_id
|
2015-09-16 18:33:23 -04:00
|
|
|
|
2014-03-10 12:58:26 -04:00
|
|
|
MockDocUpdaterApi.docs[@doc_id] =
|
|
|
|
lines: @lines
|
|
|
|
version: 7
|
|
|
|
|
2018-05-24 07:02:27 -04:00
|
|
|
TrackChangesApp.ensureRunning =>
|
|
|
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, @updates, (error) =>
|
2014-03-10 12:58:26 -04:00
|
|
|
throw error if error?
|
2018-05-24 07:02:27 -04:00
|
|
|
TrackChangesClient.restoreDoc @project_id, @doc_id, @beforeVersion, @user_id, (error) =>
|
|
|
|
throw error if error?
|
|
|
|
done()
|
2014-03-10 12:58:26 -04:00
|
|
|
|
|
|
|
after () ->
|
|
|
|
MockDocUpdaterApi.setDoc.restore()
|
|
|
|
|
|
|
|
it "should set the doc in the doc updater", ->
|
|
|
|
MockDocUpdaterApi.setDoc
|
2017-03-21 07:32:53 -04:00
|
|
|
.calledWith(@project_id, @doc_id, @restored_lines, @user_id, true)
|
2014-03-10 12:58:26 -04:00
|
|
|
.should.equal true
|