Merge pull request #21706 from overleaf/bg-clear-projects-from-docupdater

clear inactive projects from docupdater when archiving

GitOrigin-RevId: 8fb11e6ebd29dfaafb62c10e07e774b90301b5ae
This commit is contained in:
Brian Gough
2024-12-06 09:56:03 +00:00
committed by Copybot
parent d5b943fe8e
commit 0d1dfd66d7
2 changed files with 48 additions and 1 deletions

View File

@@ -11,12 +11,18 @@ const { expect } = require('chai')
describe('InactiveProjectManager', function () {
beforeEach(function () {
this.settings = {}
this.metrics = { inc: sinon.stub() }
this.DocstoreManager = {
promises: {
unarchiveProject: sinon.stub(),
archiveProject: sinon.stub(),
},
}
this.DocumentUpdaterHandler = {
promises: {
flushProjectToMongoAndDelete: sinon.stub(),
},
}
this.ProjectUpdateHandler = {
promises: {
markAsActive: sinon.stub(),
@@ -24,14 +30,19 @@ describe('InactiveProjectManager', function () {
},
}
this.ProjectGetter = { promises: { getProject: sinon.stub() } }
this.Modules = { promises: { hooks: { fire: sinon.stub() } } }
this.InactiveProjectManager = SandboxedModule.require(modulePath, {
requires: {
'mongodb-legacy': { ObjectId },
'@overleaf/settings': this.settings,
'@overleaf/metrics': this.metrics,
'../Docstore/DocstoreManager': this.DocstoreManager,
'../DocumentUpdater/DocumentUpdaterHandler':
this.DocumentUpdaterHandler,
'../Project/ProjectUpdateHandler': this.ProjectUpdateHandler,
'../Project/ProjectGetter': this.ProjectGetter,
'../../models/Project': {},
'../../infrastructure/Modules': this.Modules,
'../../infrastructure/mongodb': {
ObjectId,
READ_PREFERENCE_SECONDARY: ReadPreference.secondaryPreferred.mode,
@@ -94,13 +105,21 @@ describe('InactiveProjectManager', function () {
})
describe('deactivateProject', function () {
it('should call unarchiveProject and markAsInactive', async function () {
it('should call archiveProject and markAsInactive after flushing', async function () {
this.DocstoreManager.promises.archiveProject.resolves()
this.DocumentUpdaterHandler.promises.flushProjectToMongoAndDelete.resolves()
this.ProjectUpdateHandler.promises.markAsInactive.resolves()
this.Modules.promises.hooks.fire.resolves()
await this.InactiveProjectManager.promises.deactivateProject(
this.project_id
)
this.DocumentUpdaterHandler.promises.flushProjectToMongoAndDelete
.calledWith(this.project_id)
.should.equal(true)
this.Modules.promises.hooks.fire
.calledWith('deactivateProject', this.project_id)
.should.equal(true)
this.DocstoreManager.promises.archiveProject
.calledWith(this.project_id)
.should.equal(true)
@@ -111,11 +130,16 @@ describe('InactiveProjectManager', function () {
it('should not call markAsInactive if there was a problem archiving in docstore', async function () {
this.DocstoreManager.promises.archiveProject.rejects()
this.DocumentUpdaterHandler.promises.flushProjectToMongoAndDelete.resolves()
this.ProjectUpdateHandler.promises.markAsInactive.resolves()
this.Modules.promises.hooks.fire.resolves()
await expect(
this.InactiveProjectManager.promises.deactivateProject(this.project_id)
).to.be.rejected
this.DocumentUpdaterHandler.promises.flushProjectToMongoAndDelete
.calledWith(this.project_id)
.should.equal(true)
this.DocstoreManager.promises.archiveProject
.calledWith(this.project_id)
.should.equal(true)