[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:
@@ -13,6 +13,8 @@ const GLOBAL_BLOB_HASH = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
||||
|
||||
describe('ClsiManager', function () {
|
||||
beforeEach(function () {
|
||||
tk.freeze(Date.now())
|
||||
|
||||
this.user_id = 'user-id'
|
||||
this.project = {
|
||||
_id: 'project-id',
|
||||
@@ -182,7 +184,6 @@ describe('ClsiManager', function () {
|
||||
'../History/HistoryManager': this.HistoryManager,
|
||||
},
|
||||
})
|
||||
tk.freeze(Date.now())
|
||||
})
|
||||
|
||||
after(function () {
|
||||
|
||||
@@ -518,7 +518,12 @@ describe('EditorController', function () {
|
||||
|
||||
it('should add the folder using the project entity handler', function () {
|
||||
return this.ProjectEntityUpdateHandler.addFolder
|
||||
.calledWith(this.project_id, this.folder_id, this.folderName)
|
||||
.calledWith(
|
||||
this.project_id,
|
||||
this.folder_id,
|
||||
this.folderName,
|
||||
this.user_id
|
||||
)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -540,6 +545,7 @@ describe('EditorController', function () {
|
||||
(this.folderA = { _id: 2, parentFolder_id: 1 }),
|
||||
(this.folderB = { _id: 3, parentFolder_id: 2 }),
|
||||
]
|
||||
this.userId = new ObjectId().toString()
|
||||
this.EditorController._notifyProjectUsersOfNewFolders = sinon
|
||||
.stub()
|
||||
.yields()
|
||||
@@ -549,13 +555,14 @@ describe('EditorController', function () {
|
||||
return this.EditorController.mkdirp(
|
||||
this.project_id,
|
||||
this.path,
|
||||
this.userId,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should create the folder using the project entity handler', function () {
|
||||
return this.ProjectEntityUpdateHandler.mkdirp
|
||||
.calledWith(this.project_id, this.path)
|
||||
.calledWith(this.project_id, this.path, this.userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ describe('RestoreManager', function () {
|
||||
|
||||
it('should find the root folder', function () {
|
||||
this.RestoreManager.promises._findOrCreateFolder
|
||||
.calledWith(this.project_id, '')
|
||||
.calledWith(this.project_id, '', this.user_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('RestoreManager', function () {
|
||||
|
||||
it('should find the folder', function () {
|
||||
this.RestoreManager.promises._findOrCreateFolder
|
||||
.calledWith(this.project_id, 'foo')
|
||||
.calledWith(this.project_id, 'foo', this.user_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -143,13 +143,14 @@ describe('RestoreManager', function () {
|
||||
})
|
||||
this.result = await this.RestoreManager.promises._findOrCreateFolder(
|
||||
this.project_id,
|
||||
'folder/name'
|
||||
'folder/name',
|
||||
this.user_id
|
||||
)
|
||||
})
|
||||
|
||||
it('should look up or create the folder', function () {
|
||||
this.EditorController.promises.mkdirp
|
||||
.calledWith(this.project_id, 'folder/name')
|
||||
.calledWith(this.project_id, 'folder/name', this.user_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -747,13 +747,6 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should mark the project as updated', function () {
|
||||
const args = this.ProjectUpdater.promises.markAsUpdated.args[0]
|
||||
args[0].should.equal(projectId)
|
||||
args[1].should.exist
|
||||
args[2].should.equal(userId)
|
||||
})
|
||||
|
||||
it('sends the change in project structure to the doc updater', function () {
|
||||
const newFiles = [
|
||||
{
|
||||
@@ -1181,7 +1174,8 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.replaceFileWithNew.should.have.been.calledWith(
|
||||
projectId,
|
||||
this.existingFile._id,
|
||||
this.file
|
||||
this.file,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1198,13 +1192,6 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('should mark the project as updated', function () {
|
||||
const args = this.ProjectUpdater.promises.markAsUpdated.args[0]
|
||||
args[0].should.equal(projectId)
|
||||
args[1].should.exist
|
||||
args[2].should.equal(userId)
|
||||
})
|
||||
|
||||
it('updates the project structure in the doc updater', function () {
|
||||
const oldFiles = [
|
||||
{
|
||||
@@ -1394,7 +1381,12 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
it('replaces the existing doc with a file', function () {
|
||||
expect(
|
||||
this.ProjectEntityMongoUpdateHandler.promises.replaceDocWithFile
|
||||
).to.have.been.calledWith(projectId, this.existingDoc._id, this.newFile)
|
||||
).to.have.been.calledWith(
|
||||
projectId,
|
||||
this.existingDoc._id,
|
||||
this.newFile,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
it('updates the doc structure', function () {
|
||||
@@ -1475,7 +1467,7 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
|
||||
it('creates any necessary folders', function () {
|
||||
this.ProjectEntityUpdateHandler.promises.mkdirp.withoutLock
|
||||
.calledWith(projectId, '/folder')
|
||||
.calledWith(projectId, '/folder', userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -1620,7 +1612,7 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
|
||||
it('creates any necessary folders', function () {
|
||||
this.ProjectEntityUpdateHandler.promises.mkdirp.withoutLock
|
||||
.calledWith(projectId, '/folder')
|
||||
.calledWith(projectId, '/folder', userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -1767,7 +1759,7 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
|
||||
it('deletes the entity in mongo', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.deleteEntity
|
||||
.calledWith(projectId, docId, 'doc')
|
||||
.calledWith(projectId, docId, 'doc', userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -1873,12 +1865,17 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
beforeEach(function (done) {
|
||||
this.docPath = '/folder/doc.tex'
|
||||
this.ProjectEntityMongoUpdateHandler.promises.mkdirp.resolves({})
|
||||
this.ProjectEntityUpdateHandler.mkdirp(projectId, this.docPath, done)
|
||||
this.ProjectEntityUpdateHandler.mkdirp(
|
||||
projectId,
|
||||
this.docPath,
|
||||
userId,
|
||||
done
|
||||
)
|
||||
})
|
||||
|
||||
it('calls ProjectEntityMongoUpdateHandler', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.mkdirp
|
||||
.calledWith(projectId, this.docPath)
|
||||
.calledWith(projectId, this.docPath, userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
@@ -1890,13 +1887,14 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
this.ProjectEntityUpdateHandler.mkdirpWithExactCase(
|
||||
projectId,
|
||||
this.docPath,
|
||||
userId,
|
||||
done
|
||||
)
|
||||
})
|
||||
|
||||
it('calls ProjectEntityMongoUpdateHandler', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.mkdirp
|
||||
.calledWith(projectId, this.docPath, { exactCaseMatch: true })
|
||||
.calledWith(projectId, this.docPath, userId, { exactCaseMatch: true })
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
@@ -1911,13 +1909,14 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
projectId,
|
||||
this.parentFolderId,
|
||||
this.folderName,
|
||||
userId,
|
||||
done
|
||||
)
|
||||
})
|
||||
|
||||
it('calls ProjectEntityMongoUpdateHandler', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.addFolder
|
||||
.calledWith(projectId, this.parentFolderId, this.folderName)
|
||||
.calledWith(projectId, this.parentFolderId, this.folderName, userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
@@ -1973,7 +1972,7 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
|
||||
it('moves the entity in mongo', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.moveEntity
|
||||
.calledWith(projectId, docId, folderId, 'doc')
|
||||
.calledWith(projectId, docId, folderId, 'doc', userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -2035,7 +2034,7 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
|
||||
it('moves the entity in mongo', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.renameEntity
|
||||
.calledWith(projectId, docId, 'doc', this.newDocName)
|
||||
.calledWith(projectId, docId, 'doc', this.newDocName, userId)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -2320,25 +2319,29 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
projectId,
|
||||
'doc3',
|
||||
'doc',
|
||||
'duplicate.tex (1)'
|
||||
'duplicate.tex (1)',
|
||||
null
|
||||
)
|
||||
expect(renameEntity).to.have.been.calledWith(
|
||||
projectId,
|
||||
'doc5',
|
||||
'doc',
|
||||
'duplicate.tex (2)'
|
||||
'duplicate.tex (2)',
|
||||
null
|
||||
)
|
||||
expect(renameEntity).to.have.been.calledWith(
|
||||
projectId,
|
||||
'file3',
|
||||
'file',
|
||||
'duplicate.jpg (1)'
|
||||
'duplicate.jpg (1)',
|
||||
null
|
||||
)
|
||||
expect(renameEntity).to.have.been.calledWith(
|
||||
projectId,
|
||||
'file4',
|
||||
'file',
|
||||
'another dupe (23)'
|
||||
'another dupe (23)',
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
@@ -2410,25 +2413,29 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
projectId,
|
||||
'doc1',
|
||||
'doc',
|
||||
'_d_e_f_test.tex'
|
||||
'_d_e_f_test.tex',
|
||||
null
|
||||
)
|
||||
expect(renameEntity).to.have.been.calledWith(
|
||||
projectId,
|
||||
'doc2',
|
||||
'doc',
|
||||
'untitled'
|
||||
'untitled',
|
||||
null
|
||||
)
|
||||
expect(renameEntity).to.have.been.calledWith(
|
||||
projectId,
|
||||
'file1',
|
||||
'file',
|
||||
'A_.png'
|
||||
'A_.png',
|
||||
null
|
||||
)
|
||||
expect(renameEntity).to.have.been.calledWith(
|
||||
projectId,
|
||||
'file2',
|
||||
'file',
|
||||
'A_.png (1)'
|
||||
'A_.png (1)',
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
@@ -2501,7 +2508,8 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
projectId,
|
||||
'folder2',
|
||||
'folder',
|
||||
'bad_'
|
||||
'bad_',
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
@@ -2558,7 +2566,8 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
projectId,
|
||||
'doc1',
|
||||
'doc',
|
||||
'chapters (1)'
|
||||
'chapters (1)',
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
@@ -2929,7 +2938,7 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
this.ProjectEntityUpdateHandler.convertDocToFile(
|
||||
this.project._id,
|
||||
this.doc._id,
|
||||
this.user._id,
|
||||
userId,
|
||||
this.source,
|
||||
done
|
||||
)
|
||||
@@ -2960,7 +2969,12 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
it('replaces the doc with the file', function () {
|
||||
expect(
|
||||
this.ProjectEntityMongoUpdateHandler.promises.replaceDocWithFile
|
||||
).to.have.been.calledWith(this.project._id, this.doc._id, this.file)
|
||||
).to.have.been.calledWith(
|
||||
this.project._id,
|
||||
this.doc._id,
|
||||
this.file,
|
||||
userId
|
||||
)
|
||||
})
|
||||
|
||||
it('notifies document updater of changes', function () {
|
||||
@@ -2969,7 +2983,7 @@ describe('ProjectEntityUpdateHandler', function () {
|
||||
).to.have.been.calledWith(
|
||||
this.project._id,
|
||||
this.project.overleaf.history.id,
|
||||
this.user._id,
|
||||
userId,
|
||||
{
|
||||
oldDocs: [{ doc: this.doc, path: this.path }],
|
||||
newFiles: [
|
||||
|
||||
@@ -107,6 +107,7 @@ const mockApiRequest = function (options) {
|
||||
|
||||
describe('RecurlyWrapper', function () {
|
||||
beforeEach(function () {
|
||||
tk.freeze(Date.now()) // freeze the time for these tests
|
||||
this.settings = {
|
||||
plans: [
|
||||
{
|
||||
@@ -134,7 +135,6 @@ describe('RecurlyWrapper', function () {
|
||||
fetchStringWithResponse: sinon.stub(),
|
||||
RequestFailedError,
|
||||
}
|
||||
tk.freeze(Date.now()) // freeze the time for these tests
|
||||
this.RecurlyWrapper = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'@overleaf/settings': this.settings,
|
||||
|
||||
@@ -540,7 +540,8 @@ function expectFolderUpdateProcessed() {
|
||||
it('processes the folder update', function () {
|
||||
expect(this.UpdateMerger.promises.createFolder).to.have.been.calledWith(
|
||||
this.projects.active1._id,
|
||||
this.folderPath
|
||||
this.folderPath,
|
||||
this.userId
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -267,7 +267,8 @@ describe('ProjectUploadController', function () {
|
||||
|
||||
this.EditorController.promises.mkdirp.should.be.calledWith(
|
||||
this.project_id,
|
||||
'/test/foo/bar'
|
||||
'/test/foo/bar',
|
||||
this.user_id
|
||||
)
|
||||
|
||||
this.FileSystemImportManager.addEntity.should.be.calledOnceWith(
|
||||
|
||||
Reference in New Issue
Block a user