2014-02-12 05:40:42 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
2014-02-10 10:17:08 -05:00
|
|
|
modulePath = "../../../../app/js/RedisManager.js"
|
2014-02-12 05:40:42 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
2014-02-10 10:17:08 -05:00
|
|
|
describe "RedisManager.pushDocOp", ->
|
2014-02-12 05:40:42 -05:00
|
|
|
beforeEach ->
|
|
|
|
@RedisManager = SandboxedModule.require modulePath, requires:
|
2014-10-07 07:08:36 -04:00
|
|
|
"redis-sharelatex": createClient: () =>
|
2015-03-25 12:53:20 -04:00
|
|
|
@rclient ?=
|
2014-02-10 10:17:08 -05:00
|
|
|
auth: () ->
|
|
|
|
multi: () => @rclient
|
|
|
|
"logger-sharelatex": @logger = {log: sinon.stub()}
|
2014-02-12 05:40:42 -05:00
|
|
|
@doc_id = "doc-id-123"
|
2014-02-10 10:17:08 -05:00
|
|
|
@callback = sinon.stub()
|
|
|
|
@rclient.rpush = sinon.stub()
|
|
|
|
@rclient.expire = sinon.stub()
|
|
|
|
@rclient.incr = sinon.stub()
|
|
|
|
@rclient.ltrim = sinon.stub()
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
|
|
beforeEach ->
|
|
|
|
@op = { op: [{ i: "foo", p: 4 }] }
|
|
|
|
@version = 42
|
|
|
|
_ = null
|
|
|
|
@rclient.exec = sinon.stub().callsArgWith(0, null, [_, _, _, @version])
|
|
|
|
@RedisManager.pushDocOp @doc_id, @op, @callback
|
|
|
|
|
|
|
|
it "should push the doc op into the doc ops list", ->
|
|
|
|
@rclient.rpush
|
|
|
|
.calledWith("DocOps:#{@doc_id}", JSON.stringify(@op))
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should renew the expiry ttl on the doc ops array", ->
|
|
|
|
@rclient.expire
|
|
|
|
.calledWith("DocOps:#{@doc_id}", @RedisManager.DOC_OPS_TTL)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should truncate the list to 100 members", ->
|
|
|
|
@rclient.ltrim
|
|
|
|
.calledWith("DocOps:#{@doc_id}", -@RedisManager.DOC_OPS_MAX_LENGTH, -1)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should increment the version number", ->
|
|
|
|
@rclient.incr
|
|
|
|
.calledWith("DocVersion:#{@doc_id}")
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the version number", ->
|
|
|
|
@callback.calledWith(null, parseInt(@version, 10)).should.equal true
|
|
|
|
|
|
|
|
|
2014-02-12 05:40:42 -05:00
|
|
|
|