HistoryRedisManagerTests.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* eslint-disable
  2. camelcase,
  3. no-return-assign,
  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. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const sinon = require('sinon')
  15. const chai = require('chai')
  16. const should = chai.should()
  17. const modulePath = '../../../../app/js/HistoryRedisManager.js'
  18. const SandboxedModule = require('sandboxed-module')
  19. const Errors = require('../../../../app/js/Errors')
  20. describe('HistoryRedisManager', function () {
  21. beforeEach(function () {
  22. this.rclient = {
  23. auth() {},
  24. exec: sinon.stub()
  25. }
  26. this.rclient.multi = () => this.rclient
  27. this.HistoryRedisManager = SandboxedModule.require(modulePath, {
  28. requires: {
  29. '@overleaf/redis-wrapper': { createClient: () => this.rclient },
  30. 'settings-sharelatex': {
  31. redis: {
  32. history: (this.settings = {
  33. key_schema: {
  34. uncompressedHistoryOps({ doc_id }) {
  35. return `UncompressedHistoryOps:${doc_id}`
  36. },
  37. docsWithHistoryOps({ project_id }) {
  38. return `DocsWithHistoryOps:${project_id}`
  39. }
  40. }
  41. })
  42. }
  43. },
  44. 'logger-sharelatex': { log() {} }
  45. }
  46. })
  47. this.doc_id = 'doc-id-123'
  48. this.project_id = 'project-id-123'
  49. return (this.callback = sinon.stub())
  50. })
  51. return describe('recordDocHasHistoryOps', function () {
  52. beforeEach(function () {
  53. this.ops = [{ op: [{ i: 'foo', p: 4 }] }, { op: [{ i: 'bar', p: 56 }] }]
  54. return (this.rclient.sadd = sinon.stub().yields())
  55. })
  56. describe('with ops', function () {
  57. beforeEach(function (done) {
  58. return this.HistoryRedisManager.recordDocHasHistoryOps(
  59. this.project_id,
  60. this.doc_id,
  61. this.ops,
  62. (...args) => {
  63. this.callback(...Array.from(args || []))
  64. return done()
  65. }
  66. )
  67. })
  68. return it('should add the doc_id to the set of which records the project docs', function () {
  69. return this.rclient.sadd
  70. .calledWith(`DocsWithHistoryOps:${this.project_id}`, this.doc_id)
  71. .should.equal(true)
  72. })
  73. })
  74. return describe('with no ops', function () {
  75. beforeEach(function (done) {
  76. return this.HistoryRedisManager.recordDocHasHistoryOps(
  77. this.project_id,
  78. this.doc_id,
  79. [],
  80. (...args) => {
  81. this.callback(...Array.from(args || []))
  82. return done()
  83. }
  84. )
  85. })
  86. it('should not add the doc_id to the set of which records the project docs', function () {
  87. return this.rclient.sadd.called.should.equal(false)
  88. })
  89. return it('should call the callback with an error', function () {
  90. return this.callback
  91. .calledWith(sinon.match.instanceOf(Error))
  92. .should.equal(true)
  93. })
  94. })
  95. })
  96. })