2014-02-12 05:40:42 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/DocOpsManager.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "DocOpsManager", ->
|
|
|
|
beforeEach ->
|
2014-05-14 08:28:17 -04:00
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@project_id = ObjectId().toString()
|
2014-02-12 05:40:42 -05:00
|
|
|
@callback = sinon.stub()
|
|
|
|
@DocOpsManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"./RedisManager": @RedisManager = {}
|
2014-02-28 13:29:05 -05:00
|
|
|
"./TrackChangesManager": @TrackChangesManager = {}
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe "getPreviousDocOps", ->
|
|
|
|
beforeEach ->
|
|
|
|
@ops = [ "mock-op-1", "mock-op-2" ]
|
|
|
|
@start = 30
|
|
|
|
@end = 32
|
|
|
|
@RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
|
|
|
|
@DocOpsManager.getPreviousDocOps @project_id, @doc_id, @start, @end, @callback
|
|
|
|
|
|
|
|
it "should get the previous doc ops", ->
|
|
|
|
@RedisManager.getPreviousDocOps
|
|
|
|
.calledWith(@doc_id, @start, @end)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the ops", ->
|
|
|
|
@callback.calledWith(null, @ops).should.equal true
|
|
|
|
|
2014-02-24 11:52:12 -05:00
|
|
|
describe "pushDocOp", ->
|
|
|
|
beforeEach ->
|
|
|
|
@op = "mock-op"
|
2014-02-26 09:49:52 -05:00
|
|
|
@RedisManager.pushDocOp = sinon.stub().callsArgWith(2, null, @version = 42)
|
2014-03-19 11:56:44 -04:00
|
|
|
@TrackChangesManager.pushUncompressedHistoryOp = sinon.stub().callsArg(3)
|
2014-02-24 11:52:12 -05:00
|
|
|
@DocOpsManager.pushDocOp @project_id, @doc_id, @op, @callback
|
|
|
|
|
|
|
|
it "should push the op in to the docOps list", ->
|
|
|
|
@RedisManager.pushDocOp
|
|
|
|
.calledWith(@doc_id, @op)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should push the op into the pushUncompressedHistoryOp", ->
|
2014-02-28 13:29:05 -05:00
|
|
|
@TrackChangesManager.pushUncompressedHistoryOp
|
2014-03-19 11:56:44 -04:00
|
|
|
.calledWith(@project_id, @doc_id, @op)
|
2014-02-24 11:52:12 -05:00
|
|
|
.should.equal true
|
|
|
|
|
2014-02-26 09:49:52 -05:00
|
|
|
it "should call the callback with the version", ->
|
|
|
|
@callback.calledWith(null, @version).should.equal true
|
2014-02-24 11:52:12 -05:00
|
|
|
|