mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 05:11:34 +02:00
[web] update the projects lastUpdated timestamp when changing file-tree (#24867)
* [misc] freeze time before any other unit test setup steps Freezing it after other work (notably sandboxed-module imports) will result in flaky tests. * [web] update the projects lastUpdated timestamp when changing file-tree GitOrigin-RevId: b82b2ff74dc31886f3c4bd300375117eead6e0cd
This commit is contained in:
@@ -12,6 +12,7 @@ const MODULE_PATH =
|
||||
|
||||
describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
beforeEach(function () {
|
||||
tk.freeze(new Date())
|
||||
this.doc = {
|
||||
_id: new ObjectId(),
|
||||
name: 'test-doc.txt',
|
||||
@@ -209,19 +210,13 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
afterEach(function () {
|
||||
this.DeletedFileMock.restore()
|
||||
this.ProjectMock.restore()
|
||||
})
|
||||
|
||||
beforeEach(function () {
|
||||
tk.freeze(Date.now())
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
tk.reset()
|
||||
})
|
||||
|
||||
describe('addDoc', function () {
|
||||
beforeEach(async function () {
|
||||
const doc = { _id: new ObjectId(), name: 'other.txt' }
|
||||
const userId = new ObjectId().toString()
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
{
|
||||
@@ -231,6 +226,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
{
|
||||
$push: { 'rootFolder.0.folders.0.docs': doc },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -238,7 +234,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.result = await this.subject.promises.addDoc(
|
||||
this.project._id,
|
||||
this.folder._id,
|
||||
doc
|
||||
doc,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -260,7 +257,9 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
})
|
||||
|
||||
describe('addFile', function () {
|
||||
let userId
|
||||
beforeEach(function () {
|
||||
userId = new ObjectId().toString()
|
||||
this.newFile = { _id: new ObjectId(), name: 'picture.jpg' }
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
@@ -271,6 +270,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
{
|
||||
$push: { 'rootFolder.0.folders.0.fileRefs': this.newFile },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -282,7 +282,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.result = await this.subject.promises.addFile(
|
||||
this.project._id,
|
||||
this.folder._id,
|
||||
this.newFile
|
||||
this.newFile,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -318,7 +319,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.subject.promises.addFile(
|
||||
this.project._id,
|
||||
this.folder._id,
|
||||
this.newFile
|
||||
this.newFile,
|
||||
userId
|
||||
)
|
||||
).to.be.rejected
|
||||
})
|
||||
@@ -327,6 +329,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
|
||||
describe('addFolder', function () {
|
||||
beforeEach(async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
const folderName = 'New folder'
|
||||
this.FolderModel.withArgs({ name: folderName }).returns({
|
||||
_id: new ObjectId(),
|
||||
@@ -345,6 +348,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
}),
|
||||
},
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -352,7 +356,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
await this.subject.promises.addFolder(
|
||||
this.project._id,
|
||||
this.folder._id,
|
||||
folderName
|
||||
folderName,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -393,6 +398,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
'rootFolder.0.fileRefs.0.created': sinon.match.date,
|
||||
'rootFolder.0.fileRefs.0.linkedFileData': newFile.linkedFileData,
|
||||
'rootFolder.0.fileRefs.0.hash': newFile.hash,
|
||||
lastUpdated: new Date(),
|
||||
lastUpdatedBy: 'userId',
|
||||
},
|
||||
$inc: {
|
||||
version: 1,
|
||||
@@ -408,7 +415,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
await this.subject.promises.replaceFileWithNew(
|
||||
this.project._id,
|
||||
this.file._id,
|
||||
newFile
|
||||
newFile,
|
||||
'userId'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -460,6 +468,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
|
||||
describe('when the path is a new folder at the top level', function () {
|
||||
beforeEach(async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.newFolder = { _id: new ObjectId(), name: 'new-folder' }
|
||||
this.FolderModel.returns(this.newFolder)
|
||||
this.exactCaseMatch = false
|
||||
@@ -469,6 +478,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
{
|
||||
$push: { 'rootFolder.0.folders': this.newFolder },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -476,6 +486,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.result = await this.subject.promises.mkdirp(
|
||||
this.project._id,
|
||||
'/new-folder/',
|
||||
userId,
|
||||
{ exactCaseMatch: this.exactCaseMatch }
|
||||
)
|
||||
})
|
||||
@@ -504,6 +515,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
|
||||
describe('adding a subfolder', function () {
|
||||
beforeEach(async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.newFolder = { _id: new ObjectId(), name: 'new-folder' }
|
||||
this.FolderModel.returns(this.newFolder)
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
@@ -519,13 +531,15 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
}),
|
||||
},
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
.resolves(this.project)
|
||||
this.result = await this.subject.promises.mkdirp(
|
||||
this.project._id,
|
||||
'/test-folder/new-folder'
|
||||
'/test-folder/new-folder',
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -547,7 +561,9 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
})
|
||||
|
||||
describe('when mutliple folders are missing', async function () {
|
||||
let userId
|
||||
beforeEach(function () {
|
||||
userId = new ObjectId().toString()
|
||||
this.folder1 = { _id: new ObjectId(), name: 'folder1' }
|
||||
this.folder1Path = {
|
||||
fileSystem: '/test-folder/folder1',
|
||||
@@ -593,6 +609,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
}),
|
||||
},
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -610,6 +627,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
}),
|
||||
},
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -629,7 +647,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
beforeEach(async function () {
|
||||
this.result = await this.subject.promises.mkdirp(
|
||||
this.project._id,
|
||||
path
|
||||
path,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -661,6 +680,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
describe('moveEntity', function () {
|
||||
describe('moving a doc into a different folder', function () {
|
||||
beforeEach(async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.pathAfterMove = {
|
||||
fileSystem: '/somewhere/else.txt',
|
||||
}
|
||||
@@ -685,6 +705,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
{
|
||||
$push: { 'rootFolder.0.folders.0.docs': this.doc },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -695,6 +716,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
{
|
||||
$pull: { 'rootFolder.0.docs': { _id: this.doc._id } },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -703,7 +725,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.project._id,
|
||||
this.doc._id,
|
||||
this.folder._id,
|
||||
'doc'
|
||||
'doc',
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -770,12 +793,14 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
|
||||
describe('deleteEntity', function () {
|
||||
beforeEach(async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
{ _id: this.project._id },
|
||||
{
|
||||
$pull: { 'rootFolder.0.docs': { _id: this.doc._id } },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -783,7 +808,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
await this.subject.promises.deleteEntity(
|
||||
this.project._id,
|
||||
this.doc._id,
|
||||
'doc'
|
||||
'doc',
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -795,6 +821,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
describe('renameEntity', function () {
|
||||
describe('happy path', function () {
|
||||
beforeEach(async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.newName = 'new.tex'
|
||||
this.oldDocs = ['old-doc']
|
||||
this.oldFiles = ['old-file']
|
||||
@@ -812,7 +839,11 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
.withArgs(
|
||||
{ _id: this.project._id, 'rootFolder.0.docs.0': { $exists: true } },
|
||||
{
|
||||
$set: { 'rootFolder.0.docs.0.name': this.newName },
|
||||
$set: {
|
||||
'rootFolder.0.docs.0.name': this.newName,
|
||||
lastUpdated: new Date(),
|
||||
lastUpdatedBy: userId,
|
||||
},
|
||||
$inc: { version: 1 },
|
||||
}
|
||||
)
|
||||
@@ -822,7 +853,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.project._id,
|
||||
this.doc._id,
|
||||
'doc',
|
||||
this.newName
|
||||
this.newName,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -864,7 +896,9 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
describe('_putElement', function () {
|
||||
describe('updating the project', function () {
|
||||
describe('when the parent folder is given', function () {
|
||||
let userId
|
||||
beforeEach(function () {
|
||||
userId = new ObjectId().toString()
|
||||
this.newFile = { _id: new ObjectId(), name: 'new file.png' }
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
@@ -875,6 +909,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
{
|
||||
$push: { 'rootFolder.0.folders.0.fileRefs': this.newFile },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -886,7 +921,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.project,
|
||||
this.folder._id,
|
||||
this.newFile,
|
||||
'files'
|
||||
'files',
|
||||
userId
|
||||
)
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
@@ -896,7 +932,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.project,
|
||||
this.folder._id,
|
||||
this.newFile,
|
||||
'file'
|
||||
'file',
|
||||
userId
|
||||
)
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
@@ -998,6 +1035,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
|
||||
describe('when the parent folder is not given', function () {
|
||||
it('should default to root folder insert', async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.newFile = { _id: new ObjectId(), name: 'new file.png' }
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
@@ -1005,6 +1043,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
{
|
||||
$push: { 'rootFolder.0.fileRefs': this.newFile },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
}
|
||||
)
|
||||
.chain('exec')
|
||||
@@ -1013,7 +1052,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
this.project,
|
||||
this.rootFolder._id,
|
||||
this.newFile,
|
||||
'file'
|
||||
'file',
|
||||
userId
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1098,6 +1138,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
|
||||
describe('replaceDocWithFile', function () {
|
||||
it('should simultaneously remove the doc and add the file', async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
{ _id: this.project._id, 'rootFolder.0': { $exists: true } },
|
||||
@@ -1105,6 +1146,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
$pull: { 'rootFolder.0.docs': { _id: this.doc._id } },
|
||||
$push: { 'rootFolder.0.fileRefs': this.file },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
},
|
||||
{ new: true }
|
||||
)
|
||||
@@ -1113,7 +1155,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
await this.subject.promises.replaceDocWithFile(
|
||||
this.project._id,
|
||||
this.doc._id,
|
||||
this.file
|
||||
this.file,
|
||||
userId
|
||||
)
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
@@ -1121,6 +1164,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
|
||||
describe('replaceFileWithDoc', function () {
|
||||
it('should simultaneously remove the file and add the doc', async function () {
|
||||
const userId = new ObjectId().toString()
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
{ _id: this.project._id, 'rootFolder.0': { $exists: true } },
|
||||
@@ -1128,6 +1172,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
$pull: { 'rootFolder.0.fileRefs': { _id: this.file._id } },
|
||||
$push: { 'rootFolder.0.docs': this.doc },
|
||||
$inc: { version: 1 },
|
||||
$set: { lastUpdated: new Date(), lastUpdatedBy: userId },
|
||||
},
|
||||
{ new: true }
|
||||
)
|
||||
@@ -1136,7 +1181,8 @@ describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
await this.subject.promises.replaceFileWithDoc(
|
||||
this.project._id,
|
||||
this.file._id,
|
||||
this.doc
|
||||
this.doc,
|
||||
userId
|
||||
)
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user