mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
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:
parent
7d0f117918
commit
f7166c5c1b
3 changed files with 23 additions and 7 deletions
|
@ -278,6 +278,7 @@ async function deleteProject(projectId, options = {}) {
|
|||
}
|
||||
|
||||
async function undeleteProject(projectId, options = {}) {
|
||||
projectId = ObjectId(projectId)
|
||||
let deletedProject = await DeletedProject.findOne({
|
||||
'deleterData.deletedProjectId': projectId
|
||||
}).exec()
|
||||
|
|
|
@ -496,8 +496,16 @@ describe('Deleting a project', function () {
|
|||
.find({}, { sort: { _id: 1 } })
|
||||
.toArray()
|
||||
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
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
|
@ -627,6 +627,9 @@ describe('ProjectDeleter', function () {
|
|||
|
||||
describe('undeleteProject', function () {
|
||||
beforeEach(function () {
|
||||
this.unknownProjectId = ObjectId()
|
||||
this.purgedProjectId = ObjectId()
|
||||
|
||||
this.deletedProject = {
|
||||
_id: 'deleted',
|
||||
project: this.project,
|
||||
|
@ -638,7 +641,7 @@ describe('ProjectDeleter', function () {
|
|||
this.purgedProject = {
|
||||
_id: 'purged',
|
||||
deleterData: {
|
||||
deletedProjectId: 'purgedProject',
|
||||
deletedProjectId: this.purgedProjectId,
|
||||
deletedProjectOwnerId: 'potato'
|
||||
}
|
||||
}
|
||||
|
@ -648,11 +651,11 @@ describe('ProjectDeleter', function () {
|
|||
.chain('exec')
|
||||
.resolves(this.deletedProject)
|
||||
this.DeletedProjectMock.expects('findOne')
|
||||
.withArgs({ 'deleterData.deletedProjectId': 'purgedProject' })
|
||||
.withArgs({ 'deleterData.deletedProjectId': this.purgedProjectId })
|
||||
.chain('exec')
|
||||
.resolves(this.purgedProject)
|
||||
this.DeletedProjectMock.expects('findOne')
|
||||
.withArgs({ 'deleterData.deletedProjectId': 'wombat' })
|
||||
.withArgs({ 'deleterData.deletedProjectId': this.unknownProjectId })
|
||||
.chain('exec')
|
||||
.resolves(null)
|
||||
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 () {
|
||||
await expect(
|
||||
this.ProjectDeleter.promises.undeleteProject('wombat')
|
||||
this.ProjectDeleter.promises.undeleteProject(
|
||||
this.unknownProjectId.toString()
|
||||
)
|
||||
).to.be.rejectedWith(Errors.NotFoundError, 'project_not_found')
|
||||
})
|
||||
|
||||
it('should return not found if the project has been expired', async function () {
|
||||
await expect(
|
||||
this.ProjectDeleter.promises.undeleteProject('purgedProject')
|
||||
this.ProjectDeleter.promises.undeleteProject(
|
||||
this.purgedProjectId.toString()
|
||||
)
|
||||
).to.be.rejectedWith(Errors.NotFoundError, 'project_too_old_to_restore')
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue