CheckingTheLock.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS206: Consider reworking classes to avoid initClass
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. require('coffee-script')
  15. const sinon = require('sinon')
  16. const assert = require('assert')
  17. const path = require('path')
  18. const modulePath = path.join(__dirname, '../../../../app/js/LockManager.js')
  19. const project_id = 1234
  20. const doc_id = 5678
  21. const blockingKey = `Blocking:${doc_id}`
  22. const SandboxedModule = require('sandboxed-module')
  23. describe('LockManager - checking the lock', function () {
  24. let Profiler
  25. const existsStub = sinon.stub()
  26. const mocks = {
  27. 'logger-sharelatex': { log() {} },
  28. 'redis-sharelatex': {
  29. createClient() {
  30. return {
  31. auth() {},
  32. exists: existsStub
  33. }
  34. }
  35. },
  36. './Metrics': { inc() {} },
  37. './Profiler': (Profiler = (function () {
  38. Profiler = class Profiler {
  39. static initClass() {
  40. this.prototype.log = sinon.stub().returns({ end: sinon.stub() })
  41. this.prototype.end = sinon.stub()
  42. }
  43. }
  44. Profiler.initClass()
  45. return Profiler
  46. })())
  47. }
  48. const LockManager = SandboxedModule.require(modulePath, { requires: mocks })
  49. it('should return true if the key does not exists', function (done) {
  50. existsStub.yields(null, '0')
  51. return LockManager.checkLock(doc_id, (err, free) => {
  52. free.should.equal(true)
  53. return done()
  54. })
  55. })
  56. return it('should return false if the key does exists', function (done) {
  57. existsStub.yields(null, '1')
  58. return LockManager.checkLock(doc_id, (err, free) => {
  59. free.should.equal(false)
  60. return done()
  61. })
  62. })
  63. })