2020-05-06 06:11:22 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-05-06 06:10:51 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-06 06:11:36 -04:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = '../../../../app/js/HistoryRedisManager.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const Errors = require('../../../../app/js/Errors')
|
2017-04-13 12:00:42 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('HistoryRedisManager', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.rclient = {
|
|
|
|
auth() {},
|
2021-07-13 07:04:42 -04:00
|
|
|
exec: sinon.stub(),
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
this.rclient.multi = () => this.rclient
|
|
|
|
this.HistoryRedisManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
2020-11-10 06:32:04 -05:00
|
|
|
'@overleaf/redis-wrapper': { createClient: () => this.rclient },
|
2021-07-12 12:47:15 -04:00
|
|
|
'@overleaf/settings': {
|
2020-05-06 06:11:36 -04:00
|
|
|
redis: {
|
|
|
|
history: (this.settings = {
|
|
|
|
key_schema: {
|
|
|
|
uncompressedHistoryOps({ doc_id }) {
|
|
|
|
return `UncompressedHistoryOps:${doc_id}`
|
|
|
|
},
|
|
|
|
docsWithHistoryOps({ project_id }) {
|
|
|
|
return `DocsWithHistoryOps:${project_id}`
|
2021-07-13 07:04:42 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
this.doc_id = 'doc-id-123'
|
|
|
|
this.project_id = 'project-id-123'
|
|
|
|
return (this.callback = sinon.stub())
|
|
|
|
})
|
2017-04-13 12:00:42 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return describe('recordDocHasHistoryOps', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.ops = [{ op: [{ i: 'foo', p: 4 }] }, { op: [{ i: 'bar', p: 56 }] }]
|
|
|
|
return (this.rclient.sadd = sinon.stub().yields())
|
|
|
|
})
|
2017-04-13 12:00:42 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('with ops', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
return this.HistoryRedisManager.recordDocHasHistoryOps(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.ops,
|
|
|
|
(...args) => {
|
|
|
|
this.callback(...Array.from(args || []))
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2017-04-13 12:00:42 -04:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
return it('should add the doc_id to the set of which records the project docs', function () {
|
|
|
|
return this.rclient.sadd
|
|
|
|
.calledWith(`DocsWithHistoryOps:${this.project_id}`, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return describe('with no ops', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
return this.HistoryRedisManager.recordDocHasHistoryOps(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
[],
|
|
|
|
(...args) => {
|
|
|
|
this.callback(...Array.from(args || []))
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not add the doc_id to the set of which records the project docs', function () {
|
|
|
|
return this.rclient.sadd.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should call the callback with an error', function () {
|
|
|
|
return this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Error))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|