|
|
@@ -7,7 +7,6 @@
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
/*
|
|
|
* decaffeinate suggestions:
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
*/
|
|
|
const sinon = require('sinon')
|
|
|
@@ -17,11 +16,13 @@ const modulePath =
|
|
|
'../../../../app/src/Features/Uploads/ProjectUploadManager.js'
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
+const promiseStub = val => new Promise(resolve => resolve(val))
|
|
|
+
|
|
|
describe('ProjectUploadManager', function() {
|
|
|
beforeEach(function() {
|
|
|
this.project_id = 'project-id-123'
|
|
|
this.folder_id = 'folder-id-123'
|
|
|
- this.owner_id = 'onwer-id-123'
|
|
|
+ this.owner_id = 'owner-id-123'
|
|
|
this.callback = sinon.stub()
|
|
|
this.source = '/path/to/zip/file-name.zip'
|
|
|
this.destination = '/path/to/zile/file-extracted'
|
|
|
@@ -36,16 +37,25 @@ describe('ProjectUploadManager', function() {
|
|
|
this.ProjectUploadManager = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
|
'./FileSystemImportManager': (this.FileSystemImportManager = {}),
|
|
|
- './ArchiveManager': (this.ArchiveManager = {}),
|
|
|
- '../Project/ProjectCreationHandler': (this.ProjectCreationHandler = {}),
|
|
|
- '../Project/ProjectRootDocManager': (this.ProjectRootDocManager = {}),
|
|
|
- '../Project/ProjectDetailsHandler': (this.ProjectDetailsHandler = {}),
|
|
|
+ './ArchiveManager': (this.ArchiveManager = { promises: {} }),
|
|
|
+ '../Project/ProjectCreationHandler': (this.ProjectCreationHandler = {
|
|
|
+ promises: {}
|
|
|
+ }),
|
|
|
+ '../Project/ProjectRootDocManager': (this.ProjectRootDocManager = {
|
|
|
+ promises: {}
|
|
|
+ }),
|
|
|
+ '../Project/ProjectDetailsHandler': (this.ProjectDetailsHandler = {
|
|
|
+ promises: {}
|
|
|
+ }),
|
|
|
'../Documents/DocumentHelper': (this.DocumentHelper = {}),
|
|
|
rimraf: (this.rimraf = sinon.stub().callsArg(1))
|
|
|
}
|
|
|
})
|
|
|
|
|
|
this.ArchiveManager.extractZipArchive = sinon.stub().callsArg(2)
|
|
|
+ this.ArchiveManager.promises.extractZipArchive = sinon
|
|
|
+ .stub()
|
|
|
+ .returns(promiseStub())
|
|
|
this.ArchiveManager.findTopLevelDirectory = sinon
|
|
|
.stub()
|
|
|
.callsArgWith(
|
|
|
@@ -53,17 +63,19 @@ describe('ProjectUploadManager', function() {
|
|
|
null,
|
|
|
(this.topLevelDestination = '/path/to/zip/file-extracted/nested')
|
|
|
)
|
|
|
- this.ProjectCreationHandler.createBlankProject = sinon
|
|
|
+ this.ProjectCreationHandler.promises.createBlankProject = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(2, null, this.project)
|
|
|
- this.ProjectRootDocManager.setRootDocAutomatically = sinon
|
|
|
+ .returns(promiseStub(this.project))
|
|
|
+ this.ProjectRootDocManager.promises.setRootDocAutomatically = sinon
|
|
|
.stub()
|
|
|
- .callsArg(1)
|
|
|
+ .returns(promiseStub())
|
|
|
this.FileSystemImportManager.addFolderContents = sinon.stub().callsArg(5)
|
|
|
- this.ProjectRootDocManager.findRootDocFileFromDirectory = sinon
|
|
|
+ this.ProjectRootDocManager.promises.findRootDocFileFromDirectory = sinon
|
|
|
+ .stub()
|
|
|
+ .returns(promiseStub({ path: 'main.tex', content: this.othername }))
|
|
|
+ this.ProjectRootDocManager.promises.setRootDocFromName = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, 'main.tex', this.othername)
|
|
|
- this.ProjectRootDocManager.setRootDocFromName = sinon.stub().callsArg(2)
|
|
|
+ .returns(promiseStub())
|
|
|
this.DocumentHelper.getTitleFromTexContent = sinon
|
|
|
.stub()
|
|
|
.returns(this.othername)
|
|
|
@@ -78,9 +90,9 @@ describe('ProjectUploadManager', function() {
|
|
|
this.ProjectUploadManager._getDestinationDirectory = sinon
|
|
|
.stub()
|
|
|
.returns(this.destination)
|
|
|
- this.ProjectDetailsHandler.generateUniqueName = sinon
|
|
|
+ this.ProjectDetailsHandler.promises.generateUniqueName = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(2, null, this.othername)
|
|
|
+ .returns(promiseStub(this.othername))
|
|
|
return this.ProjectUploadManager.createProjectFromZipArchive(
|
|
|
this.owner_id,
|
|
|
this.name,
|
|
|
@@ -93,25 +105,25 @@ describe('ProjectUploadManager', function() {
|
|
|
})
|
|
|
|
|
|
it('should set up the directory to extract the archive to', function() {
|
|
|
- return this.ProjectUploadManager._getDestinationDirectory
|
|
|
+ this.ProjectUploadManager._getDestinationDirectory
|
|
|
.calledWith(this.source)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should extract the archive', function() {
|
|
|
- return this.ArchiveManager.extractZipArchive
|
|
|
+ this.ArchiveManager.promises.extractZipArchive
|
|
|
.calledWith(this.source, this.destination)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should find the top level directory', function() {
|
|
|
- return this.ArchiveManager.findTopLevelDirectory
|
|
|
+ this.ArchiveManager.findTopLevelDirectory
|
|
|
.calledWith(this.destination)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should insert the extracted archive into the folder', function() {
|
|
|
- return this.FileSystemImportManager.addFolderContents
|
|
|
+ this.FileSystemImportManager.addFolderContents
|
|
|
.calledWith(
|
|
|
this.owner_id,
|
|
|
this.project_id,
|
|
|
@@ -123,31 +135,29 @@ describe('ProjectUploadManager', function() {
|
|
|
})
|
|
|
|
|
|
it('should create a project owned by the owner_id', function() {
|
|
|
- return this.ProjectCreationHandler.createBlankProject
|
|
|
+ this.ProjectCreationHandler.promises.createBlankProject
|
|
|
.calledWith(this.owner_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should create a project with the correct name', function() {
|
|
|
- return this.ProjectCreationHandler.createBlankProject
|
|
|
+ this.ProjectCreationHandler.promises.createBlankProject
|
|
|
.calledWith(sinon.match.any, this.othername)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should read the title from the tex contents', function() {
|
|
|
- return this.DocumentHelper.getTitleFromTexContent.called.should.equal(
|
|
|
- true
|
|
|
- )
|
|
|
+ this.DocumentHelper.getTitleFromTexContent.called.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should set the root document', function() {
|
|
|
- return this.ProjectRootDocManager.setRootDocFromName
|
|
|
+ this.ProjectRootDocManager.promises.setRootDocFromName
|
|
|
.calledWith(this.project_id, 'main.tex')
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should call the callback', function() {
|
|
|
- return this.callback
|
|
|
+ this.callback
|
|
|
.calledWith(sinon.match.falsy, this.project)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -161,15 +171,16 @@ describe('ProjectUploadManager', function() {
|
|
|
|
|
|
describe("when the root document can't be determined", function() {
|
|
|
beforeEach(function(done) {
|
|
|
- this.ProjectRootDocManager.findRootDocFileFromDirectory = sinon
|
|
|
+ this.ProjectRootDocManager.promises.findRootDocFileFromDirectory = sinon
|
|
|
.stub()
|
|
|
- .callsArg(1)
|
|
|
+ .returns(promiseStub())
|
|
|
this.ProjectUploadManager._getDestinationDirectory = sinon
|
|
|
.stub()
|
|
|
.returns(this.destination)
|
|
|
- this.ProjectDetailsHandler.generateUniqueName = sinon
|
|
|
+ this.ProjectDetailsHandler.promises.generateUniqueName = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(2, null, this.name)
|
|
|
+ .returns(promiseStub(this.name))
|
|
|
+
|
|
|
return this.ProjectUploadManager.createProjectFromZipArchive(
|
|
|
this.owner_id,
|
|
|
this.name,
|
|
|
@@ -182,7 +193,7 @@ describe('ProjectUploadManager', function() {
|
|
|
})
|
|
|
|
|
|
it('should not try to set the root doc', function() {
|
|
|
- return this.ProjectRootDocManager.setRootDocFromName.called.should.equal(
|
|
|
+ this.ProjectRootDocManager.promises.setRootDocFromName.called.should.equal(
|
|
|
false
|
|
|
)
|
|
|
})
|
|
|
@@ -191,16 +202,15 @@ describe('ProjectUploadManager', function() {
|
|
|
|
|
|
describe('createProjectFromZipArchiveWithName', function() {
|
|
|
beforeEach(function(done) {
|
|
|
- this.ProjectDetailsHandler.generateUniqueName = sinon
|
|
|
+ this.ProjectDetailsHandler.promises.generateUniqueName = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(2, null, this.name)
|
|
|
- // createBlankProject allows taking optional attributes and will callback the last arg
|
|
|
- this.ProjectCreationHandler.createBlankProject = sinon
|
|
|
+ .returns(promiseStub(this.name))
|
|
|
+ this.ProjectCreationHandler.promises.createBlankProject = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(3, null, this.project)
|
|
|
- this.ProjectUploadManager.insertZipArchiveIntoFolder = sinon
|
|
|
+ .returns(promiseStub(this.project))
|
|
|
+ this.ProjectUploadManager.promises.insertZipArchiveIntoFolder = sinon
|
|
|
.stub()
|
|
|
- .callsArg(4)
|
|
|
+ .returns(promiseStub())
|
|
|
return this.ProjectUploadManager.createProjectFromZipArchiveWithName(
|
|
|
this.owner_id,
|
|
|
this.name,
|
|
|
@@ -213,19 +223,19 @@ describe('ProjectUploadManager', function() {
|
|
|
})
|
|
|
|
|
|
it('should create a project owned by the owner_id', function() {
|
|
|
- return this.ProjectCreationHandler.createBlankProject
|
|
|
+ this.ProjectCreationHandler.promises.createBlankProject
|
|
|
.calledWith(this.owner_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should create a project with the correct name', function() {
|
|
|
- return this.ProjectCreationHandler.createBlankProject
|
|
|
+ this.ProjectCreationHandler.promises.createBlankProject
|
|
|
.calledWith(sinon.match.any, this.name)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should insert the zip file contents into the root folder', function() {
|
|
|
- return this.ProjectUploadManager.insertZipArchiveIntoFolder
|
|
|
+ this.ProjectUploadManager.promises.insertZipArchiveIntoFolder
|
|
|
.calledWith(
|
|
|
this.owner_id,
|
|
|
this.project_id,
|
|
|
@@ -236,7 +246,7 @@ describe('ProjectUploadManager', function() {
|
|
|
})
|
|
|
|
|
|
it('should automatically set the root doc', function() {
|
|
|
- return this.ProjectRootDocManager.setRootDocAutomatically
|
|
|
+ this.ProjectRootDocManager.promises.setRootDocAutomatically
|
|
|
.calledWith(this.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -266,25 +276,25 @@ describe('ProjectUploadManager', function() {
|
|
|
})
|
|
|
|
|
|
it('should set up the directory to extract the archive to', function() {
|
|
|
- return this.ProjectUploadManager._getDestinationDirectory
|
|
|
+ this.ProjectUploadManager._getDestinationDirectory
|
|
|
.calledWith(this.source)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should extract the archive', function() {
|
|
|
- return this.ArchiveManager.extractZipArchive
|
|
|
+ this.ArchiveManager.extractZipArchive
|
|
|
.calledWith(this.source, this.destination)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should find the top level directory', function() {
|
|
|
- return this.ArchiveManager.findTopLevelDirectory
|
|
|
+ this.ArchiveManager.findTopLevelDirectory
|
|
|
.calledWith(this.destination)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should insert the extracted archive into the folder', function() {
|
|
|
- return this.FileSystemImportManager.addFolderContents
|
|
|
+ this.FileSystemImportManager.addFolderContents
|
|
|
.calledWith(
|
|
|
this.owner_id,
|
|
|
this.project_id,
|
|
|
@@ -296,11 +306,11 @@ describe('ProjectUploadManager', function() {
|
|
|
})
|
|
|
|
|
|
it('should return the callback', function() {
|
|
|
- return this.callback.called.should.equal(true)
|
|
|
+ this.callback.called.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should remove the desintation directory afterwards', function() {
|
|
|
- return this.rimraf.calledWith(this.destination).should.equal(true)
|
|
|
+ this.rimraf.calledWith(this.destination).should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -311,6 +321,6 @@ describe('ProjectUploadManager', function() {
|
|
|
this.ProjectUploadManager._getDestinationDirectory(
|
|
|
'/path/to/zip/file.zip'
|
|
|
).should.equal(`/path/to/zip/file-${date}`)
|
|
|
- return Date.now.restore()
|
|
|
+ Date.now.restore()
|
|
|
}))
|
|
|
})
|