Merge pull request #4254 from overleaf/em-active-projects-expire

Unit test for not expiring active projects

GitOrigin-RevId: 8b2f3d05c7f7e4c4d44e5487041f19d2bff9891a
This commit is contained in:
Eric Mc Sween 2021-07-01 11:02:44 -04:00 committed by Copybot
parent a966a5f9d7
commit 9820b787a7

View file

@ -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
})
})
})