|
@@ -1,30 +1,11 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- camelcase,
|
|
|
|
|
- handle-callback-err,
|
|
|
|
|
- max-len,
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
- no-use-before-define,
|
|
|
|
|
-*/
|
|
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
|
|
-/*
|
|
|
|
|
- * decaffeinate suggestions:
|
|
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
- * DS207: Consider shorter variations of null checks
|
|
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
|
- */
|
|
|
|
|
-const spies = require('chai-spies')
|
|
|
|
|
-const chai = require('chai').use(spies)
|
|
|
|
|
-const { assert } = require('chai')
|
|
|
|
|
-const should = chai.should()
|
|
|
|
|
|
|
+const { expect } = require('chai')
|
|
|
const modulePath = '../../../../app/src/Features/Project/ProjectLocator'
|
|
const modulePath = '../../../../app/src/Features/Project/ProjectLocator'
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
const sinon = require('sinon')
|
|
const sinon = require('sinon')
|
|
|
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
|
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
|
|
-const { expect } = require('chai')
|
|
|
|
|
-var Project = (Project = class Project {})
|
|
|
|
|
|
|
|
|
|
const project = { _id: '1234566', rootFolder: [] }
|
|
const project = { _id: '1234566', rootFolder: [] }
|
|
|
|
|
+class Project {}
|
|
|
const rootDoc = { name: 'rootDoc', _id: 'das239djd' }
|
|
const rootDoc = { name: 'rootDoc', _id: 'das239djd' }
|
|
|
const doc1 = { name: 'otherDoc.txt', _id: 'dsad2ddd' }
|
|
const doc1 = { name: 'otherDoc.txt', _id: 'dsad2ddd' }
|
|
|
const doc2 = { name: 'docname.txt', _id: 'dsad2ddddd' }
|
|
const doc2 = { name: 'docname.txt', _id: 'dsad2ddddd' }
|
|
@@ -59,8 +40,8 @@ project.rootDoc_id = rootDoc._id
|
|
|
|
|
|
|
|
describe('ProjectLocator', function() {
|
|
describe('ProjectLocator', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
- Project.findById = (project_id, callback) => {
|
|
|
|
|
- return callback(null, project)
|
|
|
|
|
|
|
+ Project.findById = (projectId, callback) => {
|
|
|
|
|
+ callback(null, project)
|
|
|
}
|
|
}
|
|
|
this.ProjectGetter = {
|
|
this.ProjectGetter = {
|
|
|
getProject: sinon.stub().callsArgWith(2, null, project)
|
|
getProject: sinon.stub().callsArgWith(2, null, project)
|
|
@@ -68,7 +49,7 @@ describe('ProjectLocator', function() {
|
|
|
this.ProjectHelper = {
|
|
this.ProjectHelper = {
|
|
|
isArchived: sinon.stub()
|
|
isArchived: sinon.stub()
|
|
|
}
|
|
}
|
|
|
- return (this.locator = SandboxedModule.require(modulePath, {
|
|
|
|
|
|
|
+ this.locator = SandboxedModule.require(modulePath, {
|
|
|
globals: {
|
|
globals: {
|
|
|
console: console
|
|
console: console
|
|
|
},
|
|
},
|
|
@@ -83,46 +64,52 @@ describe('ProjectLocator', function() {
|
|
|
warn() {}
|
|
warn() {}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }))
|
|
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('finding a doc', function() {
|
|
describe('finding a doc', function() {
|
|
|
it('finds one at the root level', function(done) {
|
|
it('finds one at the root level', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: doc2._id, type: 'docs' },
|
|
{ project_id: project._id, element_id: doc2._id, type: 'docs' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(err == null)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(doc2._id)
|
|
foundElement._id.should.equal(doc2._id)
|
|
|
path.fileSystem.should.equal(`/${doc2.name}`)
|
|
path.fileSystem.should.equal(`/${doc2.name}`)
|
|
|
parentFolder._id.should.equal(project.rootFolder[0]._id)
|
|
parentFolder._id.should.equal(project.rootFolder[0]._id)
|
|
|
path.mongo.should.equal('rootFolder.0.docs.1')
|
|
path.mongo.should.equal('rootFolder.0.docs.1')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('when it is nested', function(done) {
|
|
it('when it is nested', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: subSubDoc._id, type: 'doc' },
|
|
{ project_id: project._id, element_id: subSubDoc._id, type: 'doc' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(err == null)
|
|
|
|
|
- should.equal(foundElement._id, subSubDoc._id)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ expect(foundElement._id).to.equal(subSubDoc._id)
|
|
|
path.fileSystem.should.equal(
|
|
path.fileSystem.should.equal(
|
|
|
`/${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
|
`/${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
|
|
)
|
|
)
|
|
|
parentFolder._id.should.equal(secondSubFolder._id)
|
|
parentFolder._id.should.equal(secondSubFolder._id)
|
|
|
path.mongo.should.equal('rootFolder.0.folders.1.folders.0.docs.0')
|
|
path.mongo.should.equal('rootFolder.0.folders.1.folders.0.docs.0')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should give error if element could not be found', function(done) {
|
|
it('should give error if element could not be found', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: 'ddsd432nj42', type: 'docs' },
|
|
{ project_id: project._id, element_id: 'ddsd432nj42', type: 'docs' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- err.should.deep.equal(new Errors.NotFoundError('entity not found'))
|
|
|
|
|
- return done()
|
|
|
|
|
|
|
+ expect(err).to.deep.equal(
|
|
|
|
|
+ new Errors.NotFoundError('entity not found')
|
|
|
|
|
+ )
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -130,46 +117,52 @@ describe('ProjectLocator', function() {
|
|
|
|
|
|
|
|
describe('finding a folder', function() {
|
|
describe('finding a folder', function() {
|
|
|
it('should return root folder when looking for root folder', function(done) {
|
|
it('should return root folder when looking for root folder', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: rootFolder._id, type: 'folder' },
|
|
{ project_id: project._id, element_id: rootFolder._id, type: 'folder' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(!err)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(rootFolder._id)
|
|
foundElement._id.should.equal(rootFolder._id)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('when at root', function(done) {
|
|
it('when at root', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: subFolder._id, type: 'folder' },
|
|
{ project_id: project._id, element_id: subFolder._id, type: 'folder' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(!err)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(subFolder._id)
|
|
foundElement._id.should.equal(subFolder._id)
|
|
|
path.fileSystem.should.equal(`/${subFolder.name}`)
|
|
path.fileSystem.should.equal(`/${subFolder.name}`)
|
|
|
parentFolder._id.should.equal(rootFolder._id)
|
|
parentFolder._id.should.equal(rootFolder._id)
|
|
|
path.mongo.should.equal('rootFolder.0.folders.1')
|
|
path.mongo.should.equal('rootFolder.0.folders.1')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('when deeply nested', function(done) {
|
|
it('when deeply nested', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{
|
|
{
|
|
|
project_id: project._id,
|
|
project_id: project._id,
|
|
|
element_id: secondSubFolder._id,
|
|
element_id: secondSubFolder._id,
|
|
|
type: 'folder'
|
|
type: 'folder'
|
|
|
},
|
|
},
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(!err)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(secondSubFolder._id)
|
|
foundElement._id.should.equal(secondSubFolder._id)
|
|
|
path.fileSystem.should.equal(
|
|
path.fileSystem.should.equal(
|
|
|
`/${subFolder.name}/${secondSubFolder.name}`
|
|
`/${subFolder.name}/${secondSubFolder.name}`
|
|
|
)
|
|
)
|
|
|
parentFolder._id.should.equal(subFolder._id)
|
|
parentFolder._id.should.equal(subFolder._id)
|
|
|
path.mongo.should.equal('rootFolder.0.folders.1.folders.0')
|
|
path.mongo.should.equal('rootFolder.0.folders.1.folders.0')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -177,35 +170,39 @@ describe('ProjectLocator', function() {
|
|
|
|
|
|
|
|
describe('finding a file', function() {
|
|
describe('finding a file', function() {
|
|
|
it('when at root', function(done) {
|
|
it('when at root', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: file1._id, type: 'fileRefs' },
|
|
{ project_id: project._id, element_id: file1._id, type: 'fileRefs' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(!err)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(file1._id)
|
|
foundElement._id.should.equal(file1._id)
|
|
|
path.fileSystem.should.equal(`/${file1.name}`)
|
|
path.fileSystem.should.equal(`/${file1.name}`)
|
|
|
parentFolder._id.should.equal(rootFolder._id)
|
|
parentFolder._id.should.equal(rootFolder._id)
|
|
|
path.mongo.should.equal('rootFolder.0.fileRefs.0')
|
|
path.mongo.should.equal('rootFolder.0.fileRefs.0')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('when deeply nested', function(done) {
|
|
it('when deeply nested', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{
|
|
{
|
|
|
project_id: project._id,
|
|
project_id: project._id,
|
|
|
element_id: subSubFile._id,
|
|
element_id: subSubFile._id,
|
|
|
type: 'fileRefs'
|
|
type: 'fileRefs'
|
|
|
},
|
|
},
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(!err)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(subSubFile._id)
|
|
foundElement._id.should.equal(subSubFile._id)
|
|
|
path.fileSystem.should.equal(
|
|
path.fileSystem.should.equal(
|
|
|
`/${subFolder.name}/${secondSubFolder.name}/${subSubFile.name}`
|
|
`/${subFolder.name}/${secondSubFolder.name}/${subSubFile.name}`
|
|
|
)
|
|
)
|
|
|
parentFolder._id.should.equal(secondSubFolder._id)
|
|
parentFolder._id.should.equal(secondSubFolder._id)
|
|
|
path.mongo.should.equal('rootFolder.0.folders.1.folders.0.fileRefs.0')
|
|
path.mongo.should.equal('rootFolder.0.folders.1.folders.0.fileRefs.0')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -213,23 +210,27 @@ describe('ProjectLocator', function() {
|
|
|
|
|
|
|
|
describe('finding an element with wrong element type', function() {
|
|
describe('finding an element with wrong element type', function() {
|
|
|
it('should add an s onto the element type', function(done) {
|
|
it('should add an s onto the element type', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: subSubDoc._id, type: 'doc' },
|
|
{ project_id: project._id, element_id: subSubDoc._id, type: 'doc' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(!err)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(subSubDoc._id)
|
|
foundElement._id.should.equal(subSubDoc._id)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should convert file to fileRefs', function(done) {
|
|
it('should convert file to fileRefs', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project_id: project._id, element_id: file1._id, type: 'fileRefs' },
|
|
{ project_id: project._id, element_id: file1._id, type: 'fileRefs' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(!err)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(file1._id)
|
|
foundElement._id.should.equal(file1._id)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -249,15 +250,17 @@ describe('ProjectLocator', function() {
|
|
|
rootFolder: [rootFolder2]
|
|
rootFolder: [rootFolder2]
|
|
|
}
|
|
}
|
|
|
it('should find doc in project', function(done) {
|
|
it('should find doc in project', function(done) {
|
|
|
- return this.locator.findElement(
|
|
|
|
|
|
|
+ this.locator.findElement(
|
|
|
{ project: project2, element_id: doc3._id, type: 'docs' },
|
|
{ project: project2, element_id: doc3._id, type: 'docs' },
|
|
|
(err, foundElement, path, parentFolder) => {
|
|
(err, foundElement, path, parentFolder) => {
|
|
|
- assert(err == null)
|
|
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
foundElement._id.should.equal(doc3._id)
|
|
foundElement._id.should.equal(doc3._id)
|
|
|
path.fileSystem.should.equal(`/${doc3.name}`)
|
|
path.fileSystem.should.equal(`/${doc3.name}`)
|
|
|
parentFolder._id.should.equal(project2.rootFolder[0]._id)
|
|
parentFolder._id.should.equal(project2.rootFolder[0]._id)
|
|
|
path.mongo.should.equal('rootFolder.0.docs.0')
|
|
path.mongo.should.equal('rootFolder.0.docs.0')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -265,36 +268,44 @@ describe('ProjectLocator', function() {
|
|
|
|
|
|
|
|
describe('finding root doc', function() {
|
|
describe('finding root doc', function() {
|
|
|
it('should return root doc when passed project', function(done) {
|
|
it('should return root doc when passed project', function(done) {
|
|
|
- return this.locator.findRootDoc(project, (err, doc) => {
|
|
|
|
|
- assert(err == null)
|
|
|
|
|
|
|
+ this.locator.findRootDoc(project, (err, doc) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
doc._id.should.equal(rootDoc._id)
|
|
doc._id.should.equal(rootDoc._id)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return root doc when passed project_id', function(done) {
|
|
it('should return root doc when passed project_id', function(done) {
|
|
|
- return this.locator.findRootDoc(project._id, (err, doc) => {
|
|
|
|
|
- assert(err == null)
|
|
|
|
|
|
|
+ this.locator.findRootDoc(project._id, (err, doc) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
doc._id.should.equal(rootDoc._id)
|
|
doc._id.should.equal(rootDoc._id)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return null when the project has no rootDoc', function(done) {
|
|
it('should return null when the project has no rootDoc', function(done) {
|
|
|
project.rootDoc_id = null
|
|
project.rootDoc_id = null
|
|
|
- return this.locator.findRootDoc(project, (err, doc) => {
|
|
|
|
|
- assert(err == null)
|
|
|
|
|
|
|
+ this.locator.findRootDoc(project, (err, doc) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
expect(doc).to.equal(null)
|
|
expect(doc).to.equal(null)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return null when the rootDoc_id no longer exists', function(done) {
|
|
it('should return null when the rootDoc_id no longer exists', function(done) {
|
|
|
project.rootDoc_id = 'doesntexist'
|
|
project.rootDoc_id = 'doesntexist'
|
|
|
- return this.locator.findRootDoc(project, (err, doc) => {
|
|
|
|
|
- assert(err == null)
|
|
|
|
|
|
|
+ this.locator.findRootDoc(project, (err, doc) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
expect(doc).to.equal(null)
|
|
expect(doc).to.equal(null)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -302,48 +313,60 @@ describe('ProjectLocator', function() {
|
|
|
describe('findElementByPath', function() {
|
|
describe('findElementByPath', function() {
|
|
|
it('should take a doc path and return the element for a root level document', function(done) {
|
|
it('should take a doc path and return the element for a root level document', function(done) {
|
|
|
const path = `${doc1.name}`
|
|
const path = `${doc1.name}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(doc1)
|
|
element.should.deep.equal(doc1)
|
|
|
expect(type).to.equal('doc')
|
|
expect(type).to.equal('doc')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should take a doc path and return the element for a root level document with a starting slash', function(done) {
|
|
it('should take a doc path and return the element for a root level document with a starting slash', function(done) {
|
|
|
const path = `/${doc1.name}`
|
|
const path = `/${doc1.name}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(doc1)
|
|
element.should.deep.equal(doc1)
|
|
|
expect(type).to.equal('doc')
|
|
expect(type).to.equal('doc')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should take a doc path and return the element for a nested document', function(done) {
|
|
it('should take a doc path and return the element for a nested document', function(done) {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(subSubDoc)
|
|
element.should.deep.equal(subSubDoc)
|
|
|
expect(type).to.equal('doc')
|
|
expect(type).to.equal('doc')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should take a file path and return the element for a root level document', function(done) {
|
|
it('should take a file path and return the element for a root level document', function(done) {
|
|
|
const path = `${file1.name}`
|
|
const path = `${file1.name}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(file1)
|
|
element.should.deep.equal(file1)
|
|
|
expect(type).to.equal('file')
|
|
expect(type).to.equal('file')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -352,74 +375,86 @@ describe('ProjectLocator', function() {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/${
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/${
|
|
|
subSubFile.name
|
|
subSubFile.name
|
|
|
}`
|
|
}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(subSubFile)
|
|
element.should.deep.equal(subSubFile)
|
|
|
expect(type).to.equal('file')
|
|
expect(type).to.equal('file')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should take a file path and return the element for a nested document case insenstive', function(done) {
|
|
it('should take a file path and return the element for a nested document case insenstive', function(done) {
|
|
|
const path = `${subFolder.name.toUpperCase()}/${secondSubFolder.name.toUpperCase()}/${subSubFile.name.toUpperCase()}`
|
|
const path = `${subFolder.name.toUpperCase()}/${secondSubFolder.name.toUpperCase()}/${subSubFile.name.toUpperCase()}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(subSubFile)
|
|
element.should.deep.equal(subSubFile)
|
|
|
expect(type).to.equal('file')
|
|
expect(type).to.equal('file')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should take a file path and return the element for a nested folder', function(done) {
|
|
it('should take a file path and return the element for a nested folder', function(done) {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}`
|
|
const path = `${subFolder.name}/${secondSubFolder.name}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(secondSubFolder)
|
|
element.should.deep.equal(secondSubFolder)
|
|
|
expect(type).to.equal('folder')
|
|
expect(type).to.equal('folder')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should take a file path and return the root folder', function(done) {
|
|
it('should take a file path and return the root folder', function(done) {
|
|
|
const path = '/'
|
|
const path = '/'
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.should.deep.equal(rootFolder)
|
|
element.should.deep.equal(rootFolder)
|
|
|
expect(type).to.equal('folder')
|
|
expect(type).to.equal('folder')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return an error if the file can not be found inside know folder', function(done) {
|
|
it('should return an error if the file can not be found inside know folder', function(done) {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/exist.txt`
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/exist.txt`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
err.should.not.equal(undefined)
|
|
err.should.not.equal(undefined)
|
|
|
- assert.equal(element, undefined)
|
|
|
|
|
|
|
+ expect(element).to.be.undefined
|
|
|
expect(type).to.be.undefined
|
|
expect(type).to.be.undefined
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return an error if the file can not be found inside unknown folder', function(done) {
|
|
it('should return an error if the file can not be found inside unknown folder', function(done) {
|
|
|
const path = 'this/does/not/exist.txt'
|
|
const path = 'this/does/not/exist.txt'
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project, path },
|
|
{ project, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
err.should.not.equal(undefined)
|
|
err.should.not.equal(undefined)
|
|
|
- assert.equal(element, undefined)
|
|
|
|
|
|
|
+ expect(element).to.be.undefined
|
|
|
expect(type).to.be.undefined
|
|
expect(type).to.be.undefined
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -440,7 +475,7 @@ describe('ProjectLocator', function() {
|
|
|
docs: [(this.doc = { name: 'main.tex', _id: '456' })],
|
|
docs: [(this.doc = { name: 'main.tex', _id: '456' })],
|
|
|
fileRefs: []
|
|
fileRefs: []
|
|
|
}
|
|
}
|
|
|
- return (this.project = {
|
|
|
|
|
|
|
+ this.project = {
|
|
|
rootFolder: [
|
|
rootFolder: [
|
|
|
{
|
|
{
|
|
|
folders: [this.duplicateFolder, this.duplicateFolder],
|
|
folders: [this.duplicateFolder, this.duplicateFolder],
|
|
@@ -448,29 +483,27 @@ describe('ProjectLocator', function() {
|
|
|
docs: []
|
|
docs: []
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not call the callback more than once', function(done) {
|
|
it('should not call the callback more than once', function(done) {
|
|
|
const path = `${this.duplicateFolder.name}/${this.doc.name}`
|
|
const path = `${this.duplicateFolder.name}/${this.doc.name}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
- { project: this.project, path },
|
|
|
|
|
- () => done()
|
|
|
|
|
|
|
+ this.locator.findElementByPath({ project: this.project, path }, () =>
|
|
|
|
|
+ done()
|
|
|
)
|
|
)
|
|
|
}) // mocha will throw exception if done called multiple times
|
|
}) // mocha will throw exception if done called multiple times
|
|
|
|
|
|
|
|
it('should not call the callback more than once when the path is longer than 1 level below the duplicate level', function(done) {
|
|
it('should not call the callback more than once when the path is longer than 1 level below the duplicate level', function(done) {
|
|
|
const path = `${this.duplicateFolder.name}/1/main.tex`
|
|
const path = `${this.duplicateFolder.name}/1/main.tex`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
- { project: this.project, path },
|
|
|
|
|
- () => done()
|
|
|
|
|
|
|
+ this.locator.findElementByPath({ project: this.project, path }, () =>
|
|
|
|
|
+ done()
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
}) // mocha will throw exception if done called multiple times
|
|
}) // mocha will throw exception if done called multiple times
|
|
|
|
|
|
|
|
describe('with a null doc', function() {
|
|
describe('with a null doc', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
- return (this.project = {
|
|
|
|
|
|
|
+ this.project = {
|
|
|
rootFolder: [
|
|
rootFolder: [
|
|
|
{
|
|
{
|
|
|
folders: [],
|
|
folders: [],
|
|
@@ -478,16 +511,19 @@ describe('ProjectLocator', function() {
|
|
|
docs: [{ name: 'main.tex' }, null, { name: 'other.tex' }]
|
|
docs: [{ name: 'main.tex' }, null, { name: 'other.tex' }]
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not crash with a null', function(done) {
|
|
it('should not crash with a null', function(done) {
|
|
|
const path = '/other.tex'
|
|
const path = '/other.tex'
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project: this.project, path },
|
|
{ project: this.project, path },
|
|
|
(err, element) => {
|
|
(err, element) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
element.name.should.equal('other.tex')
|
|
element.name.should.equal('other.tex')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -495,16 +531,16 @@ describe('ProjectLocator', function() {
|
|
|
|
|
|
|
|
describe('with a null project', function() {
|
|
describe('with a null project', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
- return (this.ProjectGetter = { getProject: sinon.stub().callsArg(2) })
|
|
|
|
|
|
|
+ this.ProjectGetter = { getProject: sinon.stub().callsArg(2) }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not crash with a null', function(done) {
|
|
it('should not crash with a null', function(done) {
|
|
|
const path = '/other.tex'
|
|
const path = '/other.tex'
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project_id: project._id, path },
|
|
{ project_id: project._id, path },
|
|
|
(err, element) => {
|
|
(err, element) => {
|
|
|
expect(err).to.exist
|
|
expect(err).to.exist
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -513,15 +549,18 @@ describe('ProjectLocator', function() {
|
|
|
describe('with a project_id', function() {
|
|
describe('with a project_id', function() {
|
|
|
it('should take a doc path and return the element for a root level document', function(done) {
|
|
it('should take a doc path and return the element for a root level document', function(done) {
|
|
|
const path = `${doc1.name}`
|
|
const path = `${doc1.name}`
|
|
|
- return this.locator.findElementByPath(
|
|
|
|
|
|
|
+ this.locator.findElementByPath(
|
|
|
{ project_id: project._id, path },
|
|
{ project_id: project._id, path },
|
|
|
(err, element, type) => {
|
|
(err, element, type) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
this.ProjectGetter.getProject
|
|
this.ProjectGetter.getProject
|
|
|
.calledWith(project._id, { rootFolder: true, rootDoc_id: true })
|
|
.calledWith(project._id, { rootFolder: true, rootDoc_id: true })
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
element.should.deep.equal(doc1)
|
|
element.should.deep.equal(doc1)
|
|
|
expect(type).to.equal('doc')
|
|
expect(type).to.equal('doc')
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -530,7 +569,7 @@ describe('ProjectLocator', function() {
|
|
|
|
|
|
|
|
describe('findUsersProjectByName finding a project by user_id and project name', function() {
|
|
describe('findUsersProjectByName finding a project by user_id and project name', function() {
|
|
|
it('should return the project from an array case insenstive', function(done) {
|
|
it('should return the project from an array case insenstive', function(done) {
|
|
|
- const user_id = '123jojoidns'
|
|
|
|
|
|
|
+ const userId = '123jojoidns'
|
|
|
const stubbedProject = { name: 'findThis' }
|
|
const stubbedProject = { name: 'findThis' }
|
|
|
const projects = {
|
|
const projects = {
|
|
|
owned: [
|
|
owned: [
|
|
@@ -543,18 +582,21 @@ describe('ProjectLocator', function() {
|
|
|
this.ProjectGetter.findAllUsersProjects = sinon
|
|
this.ProjectGetter.findAllUsersProjects = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.callsArgWith(2, null, projects)
|
|
.callsArgWith(2, null, projects)
|
|
|
- return this.locator.findUsersProjectByName(
|
|
|
|
|
- user_id,
|
|
|
|
|
|
|
+ this.locator.findUsersProjectByName(
|
|
|
|
|
+ userId,
|
|
|
stubbedProject.name.toLowerCase(),
|
|
stubbedProject.name.toLowerCase(),
|
|
|
(err, project) => {
|
|
(err, project) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
project.should.equal(stubbedProject)
|
|
project.should.equal(stubbedProject)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should return the project which is not archived', function(done) {
|
|
it('should return the project which is not archived', function(done) {
|
|
|
- const user_id = '123jojoidns'
|
|
|
|
|
|
|
+ const userId = '123jojoidns'
|
|
|
const stubbedProject = { name: 'findThis', _id: 12331321 }
|
|
const stubbedProject = { name: 'findThis', _id: 12331321 }
|
|
|
const projects = {
|
|
const projects = {
|
|
|
owned: [
|
|
owned: [
|
|
@@ -568,39 +610,42 @@ describe('ProjectLocator', function() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.ProjectHelper.isArchived
|
|
this.ProjectHelper.isArchived
|
|
|
- .withArgs(projects.owned[0], user_id)
|
|
|
|
|
|
|
+ .withArgs(projects.owned[0], userId)
|
|
|
.returns(false)
|
|
.returns(false)
|
|
|
this.ProjectHelper.isArchived
|
|
this.ProjectHelper.isArchived
|
|
|
- .withArgs(projects.owned[1], user_id)
|
|
|
|
|
|
|
+ .withArgs(projects.owned[1], userId)
|
|
|
.returns(false)
|
|
.returns(false)
|
|
|
this.ProjectHelper.isArchived
|
|
this.ProjectHelper.isArchived
|
|
|
- .withArgs(projects.owned[2], user_id)
|
|
|
|
|
|
|
+ .withArgs(projects.owned[2], userId)
|
|
|
.returns(true)
|
|
.returns(true)
|
|
|
this.ProjectHelper.isArchived
|
|
this.ProjectHelper.isArchived
|
|
|
- .withArgs(projects.owned[3], user_id)
|
|
|
|
|
|
|
+ .withArgs(projects.owned[3], userId)
|
|
|
.returns(false)
|
|
.returns(false)
|
|
|
this.ProjectHelper.isArchived
|
|
this.ProjectHelper.isArchived
|
|
|
- .withArgs(projects.owned[4], user_id)
|
|
|
|
|
|
|
+ .withArgs(projects.owned[4], userId)
|
|
|
.returns(true)
|
|
.returns(true)
|
|
|
this.ProjectHelper.isArchived
|
|
this.ProjectHelper.isArchived
|
|
|
- .withArgs(projects.owned[5], user_id)
|
|
|
|
|
|
|
+ .withArgs(projects.owned[5], userId)
|
|
|
.returns(false)
|
|
.returns(false)
|
|
|
|
|
|
|
|
this.ProjectGetter.findAllUsersProjects = sinon
|
|
this.ProjectGetter.findAllUsersProjects = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.callsArgWith(2, null, projects)
|
|
.callsArgWith(2, null, projects)
|
|
|
- return this.locator.findUsersProjectByName(
|
|
|
|
|
- user_id,
|
|
|
|
|
|
|
+ this.locator.findUsersProjectByName(
|
|
|
|
|
+ userId,
|
|
|
stubbedProject.name.toLowerCase(),
|
|
stubbedProject.name.toLowerCase(),
|
|
|
(err, project) => {
|
|
(err, project) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
project._id.should.equal(stubbedProject._id)
|
|
project._id.should.equal(stubbedProject._id)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should search collab projects as well', function(done) {
|
|
it('should search collab projects as well', function(done) {
|
|
|
- const user_id = '123jojoidns'
|
|
|
|
|
|
|
+ const userId = '123jojoidns'
|
|
|
const stubbedProject = { name: 'findThis' }
|
|
const stubbedProject = { name: 'findThis' }
|
|
|
const projects = {
|
|
const projects = {
|
|
|
owned: [{ name: 'notThis' }, { name: 'wellll' }, { name: 'Noooo' }],
|
|
owned: [{ name: 'notThis' }, { name: 'wellll' }, { name: 'Noooo' }],
|
|
@@ -609,12 +654,15 @@ describe('ProjectLocator', function() {
|
|
|
this.ProjectGetter.findAllUsersProjects = sinon
|
|
this.ProjectGetter.findAllUsersProjects = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.callsArgWith(2, null, projects)
|
|
.callsArgWith(2, null, projects)
|
|
|
- return this.locator.findUsersProjectByName(
|
|
|
|
|
- user_id,
|
|
|
|
|
|
|
+ this.locator.findUsersProjectByName(
|
|
|
|
|
+ userId,
|
|
|
stubbedProject.name.toLowerCase(),
|
|
stubbedProject.name.toLowerCase(),
|
|
|
(err, project) => {
|
|
(err, project) => {
|
|
|
|
|
+ if (err != null) {
|
|
|
|
|
+ return done(err)
|
|
|
|
|
+ }
|
|
|
project.should.equal(stubbedProject)
|
|
project.should.equal(stubbedProject)
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|