2014-02-24 11:37:45 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/RedisManager.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "RedisManager.pushUncompressedHistoryOp", ->
|
|
|
|
beforeEach ->
|
|
|
|
@RedisManager = SandboxedModule.require modulePath, requires:
|
2014-09-26 12:57:15 -04:00
|
|
|
"redis-sharelatex": createClient: () =>
|
2014-02-24 11:37:45 -05:00
|
|
|
@rclient =
|
|
|
|
auth: () ->
|
|
|
|
multi: () => @rclient
|
|
|
|
"logger-sharelatex": @logger = {log: sinon.stub()}
|
|
|
|
@doc_id = "doc-id-123"
|
2014-03-21 08:41:05 -04:00
|
|
|
@project_id = "project-id-123"
|
2014-02-24 11:37:45 -05:00
|
|
|
@callback = sinon.stub()
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
|
|
beforeEach ->
|
|
|
|
@op = { op: [{ i: "foo", p: 4 }] }
|
2014-03-21 08:41:05 -04:00
|
|
|
@rclient.rpush = sinon.stub()
|
|
|
|
@rclient.sadd = sinon.stub()
|
|
|
|
@rclient.exec = sinon.stub().callsArgWith(0, null, [@length = 42, "1"])
|
|
|
|
@RedisManager.pushUncompressedHistoryOp @project_id, @doc_id, @op, @callback
|
2014-02-24 11:37:45 -05:00
|
|
|
|
|
|
|
it "should push the doc op into the doc ops list", ->
|
|
|
|
@rclient.rpush
|
|
|
|
.calledWith("UncompressedHistoryOps:#{@doc_id}", JSON.stringify(@op))
|
|
|
|
.should.equal true
|
|
|
|
|
2014-03-21 08:41:05 -04:00
|
|
|
it "should add the doc_id to the set of which records the project docs", ->
|
|
|
|
@rclient.sadd
|
|
|
|
.calledWith("DocsWithHistoryOps:#{@project_id}", @doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
2014-02-28 13:29:05 -05:00
|
|
|
it "should call the callback with the length", ->
|
|
|
|
@callback.calledWith(null, @length).should.equal true
|
2014-02-24 11:37:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
|