2016-11-28 05:14:42 -05:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
async = require "async"
|
|
|
|
rclient = require("redis").createClient()
|
|
|
|
|
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
|
|
|
DocUpdaterClient = require "./helpers/DocUpdaterClient"
|
|
|
|
|
|
|
|
describe "Track changes", ->
|
|
|
|
describe "tracking changes", ->
|
|
|
|
before (done) ->
|
|
|
|
@project_id = DocUpdaterClient.randomId()
|
2016-12-02 06:04:21 -05:00
|
|
|
@user_id = DocUpdaterClient.randomId()
|
2016-11-28 05:14:42 -05:00
|
|
|
@doc = {
|
2016-12-02 06:04:21 -05:00
|
|
|
id: DocUpdaterClient.randomId()
|
|
|
|
lines: ["aaa"]
|
2016-11-28 05:14:42 -05:00
|
|
|
}
|
2016-12-02 06:04:21 -05:00
|
|
|
@updates = [{
|
2016-11-28 05:14:42 -05:00
|
|
|
doc: @doc.id
|
2016-12-02 06:04:21 -05:00
|
|
|
op: [{ i: "123", p: 1 }]
|
2016-11-28 05:14:42 -05:00
|
|
|
v: 0
|
2016-12-02 06:04:21 -05:00
|
|
|
meta: { user_id: @user_id }
|
|
|
|
}, {
|
|
|
|
doc: @doc.id
|
|
|
|
op: [{ i: "456", p: 5 }]
|
|
|
|
v: 1
|
|
|
|
meta: { user_id: @user_id, tc: 1 }
|
|
|
|
}, {
|
|
|
|
doc: @doc.id
|
|
|
|
op: [{ d: "12", p: 1 }]
|
|
|
|
v: 2
|
|
|
|
meta: { user_id: @user_id }
|
|
|
|
}]
|
2016-11-28 05:14:42 -05:00
|
|
|
MockWebApi.insertDoc @project_id, @doc.id, {
|
|
|
|
lines: @doc.lines
|
|
|
|
version: 0
|
|
|
|
}
|
2016-12-02 06:04:21 -05:00
|
|
|
jobs = []
|
|
|
|
for update in @updates
|
|
|
|
do (update) =>
|
|
|
|
jobs.push (callback) => DocUpdaterClient.sendUpdate @project_id, @doc.id, update, callback
|
2016-11-28 05:14:42 -05:00
|
|
|
DocUpdaterClient.preloadDoc @project_id, @doc.id, (error) =>
|
|
|
|
throw error if error?
|
2016-12-02 06:04:21 -05:00
|
|
|
async.series jobs, (error) ->
|
2016-11-28 05:14:42 -05:00
|
|
|
throw error if error?
|
2016-12-02 06:04:21 -05:00
|
|
|
setTimeout done, 200
|
2016-11-28 05:14:42 -05:00
|
|
|
|
|
|
|
it "should set the updated track changes entries in redis", (done) ->
|
2016-12-02 06:37:27 -05:00
|
|
|
DocUpdaterClient.getDoc @project_id, @doc.id, (error, res, data) =>
|
2016-11-28 05:14:42 -05:00
|
|
|
throw error if error?
|
2016-12-02 06:37:27 -05:00
|
|
|
entries = data.track_changes_entries
|
2016-11-28 05:14:42 -05:00
|
|
|
change = entries.changes[0]
|
2016-12-02 06:04:21 -05:00
|
|
|
change.op.should.deep.equal { i: "456", p: 3 }
|
2016-11-28 05:14:42 -05:00
|
|
|
change.metadata.user_id.should.equal @user_id
|
|
|
|
done()
|
|
|
|
|