HistoryRedisManagerTests.js 3.0 KB

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