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

43 lines
1.1 KiB
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.js"
2014-02-12 05:40:42 -05:00
SandboxedModule = require('sandboxed-module')
2014-10-07 07:08:36 -04:00
describe 'RedisManager.getDoc', ->
2014-02-12 05:40:42 -05:00
beforeEach ->
@rclient = {}
@rclient.auth = () ->
@rclient.multi = () => @rclient
@RedisManager = SandboxedModule.require modulePath, requires:
"logger-sharelatex": {}
2014-10-07 07:08:36 -04:00
"redis-sharelatex": @redis =
2014-02-12 05:40:42 -05:00
createClient: () => @rclient
@doc_id = "doc-id-123"
@lines = ["one", "two", "three"]
@jsonlines = JSON.stringify @lines
@version = 42
@callback = sinon.stub()
@rclient.get = sinon.stub()
@rclient.exec = sinon.stub().callsArgWith(0, null, [@jsonlines, @version])
@RedisManager.getDoc @doc_id, @callback
it "should get the lines from redis", ->
@rclient.get
.calledWith("doclines:#{@doc_id}")
.should.equal true
it "should get the version from", ->
@rclient.get
.calledWith("DocVersion:#{@doc_id}")
.should.equal true
it 'should return the document', ->
@callback
.calledWith(null, @lines, @version)
.should.equal true