overleaf/services/document-updater/test/unit/coffee/GettingListOfPendingUpdates.coffee

43 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2014-02-12 05:40:42 -05:00
assert = require('assert')
should = require('chai').should()
path = require('path')
modulePath = path.join __dirname, '../../../app/js/RedisManager.js'
_ = require('underscore')
SandboxedModule = require('sandboxed-module')
2014-02-12 05:40:42 -05:00
keys = require(path.join __dirname, '../../../app/js/RedisKeyBuilder.js')
describe 'getting entire list of pending updates', ()->
doc_id = 123
redisMemory = {}
correctUpdates = [{"update1"}, {"update2"}, {"update3"}]
jsonCorrectUpdates = _.map correctUpdates, (d)-> JSON.stringify d
redisMemory[keys.pendingUpdates(doc_id:doc_id)] = jsonCorrectUpdates
redisMemory[keys.pendingUpdates(doc_id:"notThis")] = JSON.stringify([{"updatex"}, {"updatez"}])
redisReturn = []
mocks =
2014-10-07 07:08:36 -04:00
"redis-sharelatex":
2014-02-12 05:40:42 -05:00
createClient: ()->
auth:->
multi: ()->
lrange:(key, start, end)->
key.should.equal(keys.pendingUpdates(doc_id:doc_id))
start.should.equal(0)
end.should.equal(-1)
redisReturn.push(redisMemory[key])
del : (key)->
key.should.equal(keys.pendingUpdates(doc_id:doc_id))
redisReturn.push(1)
exec: (callback)->
callback(null, redisReturn)
redisManager = SandboxedModule.require(modulePath, requires: mocks)
2014-02-12 05:40:42 -05:00
it 'should have 3 elements in array', (done)->
redisManager.getPendingUpdatesForDoc doc_id, (err, listOfUpdates)->
listOfUpdates.length.should.equal(3)
done()