CheckingTheLock.coffee 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. require('coffee-script')
  2. sinon = require('sinon')
  3. assert = require('assert')
  4. path = require('path')
  5. modulePath = path.join __dirname, '../../../../app/js/LockManager.js'
  6. project_id = 1234
  7. doc_id = 5678
  8. blockingKey = "Blocking:#{doc_id}"
  9. SandboxedModule = require('sandboxed-module')
  10. describe 'LockManager - checking the lock', ()->
  11. existsStub = sinon.stub()
  12. mocks =
  13. "logger-sharelatex": log:->
  14. "redis-sharelatex":
  15. createClient : ()->
  16. auth:->
  17. exists: existsStub
  18. "./Metrics": {inc: () ->}
  19. "./Profiler": class Profiler
  20. log: sinon.stub().returns { end: sinon.stub() }
  21. end: sinon.stub()
  22. LockManager = SandboxedModule.require(modulePath, requires: mocks)
  23. it 'should return true if the key does not exists', (done)->
  24. existsStub.yields(null, "0")
  25. LockManager.checkLock doc_id, (err, free)->
  26. free.should.equal true
  27. done()
  28. it 'should return false if the key does exists', (done)->
  29. existsStub.yields(null, "1")
  30. LockManager.checkLock doc_id, (err, free)->
  31. free.should.equal false
  32. done()