diff --git a/services/web/test/unit/src/Project/ProjectDeleterTests.js b/services/web/test/unit/src/Project/ProjectDeleterTests.js index 6578a4a76d..65d4b00892 100644 --- a/services/web/test/unit/src/Project/ProjectDeleterTests.js +++ b/services/web/test/unit/src/Project/ProjectDeleterTests.js @@ -419,70 +419,112 @@ describe('ProjectDeleter', function () { }) describe('expireDeletedProject', function () { - beforeEach(async function () { - for (const deletedProject of this.deletedProjects) { + describe('on an inactive project', function () { + beforeEach(async function () { this.ProjectMock.expects('findById') - .withArgs(deletedProject.deleterData.deletedProjectId) + .withArgs(this.deletedProjects[0].deleterData.deletedProjectId) .chain('exec') .resolves(null) - } - this.DeletedProjectMock.expects('updateOne') - .withArgs( - { - _id: this.deletedProjects[0]._id, - }, - { - $set: { - 'deleterData.deleterIpAddress': null, - project: null, + this.DeletedProjectMock.expects('updateOne') + .withArgs( + { + _id: this.deletedProjects[0]._id, }, - } + { + $set: { + 'deleterData.deleterIpAddress': null, + project: null, + }, + } + ) + .chain('exec') + .resolves() + + this.DeletedProjectMock.expects('findOne') + .withArgs({ + 'deleterData.deletedProjectId': this.deletedProjects[0].project._id, + }) + .chain('exec') + .resolves(this.deletedProjects[0]) + + await this.ProjectDeleter.promises.expireDeletedProject( + this.deletedProjects[0].project._id ) - .chain('exec') - .resolves() + }) - this.DeletedProjectMock.expects('findOne') - .withArgs({ - 'deleterData.deletedProjectId': this.deletedProjects[0].project._id, + it('should find the specified deletedProject and remove its project and ip address', function () { + this.DeletedProjectMock.verify() + }) + + it('should destroy the docs in docstore', function () { + expect( + this.DocstoreManager.promises.destroyProject + ).to.have.been.calledWith(this.deletedProjects[0].project._id) + }) + + it('should delete the project in history', function () { + expect( + this.HistoryManager.promises.deleteProject + ).to.have.been.calledWith( + this.deletedProjects[0].project._id, + this.deletedProjects[0].project.overleaf.history.id + ) + }) + + it('should destroy the files in filestore', function () { + expect( + this.FileStoreHandler.promises.deleteProject + ).to.have.been.calledWith(this.deletedProjects[0].project._id) + }) + + it('should destroy the files in project-archiver', function () { + expect( + this.TpdsUpdateSender.promises.deleteProject + ).to.have.been.calledWith({ + project_id: this.deletedProjects[0].project._id, }) - .chain('exec') - .resolves(this.deletedProjects[0]) - - await this.ProjectDeleter.promises.expireDeletedProject( - this.deletedProjects[0].project._id - ) + }) }) - it('should find the specified deletedProject and remove its project and ip address', function () { - this.DeletedProjectMock.verify() - }) + describe('on an active project (from an incomplete delete)', function () { + beforeEach(async function () { + this.ProjectMock.expects('findById') + .withArgs(this.deletedProjects[0].deleterData.deletedProjectId) + .chain('exec') + .resolves(this.deletedProjects[0].project) + this.DeletedProjectMock.expects('deleteOne') + .withArgs({ + 'deleterData.deletedProjectId': this.deletedProjects[0].project._id, + }) + .chain('exec') + .resolves() + await this.ProjectDeleter.promises.expireDeletedProject( + this.deletedProjects[0].project._id + ) + }) - it('should destroy the docs in docstore', function () { - expect( - this.DocstoreManager.promises.destroyProject - ).to.have.been.calledWith(this.deletedProjects[0].project._id) - }) + it('should delete the spurious deleted project record', function () { + this.DeletedProjectMock.verify() + }) - it('should delete the project in history', function () { - expect( - this.HistoryManager.promises.deleteProject - ).to.have.been.calledWith( - this.deletedProjects[0].project._id, - this.deletedProjects[0].project.overleaf.history.id - ) - }) + it('should not destroy the docs in docstore', function () { + expect(this.DocstoreManager.promises.destroyProject).to.not.have.been + .called + }) - it('should destroy the files in filestore', function () { - expect( - this.FileStoreHandler.promises.deleteProject - ).to.have.been.calledWith(this.deletedProjects[0].project._id) - }) + it('should not delete the project in history', function () { + expect(this.HistoryManager.promises.deleteProject).to.not.have.been + .called + }) - it('should destroy the files in project-archiver', function () { - expect( - this.TpdsUpdateSender.promises.deleteProject - ).to.have.been.calledWith({ - project_id: this.deletedProjects[0].project._id, + it('should not destroy the files in filestore', function () { + expect(this.FileStoreHandler.promises.deleteProject).to.not.have.been + .called + }) + + it('should not destroy the files in project-archiver', function () { + expect(this.TpdsUpdateSender.promises.deleteProject).to.not.have.been + .called }) }) })