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

49 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2014-02-12 05:40:42 -05:00
require('coffee-script')
assert = require('assert')
should = require('chai').should()
path = require('path')
modulePath = path.join __dirname, '../../../../app/js/RedisManager.js'
keys = require(path.join __dirname, '../../../../app/js/RedisKeyBuilder.js')
SandboxedModule = require('sandboxed-module')
2014-02-12 05:40:42 -05:00
describe 'RedisManager.getCountOfDocsInMemory', ()->
2014-02-12 05:40:42 -05:00
project_id = "12345"
doc_id1 = "docid1"
doc_id2 = "docid2"
doc_id3 = "docid3"
redisMemory = {}
redisManager = undefined
beforeEach (done)->
mocks =
"./ZipManager": {}
2014-02-12 05:40:42 -05:00
"logger-sharelatex": log:->
2014-10-07 07:08:36 -04:00
"redis-sharelatex":
2014-02-12 05:40:42 -05:00
createClient : ()->
auth:->
smembers:(key, callback)->
callback(null, redisMemory[key])
multi: ()->
set:(key, value)->
redisMemory[key] = value
sadd:(key, value)->
if !redisMemory[key]?
redisMemory[key] = []
redisMemory[key].push value
del:()->
exec:(callback)->
callback()
redisManager = SandboxedModule.require(modulePath, requires: mocks)
2014-02-12 05:40:42 -05:00
redisManager.putDocInMemory project_id, doc_id1, 0, ["line"], ->
redisManager.putDocInMemory project_id, doc_id2, 0, ["ledf"], ->
redisManager.putDocInMemory project_id, doc_id3, 0, ["ledf"], ->
done()
it 'should return total', (done)->
redisManager.getCountOfDocsInMemory (err, count)->
assert.equal count, 3
done()