HistoryRedisManagerTests.js 3.0 KB

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