Merge pull request #19041 from overleaf/em-docupdater-block-project

Endpoint for blocking projects from being loaded in docupdater

GitOrigin-RevId: 87d79a0b8ccfa0ed46fbf0c198e8a405c1c1151f
This commit is contained in:
Eric Mc Sween
2024-07-03 08:04:40 +00:00
committed by Copybot
parent f77894c427
commit e8e31dbdb5
5 changed files with 191 additions and 62 deletions
@@ -1,4 +1,5 @@
const sinon = require('sinon')
const { expect } = require('chai')
const SandboxedModule = require('sandboxed-module')
const Errors = require('../../../../app/js/Errors')
const crypto = require('crypto')
@@ -54,6 +55,9 @@ describe('RedisManager', function () {
projectState({ project_id: projectId }) {
return `ProjectState:${projectId}`
},
projectBlock({ project_id: projectId }) {
return `ProjectBlock:${projectId}`
},
unflushedTime({ doc_id: docId }) {
return `UnflushedTime:${docId}`
},
@@ -782,6 +786,8 @@ describe('RedisManager', function () {
this.multi.mset = sinon.stub()
this.multi.sadd = sinon.stub()
this.multi.del = sinon.stub()
this.multi.exists = sinon.stub()
this.multi.exec.onCall(0).yields(null, [0])
this.rclient.sadd = sinon.stub().yields()
this.lines = ['one', 'two', 'three', 'これは']
this.version = 42
@@ -825,7 +831,7 @@ describe('RedisManager', function () {
})
it('should add the docId to the project set', function () {
this.rclient.sadd
this.multi.sadd
.calledWith(`DocsIn:${this.project_id}`, this.docId)
.should.equal(true)
})
@@ -975,6 +981,35 @@ describe('RedisManager', function () {
)
})
})
describe('when the project is blocked', function () {
beforeEach(function (done) {
this.multi.exec.onCall(0).yields(null, [1])
this.RedisManager.putDocInMemory(
this.project_id,
this.docId,
this.lines,
this.version,
this.ranges,
this.resolvedCommentIds,
this.pathname,
this.projectHistoryId,
this.historyRangesSupport,
err => {
this.error = err
done()
}
)
})
it('should throw an error', function () {
expect(this.error.message).to.equal('Project blocked from loading docs')
})
it('should not store the doc', function () {
expect(this.multi.mset).to.not.have.been.called
})
})
})
describe('removeDocFromMemory', function () {