CheckingTheLock.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. const sinon = require('sinon')
  15. const assert = require('assert')
  16. const path = require('path')
  17. const modulePath = path.join(__dirname, '../../../../app/js/LockManager.js')
  18. const project_id = 1234
  19. const doc_id = 5678
  20. const blockingKey = `Blocking:${doc_id}`
  21. const SandboxedModule = require('sandboxed-module')
  22. describe('LockManager - checking the lock', function () {
  23. let Profiler
  24. const existsStub = sinon.stub()
  25. const mocks = {
  26. '@overleaf/redis-wrapper': {
  27. createClient() {
  28. return {
  29. auth() {},
  30. exists: existsStub
  31. }
  32. }
  33. },
  34. './Metrics': { inc() {} },
  35. './Profiler': (Profiler = (function () {
  36. Profiler = class Profiler {
  37. static initClass() {
  38. this.prototype.log = sinon.stub().returns({ end: sinon.stub() })
  39. this.prototype.end = sinon.stub()
  40. }
  41. }
  42. Profiler.initClass()
  43. return Profiler
  44. })())
  45. }
  46. const LockManager = SandboxedModule.require(modulePath, { requires: mocks })
  47. it('should return true if the key does not exists', function (done) {
  48. existsStub.yields(null, '0')
  49. return LockManager.checkLock(doc_id, (err, free) => {
  50. free.should.equal(true)
  51. return done()
  52. })
  53. })
  54. return it('should return false if the key does exists', function (done) {
  55. existsStub.yields(null, '1')
  56. return LockManager.checkLock(doc_id, (err, free) => {
  57. free.should.equal(false)
  58. return done()
  59. })
  60. })
  61. })