2014-02-12 05:40:42 -05:00
|
|
|
require('coffee-script')
|
|
|
|
assert = require('assert')
|
|
|
|
path = require('path')
|
2016-01-20 12:36:06 -05:00
|
|
|
modulePath = path.join __dirname, '../../../../app/js/RedisManager.js'
|
|
|
|
keys = require(path.join __dirname, '../../../../app/js/RedisKeyBuilder.js')
|
2014-02-12 05:40:42 -05:00
|
|
|
project_id = 1234
|
|
|
|
doc_id = 5678
|
2014-05-14 09:16:27 -04:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2016-01-20 12:36:06 -05:00
|
|
|
describe 'RedisManager.putDocInMemory', ()->
|
2014-02-12 05:40:42 -05:00
|
|
|
lines = ["this is one line", "and another line"]
|
|
|
|
version = 42
|
|
|
|
|
|
|
|
potentialSets = {}
|
|
|
|
potentialSets[keys.docLines(doc_id:doc_id)] = lines
|
|
|
|
potentialSets[keys.projectKey(doc_id:doc_id)] = project_id
|
|
|
|
potentialSets[keys.docVersion(doc_id:doc_id)] = version
|
|
|
|
|
|
|
|
potentialSAdds = {}
|
|
|
|
potentialSAdds[keys.docsInProject(project_id:project_id)] = doc_id
|
|
|
|
|
2016-06-01 06:40:12 -04:00
|
|
|
rclient =
|
|
|
|
auth:->
|
|
|
|
set:(key, value)->
|
|
|
|
result = potentialSets[key]
|
|
|
|
delete potentialSets[key]
|
|
|
|
if key == keys.docLines(doc_id:doc_id)
|
|
|
|
value = JSON.parse(value)
|
|
|
|
assert.deepEqual result, value
|
|
|
|
incr:()->
|
|
|
|
sadd:(key, value, cb)->
|
|
|
|
result = potentialSAdds[key]
|
|
|
|
delete potentialSAdds[key]
|
|
|
|
assert.equal result, value
|
|
|
|
cb()
|
|
|
|
del: (key) ->
|
|
|
|
result = potentialDels[key]
|
|
|
|
delete potentialDels[key]
|
|
|
|
assert.equal result, true
|
|
|
|
exec:(callback)->
|
|
|
|
callback()
|
|
|
|
rclient.multi = () -> rclient
|
2014-02-12 05:40:42 -05:00
|
|
|
mocks =
|
2016-01-20 12:36:06 -05:00
|
|
|
"./ZipManager": {}
|
2014-02-12 05:40:42 -05:00
|
|
|
"logger-sharelatex": log:->
|
2014-10-07 07:08:36 -04:00
|
|
|
"redis-sharelatex":
|
2016-06-01 06:40:12 -04:00
|
|
|
createClient : () -> rclient
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 09:16:27 -04:00
|
|
|
redisManager = SandboxedModule.require(modulePath, requires: mocks)
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it 'should put a all data into memory', (done)->
|
|
|
|
redisManager.putDocInMemory project_id, doc_id, lines, version, ()->
|
|
|
|
assert.deepEqual potentialSets, {}
|
|
|
|
assert.deepEqual potentialSAdds, {}
|
|
|
|
done()
|
|
|
|
|