overleaf/services/document-updater/test/unit/coffee/RedisManager/prependDocOpsTests.coffee

33 lines
860 B
CoffeeScript
Raw Normal View History

2014-02-12 05:40:42 -05:00
sinon = require('sinon')
chai = require('chai')
should = chai.should()
modulePath = "../../../../app/js/RedisManager"
SandboxedModule = require('sandboxed-module')
describe "RedisManager.clearDocFromPendingUpdatesSet", ->
beforeEach ->
@doc_id = "document-id"
@callback = sinon.stub()
@RedisManager = SandboxedModule.require modulePath, requires:
"redis" : createClient: () =>
@rclient = auth:->
@rclient.lpush = sinon.stub().callsArg(2)
@ops = [
{ "mock" : "op-1" },
{ "mock" : "op-2" }
]
@reversedJsonOps = @ops.map((op) -> JSON.stringify op).reverse()
@RedisManager.prependDocOps(@doc_id, @ops, @callback)
it "should push the reversed JSONed ops", ->
@rclient.lpush
.calledWith("DocOps:#{@doc_id}", @reversedJsonOps)
.should.equal true
it "should return the callback", ->
@callback.called.should.equal true