CheckingTheLock.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. 'logger-sharelatex': { log() {} },
  27. '@overleaf/redis-wrapper': {
  28. createClient() {
  29. return {
  30. auth() {},
  31. exists: existsStub
  32. }
  33. }
  34. },
  35. './Metrics': { inc() {} },
  36. './Profiler': (Profiler = (function () {
  37. Profiler = class Profiler {
  38. static initClass() {
  39. this.prototype.log = sinon.stub().returns({ end: sinon.stub() })
  40. this.prototype.end = sinon.stub()
  41. }
  42. }
  43. Profiler.initClass()
  44. return Profiler
  45. })())
  46. }
  47. const LockManager = SandboxedModule.require(modulePath, { requires: mocks })
  48. it('should return true if the key does not exists', function (done) {
  49. existsStub.yields(null, '0')
  50. return LockManager.checkLock(doc_id, (err, free) => {
  51. free.should.equal(true)
  52. return done()
  53. })
  54. })
  55. return it('should return false if the key does exists', function (done) {
  56. existsStub.yields(null, '1')
  57. return LockManager.checkLock(doc_id, (err, free) => {
  58. free.should.equal(false)
  59. return done()
  60. })
  61. })
  62. })