|
|
@@ -5,7 +5,6 @@ const sinon = require('sinon')
|
|
|
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
|
|
|
|
|
const project = { _id: '1234566', rootFolder: [] }
|
|
|
-class Project {}
|
|
|
const rootDoc = { name: 'rootDoc', _id: 'das239djd' }
|
|
|
const doc1 = { name: 'otherDoc.txt', _id: 'dsad2ddd' }
|
|
|
const doc2 = { name: 'docname.txt', _id: 'dsad2ddddd' }
|
|
|
@@ -40,9 +39,6 @@ project.rootDoc_id = rootDoc._id
|
|
|
|
|
|
describe('ProjectLocator', function () {
|
|
|
beforeEach(function () {
|
|
|
- Project.findById = (projectId, callback) => {
|
|
|
- callback(null, project)
|
|
|
- }
|
|
|
this.ProjectGetter = {
|
|
|
getProject: sinon.stub().callsArgWith(2, null, project),
|
|
|
}
|
|
|
@@ -53,7 +49,6 @@ describe('ProjectLocator', function () {
|
|
|
}
|
|
|
this.locator = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
|
- '../../models/Project': { Project },
|
|
|
'../../models/User': { User: this.User },
|
|
|
'./ProjectGetter': this.ProjectGetter,
|
|
|
'./ProjectHelper': this.ProjectHelper,
|
|
|
@@ -62,170 +57,152 @@ describe('ProjectLocator', function () {
|
|
|
})
|
|
|
|
|
|
describe('finding a doc', function () {
|
|
|
- it('finds one at the root level', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: doc2._id, type: 'docs' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(doc2._id)
|
|
|
- path.fileSystem.should.equal(`/${doc2.name}`)
|
|
|
- parentFolder._id.should.equal(project.rootFolder[0]._id)
|
|
|
- path.mongo.should.equal('rootFolder.0.docs.1')
|
|
|
- done()
|
|
|
+ it('finds one at the root level', async function () {
|
|
|
+ const { element, path, folder } = await this.locator.promises.findElement(
|
|
|
+ {
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: doc2._id,
|
|
|
+ type: 'docs',
|
|
|
}
|
|
|
)
|
|
|
+ element._id.should.equal(doc2._id)
|
|
|
+ path.fileSystem.should.equal(`/${doc2.name}`)
|
|
|
+ folder._id.should.equal(project.rootFolder[0]._id)
|
|
|
+ path.mongo.should.equal('rootFolder.0.docs.1')
|
|
|
})
|
|
|
|
|
|
- it('when it is nested', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: subSubDoc._id, type: 'doc' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- expect(foundElement._id).to.equal(subSubDoc._id)
|
|
|
- path.fileSystem.should.equal(
|
|
|
- `/${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
|
|
- )
|
|
|
- parentFolder._id.should.equal(secondSubFolder._id)
|
|
|
- path.mongo.should.equal('rootFolder.0.folders.1.folders.0.docs.0')
|
|
|
- done()
|
|
|
+ it('when it is nested', async function () {
|
|
|
+ const { element, path, folder } = await this.locator.promises.findElement(
|
|
|
+ {
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: subSubDoc._id,
|
|
|
+ type: 'doc',
|
|
|
}
|
|
|
)
|
|
|
+ expect(element._id).to.equal(subSubDoc._id)
|
|
|
+ path.fileSystem.should.equal(
|
|
|
+ `/${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
|
|
+ )
|
|
|
+ folder._id.should.equal(secondSubFolder._id)
|
|
|
+ path.mongo.should.equal('rootFolder.0.folders.1.folders.0.docs.0')
|
|
|
})
|
|
|
|
|
|
- it('should give error if element could not be found', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: 'ddsd432nj42', type: 'docs' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- expect(err).to.be.instanceOf(Errors.NotFoundError)
|
|
|
- expect(err).to.have.property('message', 'entity not found')
|
|
|
- done()
|
|
|
- }
|
|
|
+ it('should give error if element could not be found', async function () {
|
|
|
+ await expect(
|
|
|
+ this.locator.promises.findElement({
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: 'ddsd432nj42',
|
|
|
+ type: 'docs',
|
|
|
+ })
|
|
|
)
|
|
|
+ .to.eventually.be.rejectedWith(Errors.NotFoundError)
|
|
|
+ .and.eventually.have.property('message', 'entity not found')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('finding a folder', function () {
|
|
|
- it('should return root folder when looking for root folder', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: rootFolder._id, type: 'folder' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(rootFolder._id)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('when at root', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: subFolder._id, type: 'folder' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(subFolder._id)
|
|
|
- path.fileSystem.should.equal(`/${subFolder.name}`)
|
|
|
- parentFolder._id.should.equal(rootFolder._id)
|
|
|
- path.mongo.should.equal('rootFolder.0.folders.1')
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('when deeply nested', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
+ it('should return root folder when looking for root folder', async function () {
|
|
|
+ const { element: foundElement } = await this.locator.promises.findElement(
|
|
|
{
|
|
|
project_id: project._id,
|
|
|
- element_id: secondSubFolder._id,
|
|
|
+ element_id: rootFolder._id,
|
|
|
type: 'folder',
|
|
|
- },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(secondSubFolder._id)
|
|
|
- path.fileSystem.should.equal(
|
|
|
- `/${subFolder.name}/${secondSubFolder.name}`
|
|
|
- )
|
|
|
- parentFolder._id.should.equal(subFolder._id)
|
|
|
- path.mongo.should.equal('rootFolder.0.folders.1.folders.0')
|
|
|
- done()
|
|
|
}
|
|
|
)
|
|
|
+ foundElement._id.should.equal(rootFolder._id)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('when at root', async function () {
|
|
|
+ const {
|
|
|
+ element: foundElement,
|
|
|
+ path,
|
|
|
+ folder: parentFolder,
|
|
|
+ } = await this.locator.promises.findElement({
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: subFolder._id,
|
|
|
+ type: 'folder',
|
|
|
+ })
|
|
|
+ foundElement._id.should.equal(subFolder._id)
|
|
|
+ path.fileSystem.should.equal(`/${subFolder.name}`)
|
|
|
+ parentFolder._id.should.equal(rootFolder._id)
|
|
|
+ path.mongo.should.equal('rootFolder.0.folders.1')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('when deeply nested', async function () {
|
|
|
+ const {
|
|
|
+ element: foundElement,
|
|
|
+ path,
|
|
|
+ folder: parentFolder,
|
|
|
+ } = await this.locator.promises.findElement({
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: secondSubFolder._id,
|
|
|
+ type: 'folder',
|
|
|
+ })
|
|
|
+
|
|
|
+ foundElement._id.should.equal(secondSubFolder._id)
|
|
|
+ path.fileSystem.should.equal(`/${subFolder.name}/${secondSubFolder.name}`)
|
|
|
+ parentFolder._id.should.equal(subFolder._id)
|
|
|
+ path.mongo.should.equal('rootFolder.0.folders.1.folders.0')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('finding a file', function () {
|
|
|
- it('when at root', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: file1._id, type: 'fileRefs' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(file1._id)
|
|
|
- path.fileSystem.should.equal(`/${file1.name}`)
|
|
|
- parentFolder._id.should.equal(rootFolder._id)
|
|
|
- path.mongo.should.equal('rootFolder.0.fileRefs.0')
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('when deeply nested', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- {
|
|
|
- project_id: project._id,
|
|
|
- element_id: subSubFile._id,
|
|
|
- type: 'fileRefs',
|
|
|
- },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(subSubFile._id)
|
|
|
- path.fileSystem.should.equal(
|
|
|
- `/${subFolder.name}/${secondSubFolder.name}/${subSubFile.name}`
|
|
|
- )
|
|
|
- parentFolder._id.should.equal(secondSubFolder._id)
|
|
|
- path.mongo.should.equal('rootFolder.0.folders.1.folders.0.fileRefs.0')
|
|
|
- done()
|
|
|
- }
|
|
|
+ it('when at root', async function () {
|
|
|
+ const {
|
|
|
+ element: foundElement,
|
|
|
+ path,
|
|
|
+ folder: parentFolder,
|
|
|
+ } = await this.locator.promises.findElement({
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: file1._id,
|
|
|
+ type: 'fileRefs',
|
|
|
+ })
|
|
|
+ foundElement._id.should.equal(file1._id)
|
|
|
+ path.fileSystem.should.equal(`/${file1.name}`)
|
|
|
+ parentFolder._id.should.equal(rootFolder._id)
|
|
|
+ path.mongo.should.equal('rootFolder.0.fileRefs.0')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('when deeply nested', async function () {
|
|
|
+ const {
|
|
|
+ element: foundElement,
|
|
|
+ path,
|
|
|
+ folder: parentFolder,
|
|
|
+ } = await this.locator.promises.findElement({
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: subSubFile._id,
|
|
|
+ type: 'fileRefs',
|
|
|
+ })
|
|
|
+ foundElement._id.should.equal(subSubFile._id)
|
|
|
+ path.fileSystem.should.equal(
|
|
|
+ `/${subFolder.name}/${secondSubFolder.name}/${subSubFile.name}`
|
|
|
)
|
|
|
+ parentFolder._id.should.equal(secondSubFolder._id)
|
|
|
+ path.mongo.should.equal('rootFolder.0.folders.1.folders.0.fileRefs.0')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('finding an element with wrong element type', function () {
|
|
|
- it('should add an s onto the element type', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: subSubDoc._id, type: 'doc' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(subSubDoc._id)
|
|
|
- done()
|
|
|
+ it('should add an s onto the element type', async function () {
|
|
|
+ const { element: foundElement } = await this.locator.promises.findElement(
|
|
|
+ {
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: subSubDoc._id,
|
|
|
+ type: 'doc',
|
|
|
}
|
|
|
)
|
|
|
+ foundElement._id.should.equal(subSubDoc._id)
|
|
|
})
|
|
|
|
|
|
- it('should convert file to fileRefs', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project_id: project._id, element_id: file1._id, type: 'fileRefs' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(file1._id)
|
|
|
- done()
|
|
|
+ it('should convert file to fileRefs', async function () {
|
|
|
+ const { element: foundElement } = await this.locator.promises.findElement(
|
|
|
+ {
|
|
|
+ project_id: project._id,
|
|
|
+ element_id: file1._id,
|
|
|
+ type: 'fileRefs',
|
|
|
}
|
|
|
)
|
|
|
+ foundElement._id.should.equal(file1._id)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -242,233 +219,173 @@ describe('ProjectLocator', function () {
|
|
|
_id: '1234566',
|
|
|
rootFolder: [rootFolder2],
|
|
|
}
|
|
|
- it('should find doc in project', function (done) {
|
|
|
- this.locator.findElement(
|
|
|
- { project: project2, element_id: doc3._id, type: 'docs' },
|
|
|
- (err, foundElement, path, parentFolder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- foundElement._id.should.equal(doc3._id)
|
|
|
- path.fileSystem.should.equal(`/${doc3.name}`)
|
|
|
- parentFolder._id.should.equal(project2.rootFolder[0]._id)
|
|
|
- path.mongo.should.equal('rootFolder.0.docs.0')
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should find doc in project', async function () {
|
|
|
+ const {
|
|
|
+ element: foundElement,
|
|
|
+ path,
|
|
|
+ folder: parentFolder,
|
|
|
+ } = await this.locator.promises.findElement({
|
|
|
+ project: project2,
|
|
|
+ element_id: doc3._id,
|
|
|
+ type: 'docs',
|
|
|
+ })
|
|
|
+ foundElement._id.should.equal(doc3._id)
|
|
|
+ path.fileSystem.should.equal(`/${doc3.name}`)
|
|
|
+ parentFolder._id.should.equal(project2.rootFolder[0]._id)
|
|
|
+ path.mongo.should.equal('rootFolder.0.docs.0')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('finding root doc', function () {
|
|
|
- it('should return root doc when passed project', function (done) {
|
|
|
- this.locator.findRootDoc(project, (err, doc) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- doc._id.should.equal(rootDoc._id)
|
|
|
- done()
|
|
|
- })
|
|
|
+ it('should return root doc when passed project', async function () {
|
|
|
+ const { element: doc } = await this.locator.promises.findRootDoc(project)
|
|
|
+ doc._id.should.equal(rootDoc._id)
|
|
|
})
|
|
|
|
|
|
- it('should return root doc when passed project_id', function (done) {
|
|
|
- this.locator.findRootDoc(project._id, (err, doc) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- doc._id.should.equal(rootDoc._id)
|
|
|
- done()
|
|
|
- })
|
|
|
+ it('should return root doc when passed project_id', async function () {
|
|
|
+ const { element: doc } = await this.locator.promises.findRootDoc(
|
|
|
+ project._id
|
|
|
+ )
|
|
|
+ doc._id.should.equal(rootDoc._id)
|
|
|
})
|
|
|
|
|
|
- it('should return null when the project has no rootDoc', function (done) {
|
|
|
+ it('should return null when the project has no rootDoc', async function () {
|
|
|
project.rootDoc_id = null
|
|
|
- this.locator.findRootDoc(project, (err, doc) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- expect(doc).to.equal(null)
|
|
|
- done()
|
|
|
- })
|
|
|
+ const { element: rootDoc } =
|
|
|
+ await this.locator.promises.findRootDoc(project)
|
|
|
+ expect(rootDoc).to.equal(null)
|
|
|
})
|
|
|
|
|
|
- it('should return null when the rootDoc_id no longer exists', function (done) {
|
|
|
+ it('should return null when the rootDoc_id no longer exists', async function () {
|
|
|
project.rootDoc_id = 'doesntexist'
|
|
|
- this.locator.findRootDoc(project, (err, doc) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- expect(doc).to.equal(null)
|
|
|
- done()
|
|
|
- })
|
|
|
+ const { element: rootDoc } =
|
|
|
+ await this.locator.promises.findRootDoc(project)
|
|
|
+ expect(rootDoc).to.equal(null)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
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', async function () {
|
|
|
const path = `${doc1.name}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(doc1)
|
|
|
- expect(type).to.equal('doc')
|
|
|
- expect(folder).to.equal(rootFolder)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(doc1)
|
|
|
+ expect(type).to.equal('doc')
|
|
|
+ expect(folder).to.equal(rootFolder)
|
|
|
})
|
|
|
|
|
|
- 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', async function () {
|
|
|
const path = `/${doc1.name}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(doc1)
|
|
|
- expect(type).to.equal('doc')
|
|
|
- expect(folder).to.equal(rootFolder)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(doc1)
|
|
|
+ expect(type).to.equal('doc')
|
|
|
+ expect(folder).to.equal(rootFolder)
|
|
|
})
|
|
|
|
|
|
- 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', async function () {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(subSubDoc)
|
|
|
- expect(type).to.equal('doc')
|
|
|
- expect(folder).to.equal(secondSubFolder)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(subSubDoc)
|
|
|
+ expect(type).to.equal('doc')
|
|
|
+ expect(folder).to.equal(secondSubFolder)
|
|
|
})
|
|
|
|
|
|
- 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', async function () {
|
|
|
const path = `${file1.name}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(file1)
|
|
|
- expect(type).to.equal('file')
|
|
|
- expect(folder).to.equal(rootFolder)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(file1)
|
|
|
+ expect(type).to.equal('file')
|
|
|
+ expect(folder).to.equal(rootFolder)
|
|
|
})
|
|
|
|
|
|
- it('should take a file path and return the element for a nested document', function (done) {
|
|
|
+ it('should take a file path and return the element for a nested document', async function () {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/${subSubFile.name}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(subSubFile)
|
|
|
- expect(type).to.equal('file')
|
|
|
- expect(folder).to.equal(secondSubFolder)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(subSubFile)
|
|
|
+ expect(type).to.equal('file')
|
|
|
+ expect(folder).to.equal(secondSubFolder)
|
|
|
})
|
|
|
|
|
|
- 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', async function () {
|
|
|
const path = `${subFolder.name.toUpperCase()}/${secondSubFolder.name.toUpperCase()}/${subSubFile.name.toUpperCase()}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(subSubFile)
|
|
|
- expect(type).to.equal('file')
|
|
|
- expect(folder).to.equal(secondSubFolder)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(subSubFile)
|
|
|
+ expect(type).to.equal('file')
|
|
|
+ expect(folder).to.equal(secondSubFolder)
|
|
|
})
|
|
|
|
|
|
- it('should not return elements with a case-insensitive match when exactCaseMatch is true', function (done) {
|
|
|
+ it('should not return elements with a case-insensitive match when exactCaseMatch is true', async function () {
|
|
|
const path = `${subFolder.name.toUpperCase()}/${secondSubFolder.name.toUpperCase()}/${subSubFile.name.toUpperCase()}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path, exactCaseMatch: true },
|
|
|
- (err, element, type, folder) => {
|
|
|
- err.should.not.equal(undefined)
|
|
|
- expect(element).to.be.undefined
|
|
|
- expect(type).to.be.undefined
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ await expect(
|
|
|
+ this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ exactCaseMatch: true,
|
|
|
+ })
|
|
|
+ ).to.eventually.be.rejected
|
|
|
})
|
|
|
|
|
|
- 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', async function () {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(secondSubFolder)
|
|
|
- expect(type).to.equal('folder')
|
|
|
- expect(folder).to.equal(subFolder)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(secondSubFolder)
|
|
|
+ expect(type).to.equal('folder')
|
|
|
+ expect(folder).to.equal(subFolder)
|
|
|
})
|
|
|
|
|
|
- it('should take a file path and return the root folder', function (done) {
|
|
|
+ it('should take a file path and return the root folder', async function () {
|
|
|
const path = '/'
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type, folder) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.should.deep.equal(rootFolder)
|
|
|
- expect(type).to.equal('folder')
|
|
|
- expect(folder).to.equal(null)
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element, type, folder } =
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.should.deep.equal(rootFolder)
|
|
|
+ expect(type).to.equal('folder')
|
|
|
+ expect(folder).to.equal(null)
|
|
|
})
|
|
|
|
|
|
- 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', async function () {
|
|
|
const path = `${subFolder.name}/${secondSubFolder.name}/exist.txt`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type) => {
|
|
|
- err.should.not.equal(undefined)
|
|
|
- expect(element).to.be.undefined
|
|
|
- expect(type).to.be.undefined
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ await expect(this.locator.promises.findElementByPath({ project, path }))
|
|
|
+ .to.eventually.be.rejected
|
|
|
})
|
|
|
|
|
|
- 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', async function () {
|
|
|
const path = 'this/does/not/exist.txt'
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project, path },
|
|
|
- (err, element, type) => {
|
|
|
- err.should.not.equal(undefined)
|
|
|
- expect(element).to.be.undefined
|
|
|
- expect(type).to.be.undefined
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ await expect(
|
|
|
+ this.locator.promises.findElementByPath({
|
|
|
+ project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ ).to.eventually.be.rejected
|
|
|
})
|
|
|
|
|
|
describe('where duplicate folder exists', function () {
|
|
|
@@ -498,18 +415,20 @@ describe('ProjectLocator', function () {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- it('should not call the callback more than once', function (done) {
|
|
|
+ it('should not call the callback more than once', async function () {
|
|
|
const path = `${this.duplicateFolder.name}/${this.doc.name}`
|
|
|
- this.locator.findElementByPath({ project: this.project, path }, () =>
|
|
|
- done()
|
|
|
- )
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project: this.project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
}) // 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', async function () {
|
|
|
const path = `${this.duplicateFolder.name}/1/main.tex`
|
|
|
- this.locator.findElementByPath({ project: this.project, path }, () =>
|
|
|
- done()
|
|
|
- )
|
|
|
+ await this.locator.promises.findElementByPath({
|
|
|
+ project: this.project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
})
|
|
|
}) // mocha will throw exception if done called multiple times
|
|
|
|
|
|
@@ -526,18 +445,13 @@ describe('ProjectLocator', function () {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- it('should not crash with a null', function (done) {
|
|
|
+ it('should not crash with a null', async function () {
|
|
|
const path = '/other.tex'
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project: this.project, path },
|
|
|
- (err, element) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- element.name.should.equal('other.tex')
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ const { element } = await this.locator.promises.findElementByPath({
|
|
|
+ project: this.project,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ element.name.should.equal('other.tex')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -546,35 +460,31 @@ describe('ProjectLocator', function () {
|
|
|
this.ProjectGetter = { getProject: sinon.stub().callsArg(2) }
|
|
|
})
|
|
|
|
|
|
- it('should not crash with a null', function (done) {
|
|
|
+ it('should not crash with a null', async function () {
|
|
|
const path = '/other.tex'
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project_id: project._id, path },
|
|
|
- (err, element) => {
|
|
|
- expect(err).to.exist
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ await expect(
|
|
|
+ this.locator.promises.findElementByPath({
|
|
|
+ project_id: project._id,
|
|
|
+ path,
|
|
|
+ })
|
|
|
+ ).to.be.rejected
|
|
|
})
|
|
|
})
|
|
|
|
|
|
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', async function () {
|
|
|
const path = `${doc1.name}`
|
|
|
- this.locator.findElementByPath(
|
|
|
- { project_id: project._id, path },
|
|
|
- (err, element, type) => {
|
|
|
- if (err != null) {
|
|
|
- return done(err)
|
|
|
- }
|
|
|
- this.ProjectGetter.getProject
|
|
|
- .calledWith(project._id, { rootFolder: true, rootDoc_id: true })
|
|
|
- .should.equal(true)
|
|
|
- element.should.deep.equal(doc1)
|
|
|
- expect(type).to.equal('doc')
|
|
|
- done()
|
|
|
+ const { element, type } = await this.locator.promises.findElementByPath(
|
|
|
+ {
|
|
|
+ project_id: project._id,
|
|
|
+ path,
|
|
|
}
|
|
|
)
|
|
|
+ this.ProjectGetter.getProject
|
|
|
+ .calledWith(project._id, { rootFolder: true, rootDoc_id: true })
|
|
|
+ .should.equal(true)
|
|
|
+ element.should.deep.equal(doc1)
|
|
|
+ expect(type).to.equal('doc')
|
|
|
})
|
|
|
})
|
|
|
})
|