2014-02-12 05:40:42 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/ShareJsDB.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "ShareJsDB.writeOps", ->
|
|
|
|
beforeEach ->
|
|
|
|
@project_id = "project-id"
|
|
|
|
@doc_id = "document-id"
|
|
|
|
@doc_key = "#{@project_id}:#{@doc_id}"
|
|
|
|
@callback = sinon.stub()
|
|
|
|
@opData =
|
|
|
|
op: {p: 20, t: "foo"}
|
|
|
|
meta: {source: "bar"}
|
|
|
|
@ShareJsDB = SandboxedModule.require modulePath, requires:
|
|
|
|
"./RedisManager": @RedisManager = {}
|
|
|
|
"./DocOpsManager": @DocOpsManager = {}
|
|
|
|
"./DocumentManager": {}
|
|
|
|
|
|
|
|
describe "writing an op", ->
|
|
|
|
beforeEach ->
|
|
|
|
@version = 42
|
|
|
|
@opData.v = @version
|
|
|
|
@DocOpsManager.pushDocOp = sinon.stub().callsArgWith(3, null, @version+1)
|
|
|
|
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
|
|
|
|
|
|
|
it "should write the op to redis", ->
|
|
|
|
@DocOpsManager.pushDocOp
|
2014-02-26 09:49:52 -05:00
|
|
|
.calledWith(@project_id, @doc_id, @opData)
|
2014-02-12 05:40:42 -05:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback without an error", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
(@callback.args[0][0]?).should.equal false
|
|
|
|
|
|
|
|
describe "writing an op at the wrong version", ->
|
|
|
|
beforeEach ->
|
|
|
|
@version = 42
|
|
|
|
@mismatch = 5
|
|
|
|
@opData.v = @version
|
|
|
|
@DocOpsManager.pushDocOp = sinon.stub().callsArgWith(3, null, @version + @mismatch)
|
|
|
|
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
|
|
|
|
|
|
|
it "should call the callback with an error", ->
|
2014-02-26 09:49:52 -05:00
|
|
|
@callback.calledWith(new Error()).should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|