CheckingTheLock.js 1.8 KB

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