overleaf/services/document-updater/test/unit/coffee/LockManager/CheckingTheLock.coffee

35 lines
932 B
CoffeeScript
Raw Normal View History

2014-02-12 05:40:42 -05:00
require('coffee-script')
sinon = require('sinon')
assert = require('assert')
path = require('path')
modulePath = path.join __dirname, '../../../../app/js/LockManager.js'
project_id = 1234
doc_id = 5678
blockingKey = "Blocking:#{doc_id}"
SandboxedModule = require('sandboxed-module')
2014-02-12 05:40:42 -05:00
describe 'LockManager - checking the lock', ()->
2014-02-12 05:40:42 -05:00
existsStub = sinon.stub()
mocks =
"logger-sharelatex": log:->
2016-07-06 06:50:02 -04:00
"redis-sharelatex":
2014-02-12 05:40:42 -05:00
createClient : ()->
auth:->
exists: existsStub
"./Metrics": {inc: () ->}
LockManager = SandboxedModule.require(modulePath, requires: mocks)
2014-02-12 05:40:42 -05:00
it 'should return true if the key does not exists', (done)->
existsStub.yields(null, "0")
2014-02-12 05:40:42 -05:00
LockManager.checkLock doc_id, (err, free)->
free.should.equal true
done()
it 'should return false if the key does exists', (done)->
existsStub.yields(null, "1")
2014-02-12 05:40:42 -05:00
LockManager.checkLock doc_id, (err, free)->
free.should.equal false
done()