2014-03-05 10:59:40 -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"
|
|
|
|
|
|
|
|
TrackChangesClient = require "./helpers/TrackChangesClient"
|
2014-03-06 13:04:00 -05:00
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
2014-03-05 10:59:40 -05:00
|
|
|
|
|
|
|
describe "Getting updates", ->
|
|
|
|
before (done) ->
|
|
|
|
@now = Date.now()
|
|
|
|
@to = @now
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
|
|
|
|
@minutes = 60 * 1000
|
|
|
|
|
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
|
|
|
|
sinon.spy MockWebApi, "getUser"
|
|
|
|
|
2014-03-05 10:59:40 -05:00
|
|
|
@updates = [{
|
|
|
|
op: [{ i: "one ", p: 0 }]
|
|
|
|
meta: { ts: @to - 4 * @minutes, user_id: @user_id }
|
|
|
|
v: 3
|
|
|
|
}, {
|
|
|
|
op: [{ i: "two ", p: 4 }]
|
|
|
|
meta: { ts: @to - 2 * @minutes, user_id: @user_id }
|
|
|
|
v: 4
|
|
|
|
}, {
|
|
|
|
op: [{ i: "three ", p: 8 }]
|
|
|
|
meta: { ts: @to, user_id: @user_id }
|
2014-03-06 05:45:51 -05:00
|
|
|
v: @toVersion = 5
|
2014-03-05 10:59:40 -05:00
|
|
|
}, {
|
|
|
|
op: [{ i: "four", p: 14 }]
|
|
|
|
meta: { ts: @to + 2 * @minutes, user_id: @user_id }
|
|
|
|
v: 6
|
|
|
|
}]
|
|
|
|
|
|
|
|
TrackChangesClient.pushRawUpdates @doc_id, @updates, (error) =>
|
|
|
|
throw error if error?
|
2014-03-06 05:45:51 -05:00
|
|
|
TrackChangesClient.getUpdates @project_id, @doc_id, { to: @toVersion, limit: 2 }, (error, body) =>
|
2014-03-05 10:59:40 -05:00
|
|
|
throw error if error?
|
|
|
|
@updates = body.updates
|
|
|
|
done()
|
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
after: () ->
|
|
|
|
MockWebApi.getUser.restore()
|
|
|
|
|
|
|
|
it "should fetch the user details from the web api", ->
|
|
|
|
MockWebApi.getUser
|
|
|
|
.calledWith(@user_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return the updates", ->
|
2014-03-05 10:59:40 -05:00
|
|
|
expect(@updates).to.deep.equal [{
|
|
|
|
meta:
|
|
|
|
start_ts: @to
|
|
|
|
end_ts: @to
|
2014-03-06 13:04:00 -05:00
|
|
|
user: @user
|
2014-03-06 06:00:49 -05:00
|
|
|
v: 5
|
2014-03-05 10:59:40 -05:00
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
start_ts: @to - 2 * @minutes
|
|
|
|
end_ts: @to - 2 * @minutes
|
2014-03-06 13:04:00 -05:00
|
|
|
user: @user
|
2014-03-06 06:00:49 -05:00
|
|
|
v: 4
|
2014-03-05 10:59:40 -05:00
|
|
|
}]
|