2014-03-04 10:27:03 -05: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-04 10:27:03 -05:00
|
|
|
TrackChangesClient = require "./helpers/TrackChangesClient"
|
|
|
|
MockDocUpdaterApi = require "./helpers/MockDocUpdaterApi"
|
2014-03-06 13:04:00 -05:00
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
2014-03-04 10:27:03 -05:00
|
|
|
|
|
|
|
describe "Getting a diff", ->
|
2018-05-24 07:02:27 -04:00
|
|
|
|
|
|
|
beforeEach (done) ->
|
2014-03-04 10:27:03 -05:00
|
|
|
sinon.spy MockDocUpdaterApi, "getDoc"
|
|
|
|
|
|
|
|
@now = Date.now()
|
|
|
|
@from = @now - 100000000
|
|
|
|
@to = @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
|
2014-03-04 10:27:03 -05:00
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
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
|
|
|
sinon.spy MockWebApi, "getUserInfo"
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2014-03-04 10:27:03 -05:00
|
|
|
twoMinutes = 2 * 60 * 1000
|
|
|
|
|
|
|
|
@updates = [{
|
|
|
|
op: [{ i: "one ", p: 0 }]
|
|
|
|
meta: { ts: @from - twoMinutes, user_id: @user_id }
|
|
|
|
v: 3
|
|
|
|
}, {
|
|
|
|
op: [{ i: "two ", p: 4 }]
|
|
|
|
meta: { ts: @from + twoMinutes, user_id: @user_id }
|
2014-03-06 05:45:51 -05:00
|
|
|
v: @fromVersion = 4
|
2014-03-04 10:27:03 -05:00
|
|
|
}, {
|
|
|
|
op: [{ i: "three ", p: 8 }]
|
|
|
|
meta: { ts: @to - twoMinutes, user_id: @user_id }
|
2014-03-06 05:45:51 -05:00
|
|
|
v: @toVersion = 5
|
2014-03-04 10:27:03 -05:00
|
|
|
}, {
|
|
|
|
op: [{ i: "four", p: 14 }]
|
|
|
|
meta: { ts: @to + twoMinutes, user_id: @user_id }
|
|
|
|
v: 6
|
|
|
|
}]
|
|
|
|
@lines = ["one two three four"]
|
|
|
|
@expected_diff = [
|
|
|
|
{ u: "one " }
|
2014-03-12 09:27:18 -04:00
|
|
|
{ i: "two three ", meta: { start_ts: @from + twoMinutes, end_ts: @to - twoMinutes, user: @user } }
|
2014-03-04 10:27:03 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
MockDocUpdaterApi.docs[@doc_id] =
|
|
|
|
lines: @lines
|
2014-03-05 11:31:38 -05:00
|
|
|
version: 7
|
2018-05-24 07:02:27 -04:00
|
|
|
TrackChangesApp.ensureRunning =>
|
|
|
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, @updates, (error) =>
|
2014-03-04 10:27:03 -05:00
|
|
|
throw error if error?
|
2018-05-24 07:02:27 -04:00
|
|
|
TrackChangesClient.getDiff @project_id, @doc_id, @fromVersion, @toVersion, (error, diff) =>
|
|
|
|
throw error if error?
|
|
|
|
@diff = diff.diff
|
|
|
|
done()
|
2014-03-04 10:27:03 -05:00
|
|
|
|
2018-05-24 07:02:27 -04:00
|
|
|
afterEach () ->
|
2014-03-04 10:27:03 -05:00
|
|
|
MockDocUpdaterApi.getDoc.restore()
|
2015-09-16 18:33:23 -04:00
|
|
|
MockWebApi.getUserInfo.restore()
|
2014-03-04 10:27:03 -05:00
|
|
|
|
|
|
|
it "should return the diff", ->
|
|
|
|
expect(@diff).to.deep.equal @expected_diff
|
|
|
|
|
|
|
|
it "should get the doc from the doc updater", ->
|
|
|
|
MockDocUpdaterApi.getDoc
|
|
|
|
.calledWith(@project_id, @doc_id)
|
|
|
|
.should.equal true
|