2014-02-12 05:40:42 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
2016-08-23 11:00:46 -04:00
|
|
|
expect = chai.expect
|
2014-02-12 05:40:42 -05:00
|
|
|
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": {}
|
2016-01-20 12:36:06 -05:00
|
|
|
"logger-sharelatex": @logger = {error: sinon.stub()}
|
2016-08-23 11:00:46 -04:00
|
|
|
@db = new @ShareJsDB()
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe "writing an op", ->
|
|
|
|
beforeEach ->
|
|
|
|
@version = 42
|
|
|
|
@opData.v = @version
|
2016-08-23 11:00:46 -04:00
|
|
|
@db.writeOp @doc_key, @opData, @callback
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2016-08-23 11:00:46 -04:00
|
|
|
it "should write into appliedOps", ->
|
|
|
|
expect(@db.appliedOps[@doc_key]).to.deep.equal [@opData]
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it "should call the callback without an error", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
(@callback.args[0][0]?).should.equal false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|