Merge pull request #3658 from overleaf/jpa-change-write-path-file-deletion

[ProjectEntityMongoUpdateHandler] track deleted files in own collection

GitOrigin-RevId: 7dff10a4737626a2d02b93b346e7e02a9d9a8608
This commit is contained in:
Jakob Ackermann
2021-02-17 11:40:56 +00:00
committed by Copybot
parent da641ba039
commit ab87ed51b9
6 changed files with 59 additions and 48 deletions
@@ -4,6 +4,7 @@ const tk = require('timekeeper')
const Errors = require('../../../../app/src/Features/Errors/Errors')
const { ObjectId } = require('mongodb')
const SandboxedModule = require('sandboxed-module')
const { DeletedFile } = require('../helpers/models/DeletedFile')
const { Project } = require('../helpers/models/Project')
const MODULE_PATH =
@@ -76,6 +77,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
}
this.FolderModel = sinon.stub()
this.DeletedFileMock = sinon.mock(DeletedFile)
this.ProjectMock = sinon.mock(Project)
this.ProjectEntityHandler = {
promises: {
@@ -192,6 +194,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
'../Cooldown/CooldownManager': this.CooldownManager,
'../../models/Folder': { Folder: this.FolderModel },
'../../infrastructure/LockManager': this.LockManager,
'../../models/DeletedFile': { DeletedFile },
'../../models/Project': { Project },
'./ProjectEntityHandler': this.ProjectEntityHandler,
'./ProjectLocator': this.ProjectLocator,
@@ -202,6 +205,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
})
afterEach(function() {
this.DeletedFileMock.restore()
this.ProjectMock.restore()
})
@@ -355,22 +359,15 @@ describe('ProjectEntityMongoUpdateHandler', function() {
hash: 'some-hash'
}
// Add a deleted file record
this.ProjectMock.expects('updateOne')
.withArgs(
{ _id: this.project._id },
{
$push: {
deletedFiles: {
_id: this.file._id,
name: this.file.name,
linkedFileData: this.file.linkedFileData,
hash: this.file.hash,
deletedAt: sinon.match.date
}
}
}
)
.chain('exec')
this.DeletedFileMock.expects('create')
.withArgs({
projectId: this.project._id,
_id: this.file._id,
name: this.file.name,
linkedFileData: this.file.linkedFileData,
hash: this.file.hash,
deletedAt: sinon.match.date
})
.resolves()
// Update the file in place
this.ProjectMock.expects('findOneAndUpdate')
@@ -399,6 +396,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
})
it('updates the database', function() {
this.DeletedFileMock.verify()
this.ProjectMock.verify()
})
})
@@ -1008,22 +1006,15 @@ describe('ProjectEntityMongoUpdateHandler', function() {
describe('_insertDeletedFileReference', function() {
beforeEach(async function() {
this.ProjectMock.expects('updateOne')
.withArgs(
{ _id: this.project._id },
{
$push: {
deletedFiles: {
_id: this.file._id,
name: this.file.name,
linkedFileData: this.file.linkedFileData,
hash: this.file.hash,
deletedAt: sinon.match.date
}
}
}
)
.chain('exec')
this.DeletedFileMock.expects('create')
.withArgs({
projectId: this.project._id,
_id: this.file._id,
name: this.file.name,
linkedFileData: this.file.linkedFileData,
hash: this.file.hash,
deletedAt: sinon.match.date
})
.resolves()
await this.subject.promises._insertDeletedFileReference(
this.project._id,
@@ -1032,7 +1023,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
})
it('should update the database', function() {
this.ProjectMock.verify()
this.DeletedFileMock.verify()
})
})