mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #2097 from overleaf/em-chai-spies
Remove chai-spies GitOrigin-RevId: 7fa41fe32c1be985d761b7327950995d6afe7c4e
This commit is contained in:
parent
03460ba229
commit
1335d21136
5 changed files with 412 additions and 419 deletions
14
services/web/package-lock.json
generated
14
services/web/package-lock.json
generated
|
@ -4184,12 +4184,6 @@
|
|||
"type-detect": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"chai-spies": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/chai-spies/-/chai-spies-1.0.0.tgz",
|
||||
"integrity": "sha512-elF2ZUczBsFoP07qCfMO/zeggs8pqCf3fZGyK5+2X4AndS8jycZYID91ztD9oQ7d/0tnS963dPkd0frQEThDsg==",
|
||||
"dev": true
|
||||
},
|
||||
"chalk": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
||||
|
@ -7702,13 +7696,11 @@
|
|||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
"bundled": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
|
@ -7725,8 +7717,7 @@
|
|||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
"bundled": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
|
@ -7855,7 +7846,6 @@
|
|||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
|
|
|
@ -119,7 +119,6 @@
|
|||
"babel-loader": "^8.0.6",
|
||||
"babel-plugin-angularjs-annotate": "^0.10.0",
|
||||
"chai": "3.5.0",
|
||||
"chai-spies": "^1.0.0",
|
||||
"clean-css-cli": "^4.2.1",
|
||||
"es6-promise": "^4.0.5",
|
||||
"eslint": "^4.18.1",
|
||||
|
|
|
@ -1,23 +1,6 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// 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
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const should = require('chai').should()
|
||||
const spies = require('chai-spies')
|
||||
const chai = require('chai').use(spies)
|
||||
const sinon = require('sinon')
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { assert } = require('chai')
|
||||
const path = require('path')
|
||||
const _ = require('underscore')
|
||||
const { ObjectId } = require('mongojs')
|
||||
const modulePath = path.join(
|
||||
__dirname,
|
||||
|
@ -48,7 +31,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
|
||||
this.callback = sinon.stub()
|
||||
return (this.handler = SandboxedModule.require(modulePath, {
|
||||
this.handler = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
},
|
||||
|
@ -71,18 +54,18 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('flushProjectToMongo', function() {
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
return this.handler.flushProjectToMongo(this.project_id, this.callback)
|
||||
this.handler.flushProjectToMongo(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should flush the document from the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWithMatch({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -93,7 +76,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback with no error', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -105,22 +88,22 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.flushProjectToMongo(this.project_id, this.callback)
|
||||
this.handler.flushProjectToMongo(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.flushProjectToMongo(this.project_id, this.callback)
|
||||
this.handler.flushProjectToMongo(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -133,14 +116,14 @@ describe('DocumentUpdaterHandler', function() {
|
|||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
return this.handler.flushProjectToMongoAndDelete(
|
||||
this.handler.flushProjectToMongoAndDelete(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should delete the project from the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWithMatch({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -151,7 +134,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback with no error', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -163,28 +146,28 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.flushProjectToMongoAndDelete(
|
||||
this.handler.flushProjectToMongoAndDelete(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.flushProjectToMongoAndDelete(
|
||||
this.handler.flushProjectToMongoAndDelete(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -197,7 +180,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
return this.handler.flushDocToMongo(
|
||||
this.handler.flushDocToMongo(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
|
@ -205,7 +188,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should flush the document from the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWithMatch({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -216,7 +199,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback with no error', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -228,7 +211,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.flushDocToMongo(
|
||||
this.handler.flushDocToMongo(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
|
@ -236,14 +219,14 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.flushDocToMongo(
|
||||
this.handler.flushDocToMongo(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
|
@ -251,7 +234,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -264,15 +247,11 @@ describe('DocumentUpdaterHandler', function() {
|
|||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
return this.handler.deleteDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
)
|
||||
this.handler.deleteDoc(this.project_id, this.doc_id, this.callback)
|
||||
})
|
||||
|
||||
it('should delete the document from the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWithMatch({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -283,7 +262,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback with no error', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -295,30 +274,22 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.deleteDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
)
|
||||
this.handler.deleteDoc(this.project_id, this.doc_id, this.callback)
|
||||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.deleteDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
)
|
||||
this.handler.deleteDoc(this.project_id, this.doc_id, this.callback)
|
||||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -329,13 +300,13 @@ describe('DocumentUpdaterHandler', function() {
|
|||
|
||||
describe('setDocument', function() {
|
||||
beforeEach(function() {
|
||||
return (this.source = 'dropbox')
|
||||
this.source = 'dropbox'
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
return this.handler.setDocument(
|
||||
this.handler.setDocument(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.user_id,
|
||||
|
@ -346,7 +317,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should set the document in the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -362,7 +333,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback with no error', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -374,7 +345,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.setDocument(
|
||||
this.handler.setDocument(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.user_id,
|
||||
|
@ -385,14 +356,14 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.setDocument(
|
||||
this.handler.setDocument(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.user_id,
|
||||
|
@ -403,7 +374,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -423,7 +394,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
this.fromVersion = 2
|
||||
this.request.callsArgWith(1, null, { statusCode: 200 }, this.body)
|
||||
return this.handler.getDocument(
|
||||
this.handler.getDocument(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.fromVersion,
|
||||
|
@ -432,7 +403,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should get the document from the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -444,7 +415,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback with the lines and version', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(null, this.lines, this.version, this.ranges, this.ops)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
@ -458,7 +429,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.getDocument(
|
||||
this.handler.getDocument(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.fromVersion,
|
||||
|
@ -467,14 +438,14 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.getDocument(
|
||||
this.handler.getDocument(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.fromVersion,
|
||||
|
@ -483,7 +454,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -494,7 +465,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
|
||||
describe('getProjectDocsIfMatch', function() {
|
||||
beforeEach(function() {
|
||||
return (this.project_state_hash = '1234567890abcdef')
|
||||
this.project_state_hash = '1234567890abcdef'
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
|
@ -509,7 +480,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 200 }, this.body)
|
||||
return this.handler.getProjectDocsIfMatch(
|
||||
this.handler.getProjectDocsIfMatch(
|
||||
this.project_id,
|
||||
this.project_state_hash,
|
||||
this.callback
|
||||
|
@ -520,13 +491,11 @@ describe('DocumentUpdaterHandler', function() {
|
|||
const url = `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
}/get_and_flush_if_old?state=${this.project_state_hash}`
|
||||
return this.request.post.calledWith(url).should.equal(true)
|
||||
this.request.post.calledWith(url).should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with the documents', function() {
|
||||
return this.callback
|
||||
.calledWithExactly(null, this.docs)
|
||||
.should.equal(true)
|
||||
this.callback.calledWithExactly(null, this.docs).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -540,7 +509,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.getProjectDocsIfMatch(
|
||||
this.handler.getProjectDocsIfMatch(
|
||||
this.project_id,
|
||||
this.project_state_hash,
|
||||
this.callback
|
||||
|
@ -548,7 +517,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -557,7 +526,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 409 }, 'Conflict')
|
||||
return this.handler.getProjectDocsIfMatch(
|
||||
this.handler.getProjectDocsIfMatch(
|
||||
this.project_id,
|
||||
this.project_state_hash,
|
||||
this.callback
|
||||
|
@ -565,7 +534,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return the callback with no documents', function() {
|
||||
return this.callback.alwaysCalledWithExactly().should.equal(true)
|
||||
this.callback.alwaysCalledWithExactly().should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -574,11 +543,11 @@ describe('DocumentUpdaterHandler', function() {
|
|||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 200 })
|
||||
return this.handler.clearProjectState(this.project_id, this.callback)
|
||||
this.handler.clearProjectState(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should clear the project state from the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWithMatch({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -589,7 +558,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -601,22 +570,22 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.clearProjectState(this.project_id, this.callback)
|
||||
this.handler.clearProjectState(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns an error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, null)
|
||||
return this.handler.clearProjectState(this.project_id, this.callback)
|
||||
this.handler.clearProjectState(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should return the callback with no documents', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -627,13 +596,13 @@ describe('DocumentUpdaterHandler', function() {
|
|||
|
||||
describe('acceptChanges', function() {
|
||||
beforeEach(function() {
|
||||
return (this.change_id = 'mock-change-id-1')
|
||||
this.change_id = 'mock-change-id-1'
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 200 }, this.body)
|
||||
return this.handler.acceptChanges(
|
||||
this.handler.acceptChanges(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
[this.change_id],
|
||||
|
@ -642,7 +611,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should accept the change in the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -656,7 +625,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -668,7 +637,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.acceptChanges(
|
||||
this.handler.acceptChanges(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
[this.change_id],
|
||||
|
@ -677,14 +646,14 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.acceptChanges(
|
||||
this.handler.acceptChanges(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
[this.change_id],
|
||||
|
@ -693,7 +662,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -704,13 +673,13 @@ describe('DocumentUpdaterHandler', function() {
|
|||
|
||||
describe('deleteThread', function() {
|
||||
beforeEach(function() {
|
||||
return (this.thread_id = 'mock-thread-id-1')
|
||||
this.thread_id = 'mock-thread-id-1'
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 200 }, this.body)
|
||||
return this.handler.deleteThread(
|
||||
this.handler.deleteThread(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.thread_id,
|
||||
|
@ -719,7 +688,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should delete the thread in the document updater', function() {
|
||||
return this.request
|
||||
this.request
|
||||
.calledWithMatch({
|
||||
url: `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
|
@ -730,7 +699,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -742,7 +711,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
null,
|
||||
null
|
||||
)
|
||||
return this.handler.deleteThread(
|
||||
this.handler.deleteThread(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.thread_id,
|
||||
|
@ -751,14 +720,14 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return an error to the callback', function() {
|
||||
return this.callback.calledWith(this.error).should.equal(true)
|
||||
this.callback.calledWith(this.error).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the document updater returns a failure error code', function() {
|
||||
beforeEach(function() {
|
||||
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.handler.deleteThread(
|
||||
this.handler.deleteThread(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.thread_id,
|
||||
|
@ -767,7 +736,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('should return the callback with an error', function() {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
new Error('doc updater returned failure status code: 500')
|
||||
)
|
||||
|
@ -779,13 +748,13 @@ describe('DocumentUpdaterHandler', function() {
|
|||
describe('updateProjectStructure ', function() {
|
||||
beforeEach(function() {
|
||||
this.user_id = 1234
|
||||
return (this.version = 999)
|
||||
this.version = 999
|
||||
})
|
||||
|
||||
describe('with project history disabled', function() {
|
||||
beforeEach(function() {
|
||||
this.settings.apis.project_history.sendProjectStructureOps = false
|
||||
return this.handler.updateProjectStructure(
|
||||
this.handler.updateProjectStructure(
|
||||
this.project_id,
|
||||
this.projectHistoryId,
|
||||
this.user_id,
|
||||
|
@ -795,11 +764,11 @@ describe('DocumentUpdaterHandler', function() {
|
|||
})
|
||||
|
||||
it('does not make a web request', function() {
|
||||
return this.request.called.should.equal(false)
|
||||
this.request.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('calls the callback', function() {
|
||||
return this.callback.called.should.equal(true)
|
||||
this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -809,7 +778,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
this.url = `${this.settings.apis.documentupdater.url}/project/${
|
||||
this.project_id
|
||||
}`
|
||||
return this.request.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
this.request.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
})
|
||||
|
||||
describe('when an entity has changed name', function() {
|
||||
|
@ -843,7 +812,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
]
|
||||
|
||||
return this.handler.updateProjectStructure(
|
||||
this.handler.updateProjectStructure(
|
||||
this.project_id,
|
||||
this.projectHistoryId,
|
||||
this.user_id,
|
||||
|
@ -862,7 +831,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
})
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -888,7 +857,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
]
|
||||
|
||||
return this.handler.updateProjectStructure(
|
||||
this.handler.updateProjectStructure(
|
||||
this.project_id,
|
||||
this.projectHistoryId,
|
||||
this.user_id,
|
||||
|
@ -907,7 +876,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
})
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -937,7 +906,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
]
|
||||
|
||||
return this.handler.updateProjectStructure(
|
||||
this.handler.updateProjectStructure(
|
||||
this.project_id,
|
||||
this.projectHistoryId,
|
||||
this.user_id,
|
||||
|
@ -956,7 +925,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
})
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -980,7 +949,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
]
|
||||
|
||||
return this.handler.updateProjectStructure(
|
||||
this.handler.updateProjectStructure(
|
||||
this.project_id,
|
||||
this.projectHistoryId,
|
||||
this.user_id,
|
||||
|
@ -999,7 +968,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
}
|
||||
})
|
||||
.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -1014,14 +983,6 @@ describe('DocumentUpdaterHandler', function() {
|
|||
]
|
||||
}
|
||||
|
||||
const docUpdates = [
|
||||
{
|
||||
id: this.docId.toString(),
|
||||
pathname: '/foo',
|
||||
newPathname: ''
|
||||
}
|
||||
]
|
||||
|
||||
this.handler.updateProjectStructure(
|
||||
this.project_id,
|
||||
this.projectHistoryId,
|
||||
|
@ -1032,7 +993,7 @@ describe('DocumentUpdaterHandler', function() {
|
|||
|
||||
this.callback.calledWith(new Error()).should.equal(true)
|
||||
const firstCallArgs = this.callback.args[0]
|
||||
return firstCallArgs[0].message.should.equal(
|
||||
firstCallArgs[0].message.should.equal(
|
||||
'did not receive project version in changes'
|
||||
)
|
||||
})
|
||||
|
|
|
@ -1,68 +1,39 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
handle-callback-err,
|
||||
max-len,
|
||||
no-path-concat,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// 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
|
||||
* DS206: Consider reworking classes to avoid initClass
|
||||
* 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 sinon = require('sinon')
|
||||
const should = chai.should()
|
||||
const { expect } = chai
|
||||
const { expect } = require('chai')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/Project/ProjectCreationHandler.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const Path = require('path')
|
||||
const _ = require('underscore')
|
||||
|
||||
describe('ProjectCreationHandler', function() {
|
||||
const ownerId = '4eecb1c1bffa66588e0000a1'
|
||||
const projectName = 'project name goes here'
|
||||
const project_id = '4eecaffcbffa66588e000008'
|
||||
const projectId = '4eecaffcbffa66588e000008'
|
||||
const docId = '4eecb17ebffa66588e00003f'
|
||||
const rootFolderId = '234adfa3r2afe'
|
||||
|
||||
beforeEach(function() {
|
||||
let Folder, Project
|
||||
this.ProjectModel = Project = (function() {
|
||||
Project = class Project {
|
||||
static initClass() {
|
||||
this.prototype.save = sinon.stub().callsArg(0)
|
||||
this.prototype.rootFolder = [
|
||||
{
|
||||
_id: rootFolderId,
|
||||
docs: []
|
||||
}
|
||||
]
|
||||
}
|
||||
constructor(options) {
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
this._id = project_id
|
||||
this.owner_ref = options.owner_ref
|
||||
this.name = options.name
|
||||
this.overleaf = { history: {} }
|
||||
}
|
||||
}
|
||||
Project.initClass()
|
||||
return Project
|
||||
})()
|
||||
this.FolderModel = Folder = class Folder {
|
||||
this.ProjectModel = class Project {
|
||||
constructor(options) {
|
||||
;({ name: this.name } = options)
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
this._id = projectId
|
||||
this.owner_ref = options.owner_ref
|
||||
this.name = options.name
|
||||
this.overleaf = { history: {} }
|
||||
}
|
||||
}
|
||||
this.ProjectModel.prototype.save = sinon.stub().callsArg(0)
|
||||
this.ProjectModel.prototype.rootFolder = [
|
||||
{
|
||||
_id: rootFolderId,
|
||||
docs: []
|
||||
}
|
||||
]
|
||||
this.FolderModel = class Folder {
|
||||
constructor(options) {
|
||||
this.name = options.name
|
||||
}
|
||||
}
|
||||
this.ProjectEntityUpdateHandler = {
|
||||
|
@ -88,7 +59,7 @@ describe('ProjectCreationHandler', function() {
|
|||
|
||||
this.AnalyticsManager = { recordEvent: sinon.stub() }
|
||||
|
||||
return (this.handler = SandboxedModule.require(modulePath, {
|
||||
this.handler = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
},
|
||||
|
@ -109,107 +80,123 @@ describe('ProjectCreationHandler', function() {
|
|||
timeAsyncMethod() {}
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('Creating a Blank project', function() {
|
||||
beforeEach(function() {
|
||||
this.overleaf_id = 1234
|
||||
this.overleafId = 1234
|
||||
this.HistoryManager.initializeProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(0, null, { overleaf_id: this.overleaf_id })
|
||||
return (this.ProjectModel.prototype.save = sinon.stub().callsArg(0))
|
||||
.callsArgWith(0, null, { overleaf_id: this.overleafId })
|
||||
this.ProjectModel.prototype.save = sinon.stub().callsArg(0)
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
it('should save the project', function(done) {
|
||||
return this.handler.createBlankProject(ownerId, projectName, () => {
|
||||
this.handler.createBlankProject(ownerId, projectName, () => {
|
||||
this.ProjectModel.prototype.save.called.should.equal(true)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return the project in the callback', function(done) {
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.name.should.equal(projectName)
|
||||
;(project.owner_ref + '').should.equal(ownerId)
|
||||
return done()
|
||||
expect(project.owner_ref + '').to.equal(ownerId)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should initialize the project overleaf if history id not provided', function(done) {
|
||||
this.handler.createBlankProject(ownerId, projectName, done)
|
||||
return this.HistoryManager.initializeProject
|
||||
.calledWith()
|
||||
.should.equal(true)
|
||||
this.HistoryManager.initializeProject.calledWith().should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the overleaf id if overleaf id not provided', function(done) {
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
project.overleaf.history.id.should.equal(this.overleaf_id)
|
||||
return done()
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.overleaf.history.id.should.equal(this.overleafId)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the overleaf id if overleaf id provided', function(done) {
|
||||
const overleaf_id = 2345
|
||||
const overleafId = 2345
|
||||
const attributes = {
|
||||
overleaf: {
|
||||
history: {
|
||||
id: overleaf_id
|
||||
id: overleafId
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
attributes,
|
||||
(err, project) => {
|
||||
project.overleaf.history.id.should.equal(overleaf_id)
|
||||
return done()
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.overleaf.history.id.should.equal(overleafId)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the language from the user', function(done) {
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.spellCheckLanguage.should.equal('de')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the imageName to currentImageName if set and no imageName attribute', function(done) {
|
||||
this.Settings.currentImageName = 'mock-image-name'
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.imageName.should.equal(this.Settings.currentImageName)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the imageName if no currentImageName', function(done) {
|
||||
this.Settings.currentImageName = null
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
expect(project.imageName).to.not.exist
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -217,46 +204,58 @@ describe('ProjectCreationHandler', function() {
|
|||
it('should set the imageName to the attribute value if set and not overwrite it with the currentImageName', function(done) {
|
||||
this.Settings.currentImageName = 'mock-image-name'
|
||||
const attributes = { imageName: 'attribute-image-name' }
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
attributes,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.imageName.should.equal(attributes.imageName)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the overleaf.history.display if not configured in settings', function(done) {
|
||||
this.Settings.apis.project_history.displayHistoryForNewProjects = false
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
expect(project.overleaf.history.display).to.not.exist
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the overleaf.history.display if configured in settings', function(done) {
|
||||
this.Settings.apis.project_history.displayHistoryForNewProjects = true
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
expect(project.overleaf.history.display).to.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a project-created event to analytics', function(done) {
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
expect(this.AnalyticsManager.recordEvent.callCount).to.equal(1)
|
||||
expect(
|
||||
this.AnalyticsManager.recordEvent.calledWith(
|
||||
|
@ -264,7 +263,7 @@ describe('ProjectCreationHandler', function() {
|
|||
'project-created'
|
||||
)
|
||||
).to.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -273,11 +272,14 @@ describe('ProjectCreationHandler', function() {
|
|||
const attributes = {
|
||||
fromV1TemplateId: 100
|
||||
}
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
attributes,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
expect(this.AnalyticsManager.recordEvent.callCount).to.equal(1)
|
||||
expect(
|
||||
this.AnalyticsManager.recordEvent.calledWith(
|
||||
|
@ -286,7 +288,7 @@ describe('ProjectCreationHandler', function() {
|
|||
{ projectId: project._id, attributes }
|
||||
)
|
||||
).to.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -299,11 +301,14 @@ describe('ProjectCreationHandler', function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
return this.handler.createBlankProject(
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
attributes,
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
expect(this.AnalyticsManager.recordEvent.callCount).to.equal(1)
|
||||
expect(
|
||||
this.AnalyticsManager.recordEvent.calledWith(
|
||||
|
@ -311,7 +316,7 @@ describe('ProjectCreationHandler', function() {
|
|||
'project-imported'
|
||||
)
|
||||
).to.equal(true)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -322,15 +327,11 @@ describe('ProjectCreationHandler', function() {
|
|||
this.ProjectModel.prototype.save = sinon
|
||||
.stub()
|
||||
.callsArgWith(0, new Error('something went wrong'))
|
||||
return this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
this.callback
|
||||
)
|
||||
this.handler.createBlankProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should return the error to the callback', function() {
|
||||
return should.exist(this.callback.args[0][0])
|
||||
expect(this.callback.args[0][0]).to.exist
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -339,19 +340,15 @@ describe('ProjectCreationHandler', function() {
|
|||
this.ProjectDetailsHandler.validateProjectName = sinon
|
||||
.stub()
|
||||
.yields(new Error('bad name'))
|
||||
return this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
this.callback
|
||||
)
|
||||
this.handler.createBlankProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should return the error to the callback', function() {
|
||||
return should.exist(this.callback.args[0][0])
|
||||
expect(this.callback.args[0][0]).to.exist
|
||||
})
|
||||
|
||||
it('should not try to create the project', function() {
|
||||
return this.ProjectModel.prototype.save.called.should.equal(false)
|
||||
this.ProjectModel.prototype.save.called.should.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -360,15 +357,15 @@ describe('ProjectCreationHandler', function() {
|
|||
beforeEach(function() {
|
||||
this.project = new this.ProjectModel()
|
||||
this.handler._buildTemplate = function(
|
||||
template_name,
|
||||
templateName,
|
||||
user,
|
||||
project_name,
|
||||
projectName,
|
||||
callback
|
||||
) {
|
||||
if (template_name === 'mainbasic.tex') {
|
||||
if (templateName === 'mainbasic.tex') {
|
||||
return callback(null, ['mainbasic.tex', 'lines'])
|
||||
}
|
||||
throw new Error(`unknown template: ${template_name}`)
|
||||
throw new Error(`unknown template: ${templateName}`)
|
||||
}
|
||||
sinon.spy(this.handler, '_buildTemplate')
|
||||
this.handler.createBlankProject = sinon
|
||||
|
@ -377,27 +374,23 @@ describe('ProjectCreationHandler', function() {
|
|||
this.handler._createRootDoc = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, this.project)
|
||||
return this.handler.createBasicProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
this.callback
|
||||
)
|
||||
this.handler.createBasicProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should create a blank project first', function() {
|
||||
return this.handler.createBlankProject
|
||||
this.handler.createBlankProject
|
||||
.calledWith(ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should create the root document', function() {
|
||||
return this.handler._createRootDoc
|
||||
this.handler._createRootDoc
|
||||
.calledWith(this.project, ownerId, ['mainbasic.tex', 'lines'])
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should build the mainbasic.tex template', function() {
|
||||
return this.handler._buildTemplate
|
||||
this.handler._buildTemplate
|
||||
.calledWith('mainbasic.tex', ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
@ -412,7 +405,7 @@ describe('ProjectCreationHandler', function() {
|
|||
this.handler._createRootDoc = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, this.project)
|
||||
return this.handler.createProjectFromSnippet(
|
||||
this.handler.createProjectFromSnippet(
|
||||
ownerId,
|
||||
projectName,
|
||||
['snippet line 1', 'snippet line 2'],
|
||||
|
@ -421,13 +414,13 @@ describe('ProjectCreationHandler', function() {
|
|||
})
|
||||
|
||||
it('should create a blank project first', function() {
|
||||
return this.handler.createBlankProject
|
||||
this.handler.createBlankProject
|
||||
.calledWith(ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should create the root document', function() {
|
||||
return this.handler._createRootDoc
|
||||
this.handler._createRootDoc
|
||||
.calledWith(this.project, ownerId, ['snippet line 1', 'snippet line 2'])
|
||||
.should.equal(true)
|
||||
})
|
||||
|
@ -437,18 +430,18 @@ describe('ProjectCreationHandler', function() {
|
|||
beforeEach(function() {
|
||||
this.project = new this.ProjectModel()
|
||||
this.handler._buildTemplate = function(
|
||||
template_name,
|
||||
templateName,
|
||||
user,
|
||||
project_name,
|
||||
projectName,
|
||||
callback
|
||||
) {
|
||||
if (template_name === 'main.tex') {
|
||||
if (templateName === 'main.tex') {
|
||||
return callback(null, ['main.tex', 'lines'])
|
||||
}
|
||||
if (template_name === 'references.bib') {
|
||||
if (templateName === 'references.bib') {
|
||||
return callback(null, ['references.bib', 'lines'])
|
||||
}
|
||||
throw new Error(`unknown template: ${template_name}`)
|
||||
throw new Error(`unknown template: ${templateName}`)
|
||||
}
|
||||
sinon.spy(this.handler, '_buildTemplate')
|
||||
this.handler.createBlankProject = sinon
|
||||
|
@ -457,29 +450,25 @@ describe('ProjectCreationHandler', function() {
|
|||
this.handler._createRootDoc = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, this.project)
|
||||
return this.handler.createExampleProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
this.callback
|
||||
)
|
||||
this.handler.createExampleProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should create a blank project first', function() {
|
||||
return this.handler.createBlankProject
|
||||
this.handler.createBlankProject
|
||||
.calledWith(ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should create the root document', function() {
|
||||
return this.handler._createRootDoc
|
||||
this.handler._createRootDoc
|
||||
.calledWith(this.project, ownerId, ['main.tex', 'lines'])
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should insert references.bib', function() {
|
||||
return this.ProjectEntityUpdateHandler.addDoc
|
||||
this.ProjectEntityUpdateHandler.addDoc
|
||||
.calledWith(
|
||||
project_id,
|
||||
projectId,
|
||||
rootFolderId,
|
||||
'references.bib',
|
||||
['references.bib', 'lines'],
|
||||
|
@ -489,13 +478,16 @@ describe('ProjectCreationHandler', function() {
|
|||
})
|
||||
|
||||
it('should insert universe.jpg', function() {
|
||||
return this.ProjectEntityUpdateHandler.addFile
|
||||
this.ProjectEntityUpdateHandler.addFile
|
||||
.calledWith(
|
||||
project_id,
|
||||
projectId,
|
||||
rootFolderId,
|
||||
'universe.jpg',
|
||||
Path.resolve(
|
||||
__dirname + '/../../../../app/templates/project_files/universe.jpg'
|
||||
Path.join(
|
||||
__dirname,
|
||||
'../../../../app/templates/project_files/universe.jpg'
|
||||
)
|
||||
),
|
||||
null,
|
||||
ownerId
|
||||
|
@ -504,13 +496,13 @@ describe('ProjectCreationHandler', function() {
|
|||
})
|
||||
|
||||
it('should build the main.tex template', function() {
|
||||
return this.handler._buildTemplate
|
||||
this.handler._buildTemplate
|
||||
.calledWith('main.tex', ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should build the references.bib template', function() {
|
||||
return this.handler._buildTemplate
|
||||
this.handler._buildTemplate
|
||||
.calledWith('references.bib', ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
@ -518,44 +510,47 @@ describe('ProjectCreationHandler', function() {
|
|||
|
||||
describe('_buildTemplate', function() {
|
||||
beforeEach(function(done) {
|
||||
return this.handler._buildTemplate(
|
||||
this.handler._buildTemplate(
|
||||
'main.tex',
|
||||
this.user_id,
|
||||
projectName,
|
||||
(err, templateLines) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
this.template = templateLines.reduce(
|
||||
(singleLine, line) => `${singleLine}\n${line}`
|
||||
)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should insert the project name into the template', function(done) {
|
||||
this.template.indexOf(projectName).should.not.equal(-1)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should insert the users name into the template', function(done) {
|
||||
this.template.indexOf(this.user.first_name).should.not.equal(-1)
|
||||
this.template.indexOf(this.user.last_name).should.not.equal(-1)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should not have undefined in the template', function(done) {
|
||||
this.template.indexOf('undefined').should.equal(-1)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should not have any underscore brackets in the output', function(done) {
|
||||
this.template.indexOf('{{').should.equal(-1)
|
||||
this.template.indexOf('<%=').should.equal(-1)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
|
||||
it('should put the year in', function(done) {
|
||||
this.template.indexOf(new Date().getUTCFullYear()).should.not.equal(-1)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -563,7 +558,7 @@ describe('ProjectCreationHandler', function() {
|
|||
beforeEach(function(done) {
|
||||
this.project = new this.ProjectModel()
|
||||
|
||||
return this.handler._createRootDoc(
|
||||
this.handler._createRootDoc(
|
||||
this.project,
|
||||
ownerId,
|
||||
['line 1', 'line 2'],
|
||||
|
@ -572,9 +567,9 @@ describe('ProjectCreationHandler', function() {
|
|||
})
|
||||
|
||||
it('should insert main.tex', function() {
|
||||
return this.ProjectEntityUpdateHandler.addDoc
|
||||
this.ProjectEntityUpdateHandler.addDoc
|
||||
.calledWith(
|
||||
project_id,
|
||||
projectId,
|
||||
rootFolderId,
|
||||
'main.tex',
|
||||
['line 1', 'line 2'],
|
||||
|
@ -584,8 +579,8 @@ describe('ProjectCreationHandler', function() {
|
|||
})
|
||||
|
||||
it('should set the main doc id', function() {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(project_id, docId)
|
||||
this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(projectId, docId)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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 SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
const { expect } = require('chai')
|
||||
var Project = (Project = class Project {})
|
||||
|
||||
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' }
|
||||
|
@ -59,8 +40,8 @@ project.rootDoc_id = rootDoc._id
|
|||
|
||||
describe('ProjectLocator', function() {
|
||||
beforeEach(function() {
|
||||
Project.findById = (project_id, callback) => {
|
||||
return callback(null, project)
|
||||
Project.findById = (projectId, callback) => {
|
||||
callback(null, project)
|
||||
}
|
||||
this.ProjectGetter = {
|
||||
getProject: sinon.stub().callsArgWith(2, null, project)
|
||||
|
@ -68,7 +49,7 @@ describe('ProjectLocator', function() {
|
|||
this.ProjectHelper = {
|
||||
isArchived: sinon.stub()
|
||||
}
|
||||
return (this.locator = SandboxedModule.require(modulePath, {
|
||||
this.locator = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
},
|
||||
|
@ -83,46 +64,52 @@ describe('ProjectLocator', function() {
|
|||
warn() {}
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('finding a doc', function() {
|
||||
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' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(err == null)
|
||||
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')
|
||||
return done()
|
||||
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' },
|
||||
(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(
|
||||
`/${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
||||
)
|
||||
parentFolder._id.should.equal(secondSubFolder._id)
|
||||
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) {
|
||||
return this.locator.findElement(
|
||||
this.locator.findElement(
|
||||
{ project_id: project._id, element_id: 'ddsd432nj42', type: 'docs' },
|
||||
(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() {
|
||||
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' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(!err)
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
foundElement._id.should.equal(rootFolder._id)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('when at root', function(done) {
|
||||
return this.locator.findElement(
|
||||
this.locator.findElement(
|
||||
{ project_id: project._id, element_id: subFolder._id, type: 'folder' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(!err)
|
||||
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')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('when deeply nested', function(done) {
|
||||
return this.locator.findElement(
|
||||
this.locator.findElement(
|
||||
{
|
||||
project_id: project._id,
|
||||
element_id: secondSubFolder._id,
|
||||
type: 'folder'
|
||||
},
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(!err)
|
||||
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')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -177,35 +170,39 @@ describe('ProjectLocator', function() {
|
|||
|
||||
describe('finding a file', function() {
|
||||
it('when at root', function(done) {
|
||||
return this.locator.findElement(
|
||||
this.locator.findElement(
|
||||
{ project_id: project._id, element_id: file1._id, type: 'fileRefs' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(!err)
|
||||
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')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('when deeply nested', function(done) {
|
||||
return this.locator.findElement(
|
||||
this.locator.findElement(
|
||||
{
|
||||
project_id: project._id,
|
||||
element_id: subSubFile._id,
|
||||
type: 'fileRefs'
|
||||
},
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(!err)
|
||||
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')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -213,23 +210,27 @@ describe('ProjectLocator', function() {
|
|||
|
||||
describe('finding an element with wrong element type', function() {
|
||||
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' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(!err)
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
foundElement._id.should.equal(subSubDoc._id)
|
||||
return done()
|
||||
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' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(!err)
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
foundElement._id.should.equal(file1._id)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -249,15 +250,17 @@ describe('ProjectLocator', function() {
|
|||
rootFolder: [rootFolder2]
|
||||
}
|
||||
it('should find doc in project', function(done) {
|
||||
return this.locator.findElement(
|
||||
this.locator.findElement(
|
||||
{ project: project2, element_id: doc3._id, type: 'docs' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
assert(err == null)
|
||||
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')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -265,36 +268,44 @@ describe('ProjectLocator', function() {
|
|||
|
||||
describe('finding root doc', function() {
|
||||
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)
|
||||
return done()
|
||||
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)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return null when the project has no rootDoc', function(done) {
|
||||
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)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return null when the rootDoc_id no longer exists', function(done) {
|
||||
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)
|
||||
return done()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -302,48 +313,60 @@ describe('ProjectLocator', function() {
|
|||
describe('findElementByPath', function() {
|
||||
it('should take a doc path and return the element for a root level document', function(done) {
|
||||
const path = `${doc1.name}`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(doc1)
|
||||
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) {
|
||||
const path = `/${doc1.name}`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(doc1)
|
||||
expect(type).to.equal('doc')
|
||||
return done()
|
||||
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}`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(subSubDoc)
|
||||
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) {
|
||||
const path = `${file1.name}`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(file1)
|
||||
expect(type).to.equal('file')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -352,74 +375,86 @@ describe('ProjectLocator', function() {
|
|||
const path = `${subFolder.name}/${secondSubFolder.name}/${
|
||||
subSubFile.name
|
||||
}`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(subSubFile)
|
||||
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) {
|
||||
const path = `${subFolder.name.toUpperCase()}/${secondSubFolder.name.toUpperCase()}/${subSubFile.name.toUpperCase()}`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(subSubFile)
|
||||
expect(type).to.equal('file')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a file path and return the element for a nested folder', function(done) {
|
||||
const path = `${subFolder.name}/${secondSubFolder.name}`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(secondSubFolder)
|
||||
expect(type).to.equal('folder')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a file path and return the root folder', function(done) {
|
||||
const path = '/'
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.should.deep.equal(rootFolder)
|
||||
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) {
|
||||
const path = `${subFolder.name}/${secondSubFolder.name}/exist.txt`
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
err.should.not.equal(undefined)
|
||||
assert.equal(element, undefined)
|
||||
expect(element).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) {
|
||||
const path = 'this/does/not/exist.txt'
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
(err, element, type) => {
|
||||
err.should.not.equal(undefined)
|
||||
assert.equal(element, undefined)
|
||||
expect(element).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' })],
|
||||
fileRefs: []
|
||||
}
|
||||
return (this.project = {
|
||||
this.project = {
|
||||
rootFolder: [
|
||||
{
|
||||
folders: [this.duplicateFolder, this.duplicateFolder],
|
||||
|
@ -448,29 +483,27 @@ describe('ProjectLocator', function() {
|
|||
docs: []
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should not call the callback more than once', function(done) {
|
||||
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
|
||||
|
||||
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`
|
||||
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
|
||||
|
||||
describe('with a null doc', function() {
|
||||
beforeEach(function() {
|
||||
return (this.project = {
|
||||
this.project = {
|
||||
rootFolder: [
|
||||
{
|
||||
folders: [],
|
||||
|
@ -478,16 +511,19 @@ describe('ProjectLocator', function() {
|
|||
docs: [{ name: 'main.tex' }, null, { name: 'other.tex' }]
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('should not crash with a null', function(done) {
|
||||
const path = '/other.tex'
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project: this.project, path },
|
||||
(err, element) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
element.name.should.equal('other.tex')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -495,16 +531,16 @@ describe('ProjectLocator', function() {
|
|||
|
||||
describe('with a null project', 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) {
|
||||
const path = '/other.tex'
|
||||
return this.locator.findElementByPath(
|
||||
this.locator.findElementByPath(
|
||||
{ project_id: project._id, path },
|
||||
(err, element) => {
|
||||
expect(err).to.exist
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -513,15 +549,18 @@ describe('ProjectLocator', function() {
|
|||
describe('with a project_id', function() {
|
||||
it('should take a doc path and return the element for a root level document', function(done) {
|
||||
const path = `${doc1.name}`
|
||||
return this.locator.findElementByPath(
|
||||
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')
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -530,7 +569,7 @@ describe('ProjectLocator', 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) {
|
||||
const user_id = '123jojoidns'
|
||||
const userId = '123jojoidns'
|
||||
const stubbedProject = { name: 'findThis' }
|
||||
const projects = {
|
||||
owned: [
|
||||
|
@ -543,18 +582,21 @@ describe('ProjectLocator', function() {
|
|||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, projects)
|
||||
return this.locator.findUsersProjectByName(
|
||||
user_id,
|
||||
this.locator.findUsersProjectByName(
|
||||
userId,
|
||||
stubbedProject.name.toLowerCase(),
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.should.equal(stubbedProject)
|
||||
return done()
|
||||
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 projects = {
|
||||
owned: [
|
||||
|
@ -568,39 +610,42 @@ describe('ProjectLocator', function() {
|
|||
}
|
||||
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[0], user_id)
|
||||
.withArgs(projects.owned[0], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[1], user_id)
|
||||
.withArgs(projects.owned[1], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[2], user_id)
|
||||
.withArgs(projects.owned[2], userId)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[3], user_id)
|
||||
.withArgs(projects.owned[3], userId)
|
||||
.returns(false)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[4], user_id)
|
||||
.withArgs(projects.owned[4], userId)
|
||||
.returns(true)
|
||||
this.ProjectHelper.isArchived
|
||||
.withArgs(projects.owned[5], user_id)
|
||||
.withArgs(projects.owned[5], userId)
|
||||
.returns(false)
|
||||
|
||||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, projects)
|
||||
return this.locator.findUsersProjectByName(
|
||||
user_id,
|
||||
this.locator.findUsersProjectByName(
|
||||
userId,
|
||||
stubbedProject.name.toLowerCase(),
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project._id.should.equal(stubbedProject._id)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should search collab projects as well', function(done) {
|
||||
const user_id = '123jojoidns'
|
||||
const userId = '123jojoidns'
|
||||
const stubbedProject = { name: 'findThis' }
|
||||
const projects = {
|
||||
owned: [{ name: 'notThis' }, { name: 'wellll' }, { name: 'Noooo' }],
|
||||
|
@ -609,12 +654,15 @@ describe('ProjectLocator', function() {
|
|||
this.ProjectGetter.findAllUsersProjects = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, projects)
|
||||
return this.locator.findUsersProjectByName(
|
||||
user_id,
|
||||
this.locator.findUsersProjectByName(
|
||||
userId,
|
||||
stubbedProject.name.toLowerCase(),
|
||||
(err, project) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
project.should.equal(stubbedProject)
|
||||
return done()
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue