2014-01-27 11:26:58 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
2014-03-05 10:59:40 -05:00
|
|
|
modulePath = "../../../../app/js/UpdatesManager.js"
|
2014-01-27 11:26:58 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
2014-03-05 10:59:40 -05:00
|
|
|
describe "UpdatesManager", ->
|
2014-01-27 11:26:58 -05:00
|
|
|
beforeEach ->
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager = SandboxedModule.require modulePath, requires:
|
2014-01-27 11:26:58 -05:00
|
|
|
"./UpdateCompressor": @UpdateCompressor = {}
|
2014-02-24 12:43:27 -05:00
|
|
|
"./MongoManager" : @MongoManager = {}
|
2014-02-25 11:48:42 -05:00
|
|
|
"./RedisManager" : @RedisManager = {}
|
2014-02-26 05:55:20 -05:00
|
|
|
"./LockManager" : @LockManager = {}
|
2014-03-06 13:04:00 -05:00
|
|
|
"./WebApiManager": @WebApiManager = {}
|
2014-03-05 08:22:38 -05:00
|
|
|
"logger-sharelatex": { log: sinon.stub(), error: sinon.stub() }
|
2014-01-27 11:26:58 -05:00
|
|
|
@doc_id = "doc-id-123"
|
|
|
|
@callback = sinon.stub()
|
|
|
|
|
2014-02-25 11:48:42 -05:00
|
|
|
describe "compressAndSaveRawUpdates", ->
|
|
|
|
describe "when there are no raw ops", ->
|
|
|
|
beforeEach ->
|
|
|
|
@MongoManager.popLastCompressedUpdate = sinon.stub()
|
|
|
|
@MongoManager.insertCompressedUpdates = sinon.stub()
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates @doc_id, [], @callback
|
2014-01-27 11:26:58 -05:00
|
|
|
|
2014-02-25 11:48:42 -05:00
|
|
|
it "should not need to access the database", ->
|
|
|
|
@MongoManager.popLastCompressedUpdate.called.should.equal false
|
|
|
|
@MongoManager.insertCompressedUpdates.called.should.equal false
|
2014-01-27 11:26:58 -05:00
|
|
|
|
2014-02-25 11:48:42 -05:00
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2014-01-27 11:26:58 -05:00
|
|
|
|
2014-02-25 11:48:42 -05:00
|
|
|
describe "when there is no compressed history to begin with", ->
|
2014-02-25 07:27:42 -05:00
|
|
|
beforeEach ->
|
|
|
|
@rawUpdates = [{ v: 12, op: "mock-op-12" }, { v: 13, op: "mock-op-13" }]
|
2014-02-25 11:48:42 -05:00
|
|
|
@compressedUpdates = { v: 13, op: "compressed-op-12" }
|
|
|
|
|
|
|
|
@MongoManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, null)
|
|
|
|
@MongoManager.insertCompressedUpdates = sinon.stub().callsArg(2)
|
|
|
|
@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
2014-02-25 07:27:42 -05:00
|
|
|
|
|
|
|
it "should try to pop the last compressed op", ->
|
|
|
|
@MongoManager.popLastCompressedUpdate
|
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
2014-02-25 11:48:42 -05:00
|
|
|
it "should compress the raw ops", ->
|
2014-02-25 07:27:42 -05:00
|
|
|
@UpdateCompressor.compressRawUpdates
|
2014-02-25 11:48:42 -05:00
|
|
|
.calledWith(null, @rawUpdates)
|
2014-02-25 07:27:42 -05:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should save the compressed ops", ->
|
|
|
|
@MongoManager.insertCompressedUpdates
|
|
|
|
.calledWith(@doc_id, @compressedUpdates)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
2014-02-25 11:48:42 -05:00
|
|
|
describe "when the raw ops need appending to existing history", ->
|
2014-02-25 07:27:42 -05:00
|
|
|
beforeEach ->
|
2014-02-25 11:48:42 -05:00
|
|
|
@lastCompressedUpdate = { v: 11, op: "compressed-op-11" }
|
|
|
|
@compressedUpdates = { v: 13, op: "compressed-op-12" }
|
|
|
|
|
|
|
|
@MongoManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @lastCompressedUpdate)
|
|
|
|
@MongoManager.insertCompressedUpdates = sinon.stub().callsArg(2)
|
|
|
|
@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
|
|
|
|
|
|
|
|
describe "when the raw ops start where the existing history ends", ->
|
|
|
|
beforeEach ->
|
|
|
|
@rawUpdates = [{ v: 12, op: "mock-op-12" }, { v: 13, op: "mock-op-13" }]
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
2014-02-25 11:48:42 -05:00
|
|
|
|
|
|
|
it "should try to pop the last compressed op", ->
|
|
|
|
@MongoManager.popLastCompressedUpdate
|
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should compress the last compressed op and the raw ops", ->
|
|
|
|
@UpdateCompressor.compressRawUpdates
|
|
|
|
.calledWith(@lastCompressedUpdate, @rawUpdates)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should save the compressed ops", ->
|
|
|
|
@MongoManager.insertCompressedUpdates
|
|
|
|
.calledWith(@doc_id, @compressedUpdates)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "when some raw ops are passed that have already been compressed", ->
|
|
|
|
beforeEach ->
|
|
|
|
@rawUpdates = [{ v: 10, op: "mock-op-10" }, { v: 11, op: "mock-op-11"}, { v: 12, op: "mock-op-12" }, { v: 13, op: "mock-op-13" }]
|
|
|
|
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
2014-02-25 11:48:42 -05:00
|
|
|
|
|
|
|
it "should only compress the more recent raw ops", ->
|
|
|
|
@UpdateCompressor.compressRawUpdates
|
|
|
|
.calledWith(@lastCompressedUpdate, @rawUpdates.slice(-2))
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "when the raw ops do not follow from the last compressed op version", ->
|
|
|
|
beforeEach ->
|
|
|
|
@rawUpdates = [{ v: 13, op: "mock-op-13" }]
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
|
2014-02-25 11:48:42 -05:00
|
|
|
|
|
|
|
it "should call the callback with an error", ->
|
|
|
|
@callback
|
|
|
|
.calledWith(new Error("Tried to apply raw op at version 13 to last compressed update with version 11"))
|
|
|
|
.should.equal true
|
|
|
|
|
2014-03-05 08:22:38 -05:00
|
|
|
it "should put the popped update back into mongo", ->
|
|
|
|
@MongoManager.insertCompressedUpdates.calledOnce.should.equal true
|
|
|
|
@MongoManager.insertCompressedUpdates
|
|
|
|
.calledWith(@doc_id, [@lastCompressedUpdate])
|
|
|
|
.should.equal true
|
|
|
|
|
2014-02-25 11:48:42 -05:00
|
|
|
describe "processUncompressedUpdates", ->
|
2014-02-26 06:18:26 -05:00
|
|
|
describe "when there is fewer than one batch to send", ->
|
|
|
|
beforeEach ->
|
|
|
|
@updates = ["mock-update"]
|
|
|
|
@RedisManager.getOldestRawUpdates = sinon.stub().callsArgWith(2, null, @updates)
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates = sinon.stub().callsArgWith(2)
|
2014-02-26 06:18:26 -05:00
|
|
|
@RedisManager.deleteOldestRawUpdates = sinon.stub().callsArg(2)
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.processUncompressedUpdates @doc_id, @callback
|
2014-02-26 06:18:26 -05:00
|
|
|
|
|
|
|
it "should get the oldest updates", ->
|
|
|
|
@RedisManager.getOldestRawUpdates
|
2014-03-05 10:59:40 -05:00
|
|
|
.calledWith(@doc_id, @UpdatesManager.REDIS_READ_BATCH_SIZE)
|
2014-02-26 06:18:26 -05:00
|
|
|
.should.equal true
|
2014-02-25 07:27:42 -05:00
|
|
|
|
2014-02-26 06:18:26 -05:00
|
|
|
it "should compress and save the updates", ->
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates
|
2014-02-26 06:18:26 -05:00
|
|
|
.calledWith(@doc_id, @updates)
|
|
|
|
.should.equal true
|
2014-02-25 07:27:42 -05:00
|
|
|
|
2014-02-26 06:18:26 -05:00
|
|
|
it "should delete the batch of uncompressed updates that was just processed", ->
|
|
|
|
@RedisManager.deleteOldestRawUpdates
|
2014-03-01 06:42:31 -05:00
|
|
|
.calledWith(@doc_id, @updates.length)
|
2014-02-26 06:18:26 -05:00
|
|
|
.should.equal true
|
2014-02-25 07:27:42 -05:00
|
|
|
|
2014-02-26 06:18:26 -05:00
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "when there are multiple batches to send", ->
|
|
|
|
beforeEach (done) ->
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.REDIS_READ_BATCH_SIZE = 2
|
2014-02-26 06:18:26 -05:00
|
|
|
@updates = ["mock-update-0", "mock-update-1", "mock-update-2", "mock-update-3", "mock-update-4"]
|
|
|
|
@redisArray = @updates.slice()
|
|
|
|
@RedisManager.getOldestRawUpdates = (doc_id, batchSize, callback = (error, updates) ->) =>
|
|
|
|
updates = @redisArray.slice(0, batchSize)
|
|
|
|
@redisArray = @redisArray.slice(batchSize)
|
|
|
|
callback null, updates
|
|
|
|
sinon.spy @RedisManager, "getOldestRawUpdates"
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates = sinon.stub().callsArgWith(2)
|
2014-02-26 06:18:26 -05:00
|
|
|
@RedisManager.deleteOldestRawUpdates = sinon.stub().callsArg(2)
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.processUncompressedUpdates @doc_id, (args...) =>
|
2014-02-26 06:18:26 -05:00
|
|
|
@callback(args...)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should get the oldest updates in three batches ", ->
|
|
|
|
@RedisManager.getOldestRawUpdates.callCount.should.equal 3
|
|
|
|
|
|
|
|
it "should compress and save the updates in batches", ->
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates
|
2014-02-26 06:18:26 -05:00
|
|
|
.calledWith(@doc_id, @updates.slice(0,2))
|
|
|
|
.should.equal true
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates
|
2014-02-26 06:18:26 -05:00
|
|
|
.calledWith(@doc_id, @updates.slice(2,4))
|
|
|
|
.should.equal true
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.compressAndSaveRawUpdates
|
2014-02-26 06:18:26 -05:00
|
|
|
.calledWith(@doc_id, @updates.slice(4,5))
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should delete the batches of uncompressed updates", ->
|
|
|
|
@RedisManager.deleteOldestRawUpdates.callCount.should.equal 3
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2014-01-27 11:26:58 -05:00
|
|
|
|
2014-02-26 05:55:20 -05:00
|
|
|
describe "processCompressedUpdatesWithLock", ->
|
|
|
|
beforeEach ->
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.processUncompressedUpdates = sinon.stub().callsArg(2)
|
2014-02-26 05:55:20 -05:00
|
|
|
@LockManager.runWithLock = sinon.stub().callsArg(2)
|
2014-03-05 10:59:40 -05:00
|
|
|
@UpdatesManager.processUncompressedUpdatesWithLock @doc_id, @callback
|
2014-02-26 05:55:20 -05:00
|
|
|
|
|
|
|
it "should run processUncompressedUpdates with the lock", ->
|
|
|
|
@LockManager.runWithLock
|
|
|
|
.calledWith(
|
2014-02-26 07:11:45 -05:00
|
|
|
"HistoryLock:#{@doc_id}"
|
2014-02-26 05:55:20 -05:00
|
|
|
)
|
|
|
|
.should.equal true
|
2014-01-27 11:26:58 -05:00
|
|
|
|
2014-02-26 05:55:20 -05:00
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2014-03-05 10:59:40 -05:00
|
|
|
|
|
|
|
describe "getUpdates", ->
|
|
|
|
beforeEach ->
|
|
|
|
@updates = ["mock-updates"]
|
|
|
|
@options = { to: "mock-to", limit: "mock-limit" }
|
|
|
|
@MongoManager.getUpdates = sinon.stub().callsArgWith(2, null, @updates)
|
|
|
|
@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
|
|
|
|
@UpdatesManager.getUpdates @doc_id, @options, @callback
|
|
|
|
|
|
|
|
it "should process outstanding updates", ->
|
|
|
|
@UpdatesManager.processUncompressedUpdatesWithLock
|
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should get the updates from the database", ->
|
|
|
|
@MongoManager.getUpdates
|
|
|
|
.calledWith(@doc_id, @options)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return the updates", ->
|
|
|
|
@callback
|
|
|
|
.calledWith(null, @updates)
|
|
|
|
.should.equal true
|
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
describe "getUpdatesWithUserInfo", ->
|
|
|
|
beforeEach ->
|
|
|
|
@updates = ["mock-updates"]
|
|
|
|
@options = { to: "mock-to", limit: "mock-limit" }
|
|
|
|
@updatesWithUserInfo = ["updates-with-user-info"]
|
|
|
|
@UpdatesManager.getUpdates = sinon.stub().callsArgWith(2, null, @updates)
|
|
|
|
@UpdatesManager.fillUserInfo = sinon.stub().callsArgWith(1, null, @updatesWithUserInfo)
|
|
|
|
@UpdatesManager.getUpdatesWithUserInfo @doc_id, @options, @callback
|
|
|
|
|
|
|
|
it "should get the updates", ->
|
|
|
|
@UpdatesManager.getUpdates
|
|
|
|
.calledWith(@doc_id, @options)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should file the updates with the user info", ->
|
|
|
|
@UpdatesManager.fillUserInfo
|
|
|
|
.calledWith(@updates)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "shoudl return the updates with the filled details", ->
|
|
|
|
@callback.calledWith(null, @updatesWithUserInfo).should.equal true
|
|
|
|
|
2014-03-18 07:41:48 -04:00
|
|
|
describe "getSummarizedUpdates", ->
|
|
|
|
beforeEach ->
|
|
|
|
@to = 42
|
|
|
|
@limit = 10
|
|
|
|
@updates = ["mock-updates"]
|
|
|
|
@summarizedUpdates = ["summarized-updates"]
|
|
|
|
@UpdatesManager._summarizeUpdates = sinon.stub().returns(@summarizedUpdates)
|
|
|
|
@UpdatesManager.getUpdatesWithUserInfo = sinon.stub().callsArgWith(2, null, @updates)
|
|
|
|
@UpdatesManager.getSummarizedUpdates @doc_id, { to: @to, limit: @limit }, @callback
|
|
|
|
|
|
|
|
it "should get the updates", ->
|
|
|
|
@UpdatesManager.getUpdatesWithUserInfo
|
|
|
|
.calledWith(@doc_id, { to: @to, limit: @limit })
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should summarize the updates", ->
|
|
|
|
@UpdatesManager._summarizeUpdates
|
|
|
|
.calledWith(@updates)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the summarized updates", ->
|
|
|
|
@callback.calledWith(null, @summarizedUpdates).should.equal true
|
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
describe "fillUserInfo", ->
|
2014-03-11 07:45:25 -04:00
|
|
|
describe "with valid users", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
{ObjectId} = require "mongojs"
|
|
|
|
@user_id_1 = ObjectId().toString()
|
|
|
|
@user_id_2 = ObjectId().toString()
|
|
|
|
@updates = [{
|
|
|
|
meta:
|
|
|
|
user_id: @user_id_1
|
|
|
|
op: "mock-op-1"
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
user_id: @user_id_1
|
|
|
|
op: "mock-op-2"
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
user_id: @user_id_2
|
|
|
|
op: "mock-op-3"
|
|
|
|
}]
|
|
|
|
@user_info = {}
|
|
|
|
@user_info[@user_id_1] = email: "user1@sharelatex.com"
|
|
|
|
@user_info[@user_id_2] = email: "user2@sharelatex.com"
|
|
|
|
|
|
|
|
@WebApiManager.getUserInfo = (user_id, callback = (error, userInfo) ->) =>
|
|
|
|
callback null, @user_info[user_id]
|
|
|
|
sinon.spy @WebApiManager, "getUserInfo"
|
|
|
|
|
|
|
|
@UpdatesManager.fillUserInfo @updates, (error, @results) =>
|
|
|
|
done()
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2014-03-11 07:45:25 -04:00
|
|
|
it "should only call getUserInfo once for each user_id", ->
|
|
|
|
@WebApiManager.getUserInfo.calledTwice.should.equal true
|
|
|
|
@WebApiManager.getUserInfo
|
|
|
|
.calledWith(@user_id_1)
|
|
|
|
.should.equal true
|
|
|
|
@WebApiManager.getUserInfo
|
|
|
|
.calledWith(@user_id_2)
|
|
|
|
.should.equal true
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2014-03-11 07:45:25 -04:00
|
|
|
it "should return the updates with the user info filled", ->
|
|
|
|
expect(@results).to.deep.equal [{
|
|
|
|
meta:
|
|
|
|
user:
|
|
|
|
email: "user1@sharelatex.com"
|
|
|
|
op: "mock-op-1"
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
user:
|
|
|
|
email: "user1@sharelatex.com"
|
|
|
|
op: "mock-op-2"
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
user:
|
|
|
|
email: "user2@sharelatex.com"
|
|
|
|
op: "mock-op-3"
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
|
|
describe "with invalid user ids", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@updates = [{
|
|
|
|
meta:
|
|
|
|
user_id: null
|
|
|
|
op: "mock-op-1"
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
user_id: "anonymous-user"
|
|
|
|
op: "mock-op-2"
|
|
|
|
}]
|
|
|
|
@WebApiManager.getUserInfo = (user_id, callback = (error, userInfo) ->) =>
|
|
|
|
callback null, @user_info[user_id]
|
|
|
|
sinon.spy @WebApiManager, "getUserInfo"
|
|
|
|
|
|
|
|
@UpdatesManager.fillUserInfo @updates, (error, @results) =>
|
|
|
|
done()
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2014-03-11 07:45:25 -04:00
|
|
|
it "should not call getUserInfo", ->
|
|
|
|
@WebApiManager.getUserInfo.called.should.equal false
|
|
|
|
|
|
|
|
it "should return the updates without the user info filled", ->
|
|
|
|
expect(@results).to.deep.equal [{
|
|
|
|
meta: {}
|
|
|
|
op: "mock-op-1"
|
|
|
|
}, {
|
|
|
|
meta: {}
|
|
|
|
op: "mock-op-2"
|
|
|
|
}]
|
2014-03-06 13:04:00 -05:00
|
|
|
|
2014-03-18 07:41:48 -04:00
|
|
|
describe "_buildUpdatesView", ->
|
|
|
|
beforeEach ->
|
|
|
|
@now = Date.now()
|
|
|
|
|
|
|
|
it "should concat updates that are close in time", ->
|
|
|
|
expect(@UpdatesManager._summarizeUpdates [{
|
|
|
|
meta:
|
|
|
|
user: @user_2 = { id: "mock-user-2" }
|
|
|
|
start_ts: @now + 20
|
|
|
|
end_ts: @now + 30
|
|
|
|
v: 5
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
user: @user_1 = { id: "mock-user-1" }
|
|
|
|
start_ts: @now
|
|
|
|
end_ts: @now + 10
|
|
|
|
v: 4
|
|
|
|
}]).to.deep.equal [{
|
|
|
|
meta:
|
|
|
|
users: [@user_1, @user_2]
|
|
|
|
start_ts: @now
|
|
|
|
end_ts: @now + 30
|
|
|
|
fromV: 4
|
|
|
|
toV: 5
|
|
|
|
}]
|
|
|
|
|
|
|
|
it "should leave updates that are far apart in time", ->
|
|
|
|
oneDay = 1000 * 60 * 60 * 24
|
|
|
|
expect(@UpdatesManager._summarizeUpdates [{
|
|
|
|
meta:
|
|
|
|
user: @user_2 = { id: "mock-user-2" }
|
|
|
|
start_ts: @now + oneDay
|
|
|
|
end_ts: @now + oneDay + 10
|
|
|
|
v: 5
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
user: @user_1 = { id: "mock-user-2" }
|
|
|
|
start_ts: @now
|
|
|
|
end_ts: @now + 10
|
|
|
|
v: 4
|
|
|
|
}]).to.deep.equal [{
|
|
|
|
meta:
|
|
|
|
users: [@user_2]
|
|
|
|
start_ts: @now + oneDay
|
|
|
|
end_ts: @now + oneDay + 10
|
|
|
|
fromV: 5
|
|
|
|
toV: 5
|
|
|
|
}, {
|
|
|
|
meta:
|
|
|
|
users: [@user_1]
|
|
|
|
start_ts: @now
|
|
|
|
end_ts: @now + 10
|
|
|
|
fromV: 4
|
|
|
|
toV: 4
|
|
|
|
}]
|
2014-03-06 13:04:00 -05:00
|
|
|
|
|
|
|
|