|
|
@@ -1,166 +1,200 @@
|
|
|
const { expect } = require('chai')
|
|
|
const sinon = require('sinon')
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
+const { ObjectId } = require('mongodb')
|
|
|
|
|
|
const MODULE_PATH = '../../../../app/src/Features/Project/ProjectDuplicator.js'
|
|
|
|
|
|
describe('ProjectDuplicator', function() {
|
|
|
beforeEach(function() {
|
|
|
+ this.doc0 = { _id: 'doc0_id', name: 'rootDocHere' }
|
|
|
+ this.doc1 = { _id: 'doc1_id', name: 'level1folderDocName' }
|
|
|
+ this.doc2 = { _id: 'doc2_id', name: 'level2folderDocName' }
|
|
|
+ this.doc0Lines = ['zero']
|
|
|
+ this.doc1Lines = ['one']
|
|
|
+ this.doc2Lines = ['two']
|
|
|
+ this.file0 = { name: 'file0', _id: 'file0' }
|
|
|
+ this.file1 = { name: 'file1', _id: 'file1' }
|
|
|
+ this.file2 = {
|
|
|
+ name: 'file2',
|
|
|
+ _id: 'file2',
|
|
|
+ linkedFileData: { provider: 'url' },
|
|
|
+ hash: '123456'
|
|
|
+ }
|
|
|
this.level2folder = {
|
|
|
name: 'level2folderName',
|
|
|
_id: 'level2folderId',
|
|
|
- docs: [
|
|
|
- (this.doc2 = { _id: 'doc2_id', name: 'level2folderDocName' }),
|
|
|
- undefined
|
|
|
- ],
|
|
|
+ docs: [this.doc2, undefined],
|
|
|
folders: [],
|
|
|
- fileRefs: [{ name: 'file2', _id: 'file2' }]
|
|
|
+ fileRefs: [this.file2]
|
|
|
}
|
|
|
this.level1folder = {
|
|
|
name: 'level1folder',
|
|
|
_id: 'level1folderId',
|
|
|
- docs: [(this.doc1 = { _id: 'doc1_id', name: 'level1folderDocName' })],
|
|
|
+ docs: [this.doc1],
|
|
|
folders: [this.level2folder],
|
|
|
- fileRefs: [{ name: 'file1', _id: 'file1' }, null] // the null is intentional to test null docs/files
|
|
|
+ fileRefs: [this.file1, null] // the null is intentional to test null docs/files
|
|
|
}
|
|
|
this.rootFolder = {
|
|
|
name: 'rootFolder',
|
|
|
_id: 'rootFolderId',
|
|
|
- docs: [(this.doc0 = { _id: 'doc0_id', name: 'rootDocHere' })],
|
|
|
+ docs: [this.doc0],
|
|
|
folders: [this.level1folder, {}],
|
|
|
- fileRefs: [{ name: 'file0', _id: 'file0' }]
|
|
|
+ fileRefs: [this.file0]
|
|
|
}
|
|
|
this.project = {
|
|
|
- _id: (this.old_project_id = 'this_is_the_old_project_id'),
|
|
|
- rootDoc_id: 'rootDoc_id',
|
|
|
+ _id: 'this_is_the_old_project_id',
|
|
|
+ rootDoc_id: this.doc0._id,
|
|
|
rootFolder: [this.rootFolder],
|
|
|
compiler: 'this_is_a_Compiler'
|
|
|
}
|
|
|
+ this.doc0Path = '/rootDocHere'
|
|
|
+ this.doc1Path = '/level1folder/level1folderDocName'
|
|
|
+ this.doc2Path = '/level1folder/level2folderName/level2folderDocName'
|
|
|
+ this.file0Path = '/file0'
|
|
|
+ this.file1Path = '/level1folder/file1'
|
|
|
+ this.file2Path = '/level1folder/level2folderName/file2'
|
|
|
|
|
|
this.docContents = [
|
|
|
+ { _id: this.doc0._id, lines: this.doc0Lines },
|
|
|
+ { _id: this.doc1._id, lines: this.doc1Lines },
|
|
|
+ { _id: this.doc2._id, lines: this.doc2Lines }
|
|
|
+ ]
|
|
|
+
|
|
|
+ this.rootDoc = this.doc0
|
|
|
+ this.rootDocPath = '/rootDocHere'
|
|
|
+ this.owner = { _id: 'this_is_the_owner' }
|
|
|
+ this.newBlankProject = {
|
|
|
+ _id: 'new_project_id',
|
|
|
+ overleaf: { history: { id: 339123 } },
|
|
|
+ readOnly_refs: [],
|
|
|
+ collaberator_refs: [],
|
|
|
+ rootFolder: [{ _id: 'new_root_folder_id' }]
|
|
|
+ }
|
|
|
+ this.newFolder = { _id: 'newFolderId' }
|
|
|
+ this.filestoreUrl = 'filestore-url'
|
|
|
+ this.newProjectVersion = 2
|
|
|
+
|
|
|
+ this.newDocId = new ObjectId()
|
|
|
+ this.newFileId = new ObjectId()
|
|
|
+ this.newDoc0 = { ...this.doc0, _id: this.newDocId }
|
|
|
+ this.newDoc1 = { ...this.doc1, _id: this.newDocId }
|
|
|
+ this.newDoc2 = { ...this.doc2, _id: this.newDocId }
|
|
|
+ this.newFile0 = { ...this.file0, _id: this.newFileId }
|
|
|
+ this.newFile1 = { ...this.file1, _id: this.newFileId }
|
|
|
+ this.newFile2 = { ...this.file2, _id: this.newFileId }
|
|
|
+
|
|
|
+ this.docEntries = [
|
|
|
+ {
|
|
|
+ path: this.doc0Path,
|
|
|
+ doc: this.newDoc0,
|
|
|
+ docLines: this.doc0Lines.join('\n')
|
|
|
+ },
|
|
|
+ {
|
|
|
+ path: this.doc1Path,
|
|
|
+ doc: this.newDoc1,
|
|
|
+ docLines: this.doc1Lines.join('\n')
|
|
|
+ },
|
|
|
+ {
|
|
|
+ path: this.doc2Path,
|
|
|
+ doc: this.newDoc2,
|
|
|
+ docLines: this.doc2Lines.join('\n')
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ this.fileEntries = [
|
|
|
{
|
|
|
- _id: this.doc0._id,
|
|
|
- lines: (this.doc0_lines = ['zero'])
|
|
|
+ path: this.file0Path,
|
|
|
+ file: this.newFile0,
|
|
|
+ url: this.filestoreUrl
|
|
|
},
|
|
|
{
|
|
|
- _id: this.doc1._id,
|
|
|
- lines: (this.doc1_lines = ['one'])
|
|
|
+ path: this.file1Path,
|
|
|
+ file: this.newFile1,
|
|
|
+ url: this.filestoreUrl
|
|
|
},
|
|
|
{
|
|
|
- _id: this.doc2._id,
|
|
|
- lines: (this.doc2_lines = ['two'])
|
|
|
+ path: this.file2Path,
|
|
|
+ file: this.newFile2,
|
|
|
+ url: this.filestoreUrl
|
|
|
}
|
|
|
]
|
|
|
+
|
|
|
+ this.Doc = sinon
|
|
|
+ .stub()
|
|
|
+ .callsFake(props => ({ _id: this.newDocId, ...props }))
|
|
|
+ this.File = sinon
|
|
|
+ .stub()
|
|
|
+ .callsFake(props => ({ _id: this.newFileId, ...props }))
|
|
|
+
|
|
|
this.DocstoreManager = {
|
|
|
promises: {
|
|
|
+ updateDoc: sinon.stub().resolves(),
|
|
|
getAllDocs: sinon.stub().resolves(this.docContents)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- this.owner = { _id: 'this_is_the_owner' }
|
|
|
- this.stubbedNewProject = {
|
|
|
- _id: (this.new_project_id = 'new_project_id'),
|
|
|
- readOnly_refs: [],
|
|
|
- collaberator_refs: [],
|
|
|
- rootFolder: [{ _id: 'new_root_folder_id' }]
|
|
|
+ this.DocumentUpdaterHandler = {
|
|
|
+ promises: {
|
|
|
+ flushProjectToMongo: sinon.stub().resolves(),
|
|
|
+ updateProjectStructure: sinon.stub().resolves()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.FileStoreHandler = {
|
|
|
+ promises: {
|
|
|
+ copyFile: sinon.stub().resolves(this.filestoreUrl)
|
|
|
+ }
|
|
|
}
|
|
|
- this.foundRootDoc = { _id: 'rootDocId', name: 'rootDocHere' }
|
|
|
-
|
|
|
this.ProjectCreationHandler = {
|
|
|
promises: {
|
|
|
- createBlankProject: sinon.stub().resolves(this.stubbedNewProject)
|
|
|
+ createBlankProject: sinon.stub().resolves(this.newBlankProject)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- this.newFolder = { _id: 'newFolderId' }
|
|
|
-
|
|
|
- this.ProjectLocator = {
|
|
|
+ this.ProjectDeleter = {
|
|
|
promises: {
|
|
|
- findRootDoc: sinon
|
|
|
- .stub()
|
|
|
- .resolves({ element: this.foundRootDoc, path: {} })
|
|
|
+ deleteProject: sinon.stub().resolves()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- this.ProjectOptionsHandler = {
|
|
|
+ this.ProjectEntityMongoUpdateHandler = {
|
|
|
promises: {
|
|
|
- setCompiler: sinon.stub().resolves()
|
|
|
+ createNewFolderStructure: sinon.stub().resolves(this.newProjectVersion)
|
|
|
}
|
|
|
}
|
|
|
this.ProjectEntityUpdateHandler = {
|
|
|
- addDoc: sinon.stub().callsArgWith(5, null, { name: 'somDoc' }),
|
|
|
- copyFileFromExistingProjectWithProject: sinon.stub(),
|
|
|
- setRootDoc: sinon.stub(),
|
|
|
- addFolder: sinon.stub().callsArgWith(3, null, this.newFolder)
|
|
|
+ promises: {
|
|
|
+ setRootDoc: sinon.stub().resolves()
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- this.ProjectEntityUpdateHandler.copyFileFromExistingProjectWithProject
|
|
|
- .withArgs(
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- 'BROKEN-FILE',
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any
|
|
|
- )
|
|
|
- .callsArgWith(6, new Error('failed'))
|
|
|
- this.ProjectEntityUpdateHandler.copyFileFromExistingProjectWithProject
|
|
|
- .withArgs(
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.object,
|
|
|
- sinon.match.any
|
|
|
- )
|
|
|
- .callsArg(6)
|
|
|
- this.ProjectEntityUpdateHandler.copyFileFromExistingProjectWithProject
|
|
|
- .withArgs(
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- sinon.match.any,
|
|
|
- null,
|
|
|
- sinon.match.any
|
|
|
- )
|
|
|
- .callsArg(6)
|
|
|
-
|
|
|
- this.DocumentUpdaterHandler = {
|
|
|
+ this.ProjectGetter = {
|
|
|
promises: {
|
|
|
- flushProjectToMongo: sinon.stub().resolves()
|
|
|
+ getProject: sinon
|
|
|
+ .stub()
|
|
|
+ .withArgs(this.project._id)
|
|
|
+ .resolves(this.project)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- this.Project = {
|
|
|
+ this.ProjectLocator = {
|
|
|
promises: {
|
|
|
- findById: sinon.stub().resolves(this.project)
|
|
|
+ findRootDoc: sinon.stub().resolves({
|
|
|
+ element: this.rootDoc,
|
|
|
+ path: { fileSystem: this.rootDocPath }
|
|
|
+ }),
|
|
|
+ findElementByPath: sinon
|
|
|
+ .stub()
|
|
|
+ .withArgs({
|
|
|
+ project_id: this.newBlankProject._id,
|
|
|
+ path: this.rootDocPath,
|
|
|
+ exactCaseMatch: true
|
|
|
+ })
|
|
|
+ .resolves({ element: this.doc0 })
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- this.ProjectGetter = {
|
|
|
- getProject: sinon.stub(),
|
|
|
+ this.ProjectOptionsHandler = {
|
|
|
promises: {
|
|
|
- getProject: sinon.stub()
|
|
|
+ setCompiler: sinon.stub().resolves()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- this.ProjectGetter.getProject
|
|
|
- .withArgs(this.old_project_id, sinon.match.any)
|
|
|
- .callsArgWith(2, null, this.project)
|
|
|
- this.ProjectGetter.getProject
|
|
|
- .withArgs(this.new_project_id, sinon.match.any)
|
|
|
- .callsArgWith(2, null, this.stubbedNewProject)
|
|
|
- this.ProjectGetter.promises.getProject
|
|
|
- .withArgs(this.old_project_id, sinon.match.any)
|
|
|
- .resolves(this.project)
|
|
|
- this.ProjectGetter.promises.getProject
|
|
|
- .withArgs(this.new_project_id, sinon.match.any)
|
|
|
- .resolves(this.stubbedNewProject)
|
|
|
-
|
|
|
- this.ProjectDeleter = {
|
|
|
+ this.TpdsProjectFlusher = {
|
|
|
promises: {
|
|
|
- deleteProject: sinon.stub().resolves()
|
|
|
+ flushProjectToTpds: sinon.stub().resolves()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -169,16 +203,21 @@ describe('ProjectDuplicator', function() {
|
|
|
console: console
|
|
|
},
|
|
|
requires: {
|
|
|
- '../../models/Project': { Project: this.Project },
|
|
|
+ '../../models/Doc': { Doc: this.Doc },
|
|
|
+ '../../models/File': { File: this.File },
|
|
|
+ '../Docstore/DocstoreManager': this.DocstoreManager,
|
|
|
'../DocumentUpdater/DocumentUpdaterHandler': this
|
|
|
.DocumentUpdaterHandler,
|
|
|
+ '../FileStore/FileStoreHandler': this.FileStoreHandler,
|
|
|
'./ProjectCreationHandler': this.ProjectCreationHandler,
|
|
|
+ './ProjectDeleter': this.ProjectDeleter,
|
|
|
+ './ProjectEntityMongoUpdateHandler': this
|
|
|
+ .ProjectEntityMongoUpdateHandler,
|
|
|
'./ProjectEntityUpdateHandler': this.ProjectEntityUpdateHandler,
|
|
|
+ './ProjectGetter': this.ProjectGetter,
|
|
|
'./ProjectLocator': this.ProjectLocator,
|
|
|
- './ProjectDeleter': this.ProjectDeleter,
|
|
|
'./ProjectOptionsHandler': this.ProjectOptionsHandler,
|
|
|
- '../Docstore/DocstoreManager': this.DocstoreManager,
|
|
|
- './ProjectGetter': this.ProjectGetter,
|
|
|
+ '../ThirdPartyDataStore/TpdsProjectFlusher': this.TpdsProjectFlusher,
|
|
|
'logger-sharelatex': {
|
|
|
log() {},
|
|
|
warn() {},
|
|
|
@@ -189,186 +228,125 @@ describe('ProjectDuplicator', function() {
|
|
|
})
|
|
|
|
|
|
describe('when the copy succeeds', function() {
|
|
|
- it('should look up the original project', async function() {
|
|
|
- const newProjectName = 'someProj'
|
|
|
- await this.ProjectDuplicator.promises.duplicate(
|
|
|
+ beforeEach(async function() {
|
|
|
+ this.newProjectName = 'New project name'
|
|
|
+ this.newProject = await this.ProjectDuplicator.promises.duplicate(
|
|
|
this.owner,
|
|
|
- this.old_project_id,
|
|
|
- newProjectName
|
|
|
- )
|
|
|
- this.ProjectGetter.promises.getProject.should.have.been.calledWith(
|
|
|
- this.old_project_id
|
|
|
+ this.project._id,
|
|
|
+ this.newProjectName
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should flush the original project to mongo', async function() {
|
|
|
- const newProjectName = 'someProj'
|
|
|
- await this.ProjectDuplicator.promises.duplicate(
|
|
|
- this.owner,
|
|
|
- this.old_project_id,
|
|
|
- newProjectName
|
|
|
- )
|
|
|
+ it('should flush the original project to mongo', function() {
|
|
|
this.DocumentUpdaterHandler.promises.flushProjectToMongo.should.have.been.calledWith(
|
|
|
- this.old_project_id
|
|
|
+ this.project._id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should create a blank project', async function() {
|
|
|
- const newProjectName = 'someProj'
|
|
|
- const newProject = await this.ProjectDuplicator.promises.duplicate(
|
|
|
- this.owner,
|
|
|
- this.old_project_id,
|
|
|
- newProjectName
|
|
|
- )
|
|
|
- newProject._id.should.equal(this.stubbedNewProject._id)
|
|
|
+ it('should copy docs to docstore', function() {
|
|
|
+ for (const docLines of [this.doc0Lines, this.doc1Lines, this.doc2Lines]) {
|
|
|
+ this.DocstoreManager.promises.updateDoc.should.have.been.calledWith(
|
|
|
+ this.newProject._id.toString(),
|
|
|
+ this.newDocId.toString(),
|
|
|
+ docLines,
|
|
|
+ 0,
|
|
|
+ {}
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should copy files to the filestore', function() {
|
|
|
+ for (const file of [this.file0, this.file1, this.file2]) {
|
|
|
+ this.FileStoreHandler.promises.copyFile.should.have.been.calledWith(
|
|
|
+ this.project._id,
|
|
|
+ file._id,
|
|
|
+ this.newProject._id,
|
|
|
+ this.newFileId
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should create a blank project', function() {
|
|
|
this.ProjectCreationHandler.promises.createBlankProject.should.have.been.calledWith(
|
|
|
this.owner._id,
|
|
|
- newProjectName
|
|
|
+ this.newProjectName
|
|
|
)
|
|
|
+ this.newProject._id.should.equal(this.newBlankProject._id)
|
|
|
})
|
|
|
|
|
|
- it('should use the same compiler', async function() {
|
|
|
- this.ProjectEntityUpdateHandler.addDoc.callsArgWith(
|
|
|
- 5,
|
|
|
- null,
|
|
|
- this.rootFolder.docs[0],
|
|
|
- this.owner._id
|
|
|
- )
|
|
|
- await this.ProjectDuplicator.promises.duplicate(
|
|
|
- this.owner,
|
|
|
- this.old_project_id,
|
|
|
- ''
|
|
|
- )
|
|
|
+ it('should use the same compiler', function() {
|
|
|
this.ProjectOptionsHandler.promises.setCompiler.should.have.been.calledWith(
|
|
|
- this.stubbedNewProject._id,
|
|
|
+ this.newProject._id,
|
|
|
this.project.compiler
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should use the same root doc', async function() {
|
|
|
- this.ProjectEntityUpdateHandler.addDoc.callsArgWith(
|
|
|
- 5,
|
|
|
- null,
|
|
|
- this.rootFolder.docs[0],
|
|
|
- this.owner._id
|
|
|
- )
|
|
|
- await this.ProjectDuplicator.promises.duplicate(
|
|
|
- this.owner,
|
|
|
- this.old_project_id,
|
|
|
- ''
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.setRootDoc.should.have.been.calledWith(
|
|
|
- this.stubbedNewProject._id,
|
|
|
+ it('should use the same root doc', function() {
|
|
|
+ this.ProjectEntityUpdateHandler.promises.setRootDoc.should.have.been.calledWith(
|
|
|
+ this.newProject._id,
|
|
|
this.rootFolder.docs[0]._id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should not copy the collaberators or read only refs', async function() {
|
|
|
- const newProject = await this.ProjectDuplicator.promises.duplicate(
|
|
|
- this.owner,
|
|
|
- this.old_project_id,
|
|
|
- ''
|
|
|
- )
|
|
|
- newProject.collaberator_refs.length.should.equal(0)
|
|
|
- newProject.readOnly_refs.length.should.equal(0)
|
|
|
+ it('should not copy the collaborators or read only refs', function() {
|
|
|
+ this.newProject.collaberator_refs.length.should.equal(0)
|
|
|
+ this.newProject.readOnly_refs.length.should.equal(0)
|
|
|
})
|
|
|
|
|
|
- it('should copy all the folders', async function() {
|
|
|
- await this.ProjectDuplicator.promises.duplicate(
|
|
|
- this.owner,
|
|
|
- this.old_project_id,
|
|
|
- ''
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.addFolder.should.have.been.calledWith(
|
|
|
- this.new_project_id,
|
|
|
- this.stubbedNewProject.rootFolder[0]._id,
|
|
|
- this.level1folder.name
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.addFolder.should.have.been.calledWith(
|
|
|
- this.new_project_id,
|
|
|
- this.newFolder._id,
|
|
|
- this.level2folder.name
|
|
|
+ it('should copy all documents and files', function() {
|
|
|
+ this.ProjectEntityMongoUpdateHandler.promises.createNewFolderStructure.should.have.been.calledWith(
|
|
|
+ this.newProject._id,
|
|
|
+ this.docEntries,
|
|
|
+ this.fileEntries
|
|
|
)
|
|
|
- this.ProjectEntityUpdateHandler.addFolder.callCount.should.equal(2)
|
|
|
})
|
|
|
|
|
|
- it('should copy all the docs', async function() {
|
|
|
- await this.ProjectDuplicator.promises.duplicate(
|
|
|
- this.owner,
|
|
|
- this.old_project_id,
|
|
|
- ''
|
|
|
- )
|
|
|
- this.DocstoreManager.promises.getAllDocs.should.have.been.calledWith(
|
|
|
- this.old_project_id
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.addDoc.should.have.been.calledWith(
|
|
|
- this.new_project_id,
|
|
|
- this.stubbedNewProject.rootFolder[0]._id,
|
|
|
- this.doc0.name,
|
|
|
- this.doc0_lines,
|
|
|
- this.owner._id
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.addDoc.should.have.been.calledWith(
|
|
|
- this.new_project_id,
|
|
|
- this.newFolder._id,
|
|
|
- this.doc1.name,
|
|
|
- this.doc1_lines,
|
|
|
- this.owner._id
|
|
|
+ it('should notify document updater of changes', function() {
|
|
|
+ this.DocumentUpdaterHandler.promises.updateProjectStructure.should.have.been.calledWith(
|
|
|
+ this.newProject._id,
|
|
|
+ this.newProject.overleaf.history.id,
|
|
|
+ this.owner._id,
|
|
|
+ {
|
|
|
+ newDocs: this.docEntries,
|
|
|
+ newFiles: this.fileEntries,
|
|
|
+ newProject: { version: this.newProjectVersion }
|
|
|
+ }
|
|
|
)
|
|
|
- this.ProjectEntityUpdateHandler.addDoc.should.have.been.calledWith(
|
|
|
- this.new_project_id,
|
|
|
- this.newFolder._id,
|
|
|
- this.doc2.name,
|
|
|
- this.doc2_lines,
|
|
|
- this.owner._id
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should flush the project to TPDS', function() {
|
|
|
+ this.TpdsProjectFlusher.promises.flushProjectToTpds.should.have.been.calledWith(
|
|
|
+ this.newProject._id
|
|
|
)
|
|
|
})
|
|
|
+ })
|
|
|
|
|
|
- it('should copy all the files', async function() {
|
|
|
- await this.ProjectDuplicator.promises.duplicate(
|
|
|
+ describe('without a root doc', function() {
|
|
|
+ beforeEach(async function() {
|
|
|
+ this.ProjectLocator.promises.findRootDoc.resolves({
|
|
|
+ element: null,
|
|
|
+ path: null
|
|
|
+ })
|
|
|
+ this.newProject = await this.ProjectDuplicator.promises.duplicate(
|
|
|
this.owner,
|
|
|
- this.old_project_id,
|
|
|
- ''
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.copyFileFromExistingProjectWithProject.should.have.been.calledWith(
|
|
|
- this.stubbedNewProject._id,
|
|
|
- this.stubbedNewProject,
|
|
|
- this.stubbedNewProject.rootFolder[0]._id,
|
|
|
- this.project._id,
|
|
|
- this.rootFolder.fileRefs[0],
|
|
|
- this.owner._id
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.copyFileFromExistingProjectWithProject.should.have.been.calledWith(
|
|
|
- this.stubbedNewProject._id,
|
|
|
- this.stubbedNewProject,
|
|
|
- this.newFolder._id,
|
|
|
this.project._id,
|
|
|
- this.level1folder.fileRefs[0],
|
|
|
- this.owner._id
|
|
|
- )
|
|
|
- this.ProjectEntityUpdateHandler.copyFileFromExistingProjectWithProject.should.have.been.calledWith(
|
|
|
- this.stubbedNewProject._id,
|
|
|
- this.stubbedNewProject,
|
|
|
- this.newFolder._id,
|
|
|
- this.project._id,
|
|
|
- this.level2folder.fileRefs[0],
|
|
|
- this.owner._id
|
|
|
+ 'Copy of project'
|
|
|
)
|
|
|
})
|
|
|
+
|
|
|
+ it('should not set the root doc on the copy', function() {
|
|
|
+ this.ProjectEntityUpdateHandler.promises.setRootDoc.should.not.have.been
|
|
|
+ .called
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('when there is an error', function() {
|
|
|
beforeEach(async function() {
|
|
|
- this.rootFolder.fileRefs = [
|
|
|
- { name: 'file0', _id: 'file0' },
|
|
|
- 'BROKEN-FILE',
|
|
|
- { name: 'file1', _id: 'file1' },
|
|
|
- { name: 'file2', _id: 'file2' }
|
|
|
- ]
|
|
|
+ this.ProjectEntityMongoUpdateHandler.promises.createNewFolderStructure.rejects()
|
|
|
await expect(
|
|
|
this.ProjectDuplicator.promises.duplicate(
|
|
|
this.owner,
|
|
|
- this.old_project_id,
|
|
|
+ this.project._id,
|
|
|
''
|
|
|
)
|
|
|
).to.be.rejected
|
|
|
@@ -376,13 +354,13 @@ describe('ProjectDuplicator', function() {
|
|
|
|
|
|
it('should delete the broken cloned project', function() {
|
|
|
this.ProjectDeleter.promises.deleteProject.should.have.been.calledWith(
|
|
|
- this.stubbedNewProject._id
|
|
|
+ this.newBlankProject._id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should not delete the original project', function() {
|
|
|
this.ProjectDeleter.promises.deleteProject.should.not.have.been.calledWith(
|
|
|
- this.old_project_id
|
|
|
+ this.project._id
|
|
|
)
|
|
|
})
|
|
|
})
|