Merge pull request #3922 from overleaf/jpa-fix-project-restore-deleted-files

[ProjectDeleter] undeleteProject: deletedFiles.projectId is an ObjectId

GitOrigin-RevId: 53bdc7c2a20269ef22ec7ca55a6ccf9339209cdd
This commit is contained in:
Timothée Alby 2021-04-19 14:37:36 +02:00 committed by Copybot
parent 7d0f117918
commit f7166c5c1b
3 changed files with 23 additions and 7 deletions

View file

@ -278,6 +278,7 @@ async function deleteProject(projectId, options = {}) {
} }
async function undeleteProject(projectId, options = {}) { async function undeleteProject(projectId, options = {}) {
projectId = ObjectId(projectId)
let deletedProject = await DeletedProject.findOne({ let deletedProject = await DeletedProject.findOne({
'deleterData.deletedProjectId': projectId 'deleterData.deletedProjectId': projectId
}).exec() }).exec()

View file

@ -496,8 +496,16 @@ describe('Deleting a project', function () {
.find({}, { sort: { _id: 1 } }) .find({}, { sort: { _id: 1 } })
.toArray() .toArray()
expect(docs).to.deep.equal([ expect(docs).to.deep.equal([
{ _id: fileId1, projectId: this.projectId, ...otherFileDetails }, {
{ _id: fileId2, projectId: this.projectId, ...otherFileDetails } _id: fileId1,
projectId: ObjectId(this.projectId),
...otherFileDetails
},
{
_id: fileId2,
projectId: ObjectId(this.projectId),
...otherFileDetails
}
]) ])
}) })
}) })

View file

@ -627,6 +627,9 @@ describe('ProjectDeleter', function () {
describe('undeleteProject', function () { describe('undeleteProject', function () {
beforeEach(function () { beforeEach(function () {
this.unknownProjectId = ObjectId()
this.purgedProjectId = ObjectId()
this.deletedProject = { this.deletedProject = {
_id: 'deleted', _id: 'deleted',
project: this.project, project: this.project,
@ -638,7 +641,7 @@ describe('ProjectDeleter', function () {
this.purgedProject = { this.purgedProject = {
_id: 'purged', _id: 'purged',
deleterData: { deleterData: {
deletedProjectId: 'purgedProject', deletedProjectId: this.purgedProjectId,
deletedProjectOwnerId: 'potato' deletedProjectOwnerId: 'potato'
} }
} }
@ -648,11 +651,11 @@ describe('ProjectDeleter', function () {
.chain('exec') .chain('exec')
.resolves(this.deletedProject) .resolves(this.deletedProject)
this.DeletedProjectMock.expects('findOne') this.DeletedProjectMock.expects('findOne')
.withArgs({ 'deleterData.deletedProjectId': 'purgedProject' }) .withArgs({ 'deleterData.deletedProjectId': this.purgedProjectId })
.chain('exec') .chain('exec')
.resolves(this.purgedProject) .resolves(this.purgedProject)
this.DeletedProjectMock.expects('findOne') this.DeletedProjectMock.expects('findOne')
.withArgs({ 'deleterData.deletedProjectId': 'wombat' }) .withArgs({ 'deleterData.deletedProjectId': this.unknownProjectId })
.chain('exec') .chain('exec')
.resolves(null) .resolves(null)
this.DeletedProjectMock.expects('deleteOne').chain('exec').resolves() this.DeletedProjectMock.expects('deleteOne').chain('exec').resolves()
@ -660,13 +663,17 @@ describe('ProjectDeleter', function () {
it('should return not found if the project does not exist', async function () { it('should return not found if the project does not exist', async function () {
await expect( await expect(
this.ProjectDeleter.promises.undeleteProject('wombat') this.ProjectDeleter.promises.undeleteProject(
this.unknownProjectId.toString()
)
).to.be.rejectedWith(Errors.NotFoundError, 'project_not_found') ).to.be.rejectedWith(Errors.NotFoundError, 'project_not_found')
}) })
it('should return not found if the project has been expired', async function () { it('should return not found if the project has been expired', async function () {
await expect( await expect(
this.ProjectDeleter.promises.undeleteProject('purgedProject') this.ProjectDeleter.promises.undeleteProject(
this.purgedProjectId.toString()
)
).to.be.rejectedWith(Errors.NotFoundError, 'project_too_old_to_restore') ).to.be.rejectedWith(Errors.NotFoundError, 'project_too_old_to_restore')
}) })