mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 05:41:33 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -15,75 +15,75 @@ const sinon = require('sinon')
|
||||
const modulePath = '../../../../app/src/Features/Project/DocLinesComparitor.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('doc lines comparitor', function() {
|
||||
beforeEach(function() {
|
||||
describe('doc lines comparitor', function () {
|
||||
beforeEach(function () {
|
||||
return (this.comparitor = SandboxedModule.require(modulePath, {}))
|
||||
})
|
||||
|
||||
it('should return true when the lines are the same', function() {
|
||||
it('should return true when the lines are the same', function () {
|
||||
const lines1 = ['hello', 'world']
|
||||
const lines2 = ['hello', 'world']
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return false when the lines are different', function() {
|
||||
it('should return false when the lines are different', function () {
|
||||
const lines1 = ['hello', 'world']
|
||||
const lines2 = ['diff', 'world']
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return false when the lines are different', function() {
|
||||
it('should return false when the lines are different', function () {
|
||||
const lines1 = ['hello', 'world']
|
||||
const lines2 = ['hello', 'wrld']
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return true when the lines are same', function() {
|
||||
it('should return true when the lines are same', function () {
|
||||
const lines1 = ['hello', 'world']
|
||||
const lines2 = ['hello', 'world']
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return false if the doc lines are different in length', function() {
|
||||
it('should return false if the doc lines are different in length', function () {
|
||||
const lines1 = ['hello', 'world']
|
||||
const lines2 = ['hello', 'world', 'please']
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return false if the first array is undefined', function() {
|
||||
it('should return false if the first array is undefined', function () {
|
||||
const lines1 = undefined
|
||||
const lines2 = ['hello', 'world']
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return false if the second array is undefined', function() {
|
||||
it('should return false if the second array is undefined', function () {
|
||||
const lines1 = ['hello']
|
||||
const lines2 = undefined
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return false if the second array is not an array', function() {
|
||||
it('should return false if the second array is not an array', function () {
|
||||
const lines1 = ['hello']
|
||||
const lines2 = ''
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should return true when comparing equal orchard docs', function() {
|
||||
it('should return true when comparing equal orchard docs', function () {
|
||||
const lines1 = [{ text: 'hello world' }]
|
||||
const lines2 = [{ text: 'hello world' }]
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return false when comparing different orchard docs', function() {
|
||||
it('should return false when comparing different orchard docs', function () {
|
||||
const lines1 = [{ text: 'goodbye world' }]
|
||||
const lines2 = [{ text: 'hello world' }]
|
||||
const result = this.comparitor.areSame(lines1, lines2)
|
||||
|
||||
@@ -6,8 +6,8 @@ const MODULE_PATH =
|
||||
'../../../../app/src/Features/Project/FolderStructureBuilder'
|
||||
const MOCK_OBJECT_ID = 'MOCK_OBJECT_ID'
|
||||
|
||||
describe('FolderStructureBuilder', function() {
|
||||
beforeEach(function() {
|
||||
describe('FolderStructureBuilder', function () {
|
||||
beforeEach(function () {
|
||||
this.ObjectId = sinon.stub().returns(MOCK_OBJECT_ID)
|
||||
this.FolderStructureBuilder = SandboxedModule.require(MODULE_PATH, {
|
||||
requires: {
|
||||
@@ -16,13 +16,13 @@ describe('FolderStructureBuilder', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildFolderStructure', function() {
|
||||
describe('when given no documents at all', function() {
|
||||
beforeEach(function() {
|
||||
describe('buildFolderStructure', function () {
|
||||
describe('when given no documents at all', function () {
|
||||
beforeEach(function () {
|
||||
this.result = this.FolderStructureBuilder.buildFolderStructure([], [])
|
||||
})
|
||||
|
||||
it('returns an empty root folder', function() {
|
||||
it('returns an empty root folder', function () {
|
||||
expect(this.result).to.deep.equal({
|
||||
_id: MOCK_OBJECT_ID,
|
||||
name: 'rootFolder',
|
||||
@@ -33,8 +33,8 @@ describe('FolderStructureBuilder', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when given documents and files', function() {
|
||||
beforeEach(function() {
|
||||
describe('when given documents and files', function () {
|
||||
beforeEach(function () {
|
||||
const docUploads = [
|
||||
{ path: '/main.tex', doc: { _id: 'doc-1', name: 'main.tex' } },
|
||||
{ path: '/foo/other.tex', doc: { _id: 'doc-2', name: 'other.tex' } },
|
||||
@@ -55,7 +55,7 @@ describe('FolderStructureBuilder', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('returns a full folder structure', function() {
|
||||
it('returns a full folder structure', function () {
|
||||
expect(this.result).to.deep.equal({
|
||||
_id: MOCK_OBJECT_ID,
|
||||
name: 'rootFolder',
|
||||
@@ -100,8 +100,8 @@ describe('FolderStructureBuilder', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when given duplicate files', function() {
|
||||
it('throws an error', function() {
|
||||
describe('when given duplicate files', function () {
|
||||
it('throws an error', function () {
|
||||
const docUploads = [
|
||||
{ path: '/foo/doc.tex', doc: { _id: 'doc-1', name: 'doc.tex' } },
|
||||
{ path: '/foo/doc.tex', doc: { _id: 'doc-2', name: 'doc.tex' } }
|
||||
|
||||
@@ -14,8 +14,8 @@ const modulePath = '../../../../app/src/Features/Project/ProjectApiController'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const sinon = require('sinon')
|
||||
|
||||
describe('Project api controller', function() {
|
||||
beforeEach(function() {
|
||||
describe('Project api controller', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectDetailsHandler = { getDetails: sinon.stub() }
|
||||
this.controller = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
@@ -36,8 +36,8 @@ describe('Project api controller', function() {
|
||||
return (this.projDetails = { name: 'something' })
|
||||
})
|
||||
|
||||
describe('getProjectDetails', function() {
|
||||
it('should ask the project details handler for proj details', function(done) {
|
||||
describe('getProjectDetails', function () {
|
||||
it('should ask the project details handler for proj details', function (done) {
|
||||
this.ProjectDetailsHandler.getDetails.callsArgWith(
|
||||
1,
|
||||
null,
|
||||
@@ -53,7 +53,7 @@ describe('Project api controller', function() {
|
||||
return this.controller.getProjectDetails(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send a 500 if there is an error', function() {
|
||||
it('should send a 500 if there is an error', function () {
|
||||
this.ProjectDetailsHandler.getDetails.callsArgWith(1, 'error')
|
||||
this.controller.getProjectDetails(this.req, this.res, this.next)
|
||||
return this.next.calledWith('error').should.equal(true)
|
||||
|
||||
@@ -7,8 +7,8 @@ const { Project } = require('../helpers/models/Project')
|
||||
const MODULE_PATH =
|
||||
'../../../../app/src/Features/Project/ProjectAuditLogHandler'
|
||||
|
||||
describe('ProjectAuditLogHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectAuditLogHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.projectId = ObjectId()
|
||||
this.userId = ObjectId()
|
||||
this.ProjectMock = sinon.mock(Project)
|
||||
@@ -19,13 +19,13 @@ describe('ProjectAuditLogHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
this.ProjectMock.restore()
|
||||
})
|
||||
|
||||
describe('addEntry', function() {
|
||||
describe('success', function() {
|
||||
beforeEach(async function() {
|
||||
describe('addEntry', function () {
|
||||
describe('success', function () {
|
||||
beforeEach(async function () {
|
||||
this.dbUpdate = this.ProjectMock.expects('updateOne').withArgs(
|
||||
{ _id: this.projectId },
|
||||
{
|
||||
@@ -53,19 +53,19 @@ describe('ProjectAuditLogHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('writes a log', async function() {
|
||||
it('writes a log', async function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the project does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the project does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectMock.expects('updateOne')
|
||||
.chain('exec')
|
||||
.resolves({ nModified: 0 })
|
||||
})
|
||||
|
||||
it('throws an error', async function() {
|
||||
it('throws an error', async function () {
|
||||
await expect(
|
||||
this.ProjectAuditLogHandler.promises.addEntry(
|
||||
this.projectId,
|
||||
|
||||
@@ -23,8 +23,8 @@ const modulePath = Path.join(
|
||||
'../../../../app/src/Features/Project/ProjectCollabratecDetailsHandler'
|
||||
)
|
||||
|
||||
describe('ProjectCollabratecDetailsHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectCollabratecDetailsHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.projectId = ObjectId('5bea8747c7bba6012fcaceb3')
|
||||
this.userId = ObjectId('5be316a9c7f6aa03802ea8fb')
|
||||
this.userId2 = ObjectId('5c1794b3f0e89b1d1c577eca')
|
||||
@@ -41,9 +41,9 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('initializeCollabratecProject', function() {
|
||||
describe('when update succeeds', function() {
|
||||
beforeEach(function() {
|
||||
describe('initializeCollabratecProject', function () {
|
||||
describe('when update succeeds', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields()
|
||||
return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject(
|
||||
this.projectId,
|
||||
@@ -54,7 +54,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update project model', function() {
|
||||
it('should update project model', function () {
|
||||
const update = {
|
||||
$set: {
|
||||
collabratecUsers: [
|
||||
@@ -74,8 +74,8 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when update has error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when update has error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields('error')
|
||||
return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject(
|
||||
this.projectId,
|
||||
@@ -86,13 +86,13 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback).to.have.been.calledWith('error')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid args', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid args', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject(
|
||||
'bad-project-id',
|
||||
@@ -103,24 +103,24 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('isLinkedCollabratecUserProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('isLinkedCollabratecUserProject', function () {
|
||||
beforeEach(function () {
|
||||
return (this.ProjectModel.findOne = sinon.stub().yields())
|
||||
})
|
||||
|
||||
describe('when find succeeds', function() {
|
||||
describe('when user project found', function() {
|
||||
beforeEach(function() {
|
||||
describe('when find succeeds', function () {
|
||||
describe('when user project found', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.findOne = sinon.stub().yields(null, 'project')
|
||||
return this.ProjectCollabratecDetailsHandler.isLinkedCollabratecUserProject(
|
||||
this.projectId,
|
||||
@@ -129,7 +129,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call find with project and user id', function() {
|
||||
it('should call find with project and user id', function () {
|
||||
return expect(this.ProjectModel.findOne).to.have.been.calledWithMatch(
|
||||
{
|
||||
_id: ObjectId(this.projectId),
|
||||
@@ -142,13 +142,13 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with true', function() {
|
||||
it('should callback with true', function () {
|
||||
return expect(this.callback).to.have.been.calledWith(null, true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when user project found', function() {
|
||||
beforeEach(function() {
|
||||
describe('when user project found', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.findOne = sinon.stub().yields(null, null)
|
||||
return this.ProjectCollabratecDetailsHandler.isLinkedCollabratecUserProject(
|
||||
this.projectId,
|
||||
@@ -157,14 +157,14 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with false', function() {
|
||||
it('should callback with false', function () {
|
||||
return expect(this.callback).to.have.been.calledWith(null, false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when find has error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when find has error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.findOne = sinon.stub().yields('error')
|
||||
return this.ProjectCollabratecDetailsHandler.isLinkedCollabratecUserProject(
|
||||
this.projectId,
|
||||
@@ -173,13 +173,13 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback).to.have.been.calledWith('error')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid args', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid args', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.findOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.isLinkedCollabratecUserProject(
|
||||
'bad-project-id',
|
||||
@@ -188,19 +188,19 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.findOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('linkCollabratecUserProject', function() {
|
||||
describe('when update succeeds', function() {
|
||||
beforeEach(function() {
|
||||
describe('linkCollabratecUserProject', function () {
|
||||
describe('when update succeeds', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields()
|
||||
return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject(
|
||||
this.projectId,
|
||||
@@ -210,7 +210,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update project model', function() {
|
||||
it('should update project model', function () {
|
||||
const query = {
|
||||
_id: this.projectId,
|
||||
collabratecUsers: {
|
||||
@@ -238,8 +238,8 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when update has error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when update has error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields('error')
|
||||
return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject(
|
||||
this.projectId,
|
||||
@@ -249,13 +249,13 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback).to.have.been.calledWith('error')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid args', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid args', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject(
|
||||
'bad-project-id',
|
||||
@@ -265,18 +265,18 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('setCollabratecUsers', function() {
|
||||
beforeEach(function() {
|
||||
describe('setCollabratecUsers', function () {
|
||||
beforeEach(function () {
|
||||
return (this.collabratecUsers = [
|
||||
{
|
||||
user_id: this.userId,
|
||||
@@ -291,8 +291,8 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
])
|
||||
})
|
||||
|
||||
describe('when update succeeds', function() {
|
||||
beforeEach(function() {
|
||||
describe('when update succeeds', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields()
|
||||
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
|
||||
this.projectId,
|
||||
@@ -301,7 +301,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update project model', function() {
|
||||
it('should update project model', function () {
|
||||
const update = {
|
||||
$set: {
|
||||
collabratecUsers: this.collabratecUsers
|
||||
@@ -315,8 +315,8 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when update has error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when update has error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields('error')
|
||||
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
|
||||
this.projectId,
|
||||
@@ -325,13 +325,13 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback).to.have.been.calledWith('error')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid project_id', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid project_id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
|
||||
'bad-project-id',
|
||||
@@ -340,17 +340,17 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid user_id', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid user_id', function () {
|
||||
beforeEach(function () {
|
||||
this.collabratecUsers[1].user_id = 'bad-user-id'
|
||||
this.ProjectModel.updateOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.setCollabratecUsers(
|
||||
@@ -360,19 +360,19 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('unlinkCollabratecUserProject', function() {
|
||||
describe('when update succeeds', function() {
|
||||
beforeEach(function() {
|
||||
describe('unlinkCollabratecUserProject', function () {
|
||||
describe('when update succeeds', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields()
|
||||
return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject(
|
||||
this.projectId,
|
||||
@@ -381,7 +381,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update project model', function() {
|
||||
it('should update project model', function () {
|
||||
const query = { _id: this.projectId }
|
||||
const update = {
|
||||
$pull: {
|
||||
@@ -398,8 +398,8 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when update has error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when update has error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub().yields('error')
|
||||
return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject(
|
||||
this.projectId,
|
||||
@@ -408,13 +408,13 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback).to.have.been.calledWith('error')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid args', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid args', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject(
|
||||
'bad-project-id',
|
||||
@@ -423,19 +423,19 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateCollabratecUserIds', function() {
|
||||
describe('when update succeeds', function() {
|
||||
beforeEach(function() {
|
||||
describe('updateCollabratecUserIds', function () {
|
||||
describe('when update succeeds', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateMany = sinon.stub().yields()
|
||||
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
|
||||
this.userId,
|
||||
@@ -444,7 +444,7 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update project model', function() {
|
||||
it('should update project model', function () {
|
||||
return expect(this.ProjectModel.updateMany).to.have.been.calledWith(
|
||||
{ 'collabratecUsers.user_id': this.userId },
|
||||
{ $set: { 'collabratecUsers.$.user_id': this.userId2 } },
|
||||
@@ -453,8 +453,8 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when update has error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when update has error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateMany = sinon.stub().yields('error')
|
||||
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
|
||||
this.userId,
|
||||
@@ -463,13 +463,13 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback).to.have.been.calledWith('error')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid old_user_id', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid old_user_id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
|
||||
'bad-user-id',
|
||||
@@ -478,17 +478,17 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid new_user_id', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid new_user_id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.updateOne = sinon.stub()
|
||||
return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds(
|
||||
this.userId,
|
||||
@@ -497,11 +497,11 @@ describe('ProjectCollabratecDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update', function() {
|
||||
it('should not update', function () {
|
||||
return expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
return expect(this.callback.firstCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,8 +10,8 @@ const MODULE_PATH = path.join(
|
||||
'../../../../app/src/Features/Project/ProjectController'
|
||||
)
|
||||
|
||||
describe('ProjectController', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectController', function () {
|
||||
beforeEach(function () {
|
||||
this.project_id = ObjectId('abcdefabcdefabcdefabcdef')
|
||||
|
||||
this.user = {
|
||||
@@ -194,8 +194,8 @@ describe('ProjectController', function() {
|
||||
}
|
||||
})
|
||||
|
||||
describe('updateProjectSettings', function() {
|
||||
it('should update the name', function(done) {
|
||||
describe('updateProjectSettings', function () {
|
||||
it('should update the name', function (done) {
|
||||
this.EditorController.renameProject = sinon.stub().callsArg(2)
|
||||
this.req.body = { name: (this.name = 'New name') }
|
||||
this.res.sendStatus = code => {
|
||||
@@ -208,7 +208,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.updateProjectSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should update the compiler', function(done) {
|
||||
it('should update the compiler', function (done) {
|
||||
this.EditorController.setCompiler = sinon.stub().callsArg(2)
|
||||
this.req.body = { compiler: (this.compiler = 'pdflatex') }
|
||||
this.res.sendStatus = code => {
|
||||
@@ -221,7 +221,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.updateProjectSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should update the imageName', function(done) {
|
||||
it('should update the imageName', function (done) {
|
||||
this.EditorController.setImageName = sinon.stub().callsArg(2)
|
||||
this.req.body = { imageName: (this.imageName = 'texlive-1234.5') }
|
||||
this.res.sendStatus = code => {
|
||||
@@ -234,7 +234,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.updateProjectSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should update the spell check language', function(done) {
|
||||
it('should update the spell check language', function (done) {
|
||||
this.EditorController.setSpellCheckLanguage = sinon.stub().callsArg(2)
|
||||
this.req.body = { spellCheckLanguage: (this.languageCode = 'fr') }
|
||||
this.res.sendStatus = code => {
|
||||
@@ -247,7 +247,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.updateProjectSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should update the root doc', function(done) {
|
||||
it('should update the root doc', function (done) {
|
||||
this.EditorController.setRootDoc = sinon.stub().callsArg(2)
|
||||
this.req.body = { rootDocId: (this.rootDocId = 'root-doc-id') }
|
||||
this.res.sendStatus = code => {
|
||||
@@ -261,8 +261,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateProjectAdminSettings', function() {
|
||||
it('should update the public access level', function(done) {
|
||||
describe('updateProjectAdminSettings', function () {
|
||||
it('should update the public access level', function (done) {
|
||||
this.EditorController.setPublicAccessLevel = sinon.stub().callsArg(2)
|
||||
this.req.body = {
|
||||
publicAccessLevel: (this.publicAccessLevel = 'readonly')
|
||||
@@ -278,8 +278,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteProject', function() {
|
||||
it('should call the project deleter', function(done) {
|
||||
describe('deleteProject', function () {
|
||||
it('should call the project deleter', function (done) {
|
||||
this.res.sendStatus = code => {
|
||||
this.ProjectDeleter.deleteProject
|
||||
.calledWith(this.project_id, {
|
||||
@@ -294,8 +294,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('restoreProject', function() {
|
||||
it('should tell the project deleter', function(done) {
|
||||
describe('restoreProject', function () {
|
||||
it('should tell the project deleter', function (done) {
|
||||
this.res.sendStatus = code => {
|
||||
this.ProjectDeleter.restoreProject
|
||||
.calledWith(this.project_id)
|
||||
@@ -307,8 +307,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('cloneProject', function() {
|
||||
it('should call the project duplicator', function(done) {
|
||||
describe('cloneProject', function () {
|
||||
it('should call the project duplicator', function (done) {
|
||||
this.res.send = json => {
|
||||
this.ProjectDuplicator.duplicate
|
||||
.calledWith(this.user, this.project_id, this.projectName)
|
||||
@@ -320,8 +320,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('newProject', function() {
|
||||
it('should call the projectCreationHandler with createExampleProject', function(done) {
|
||||
describe('newProject', function () {
|
||||
it('should call the projectCreationHandler with createExampleProject', function (done) {
|
||||
this.req.body.template = 'example'
|
||||
this.res.send = json => {
|
||||
this.ProjectCreationHandler.createExampleProject
|
||||
@@ -335,7 +335,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.newProject(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should call the projectCreationHandler with createBasicProject', function(done) {
|
||||
it('should call the projectCreationHandler with createBasicProject', function (done) {
|
||||
this.req.body.template = 'basic'
|
||||
this.res.send = json => {
|
||||
this.ProjectCreationHandler.createExampleProject.called.should.equal(
|
||||
@@ -350,8 +350,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('projectListPage', function() {
|
||||
beforeEach(function() {
|
||||
describe('projectListPage', function () {
|
||||
beforeEach(function () {
|
||||
this.tags = [
|
||||
{ name: 1, project_ids: ['1', '2', '3'] },
|
||||
{ name: 2, project_ids: ['a', '1'] },
|
||||
@@ -404,7 +404,7 @@ describe('ProjectController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should render the project/list page', function(done) {
|
||||
it('should render the project/list page', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
pageName.should.equal('project/list')
|
||||
done()
|
||||
@@ -412,7 +412,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send the tags', function(done) {
|
||||
it('should send the tags', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.tags.length.should.equal(this.tags.length)
|
||||
done()
|
||||
@@ -420,7 +420,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should create trigger ip matcher notifications', function(done) {
|
||||
it('should create trigger ip matcher notifications', function (done) {
|
||||
this.settings.overleaf = true
|
||||
this.res.render = (pageName, opts) => {
|
||||
this.NotificationBuilder.ipMatcherAffiliation.called.should.equal(true)
|
||||
@@ -429,7 +429,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send the projects', function(done) {
|
||||
it('should send the projects', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.projects.length.should.equal(
|
||||
this.projects.length +
|
||||
@@ -443,7 +443,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send the user', function(done) {
|
||||
it('should send the user', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.user.should.deep.equal(this.user)
|
||||
done()
|
||||
@@ -451,7 +451,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should inject the users', function(done) {
|
||||
it('should inject the users', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.projects[0].owner.should.equal(
|
||||
this.users[this.projects[0].owner_ref]
|
||||
@@ -467,7 +467,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send hasSubscription == false when no subscription', function(done) {
|
||||
it('should send hasSubscription == false when no subscription', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.hasSubscription.should.equal(false)
|
||||
done()
|
||||
@@ -475,7 +475,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send hasSubscription == true when there is a subscription', function(done) {
|
||||
it('should send hasSubscription == true when there is a subscription', function (done) {
|
||||
this.LimitationsManager.hasPaidSubscription = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, true)
|
||||
@@ -486,14 +486,14 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('front widget', function(done) {
|
||||
beforeEach(function() {
|
||||
describe('front widget', function (done) {
|
||||
beforeEach(function () {
|
||||
this.settings.overleaf = {
|
||||
front_chat_widget_room_id: 'chat-room-id'
|
||||
}
|
||||
})
|
||||
|
||||
it('should show for paid users', function(done) {
|
||||
it('should show for paid users', function (done) {
|
||||
this.user.features.github = true
|
||||
this.user.features.dropbox = true
|
||||
this.res.render = (pageName, opts) => {
|
||||
@@ -505,7 +505,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should show for sample users', function(done) {
|
||||
it('should show for sample users', function (done) {
|
||||
this.user._id = ObjectId('588f3ddae8ebc1bac07c9f00') // last two digits
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.frontChatWidgetRoomId.should.equal(
|
||||
@@ -516,7 +516,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should not show for non sample users', function(done) {
|
||||
it('should not show for non sample users', function (done) {
|
||||
this.user._id = ObjectId('588f3ddae8ebc1bac07c9fff') // last two digits
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.frontChatWidgetRoomId).to.equal(undefined)
|
||||
@@ -526,8 +526,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('With Institution SSO feature', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('With Institution SSO feature', function () {
|
||||
beforeEach(function (done) {
|
||||
this.institutionEmail = 'test@overleaf.com'
|
||||
this.institutionName = 'Overleaf'
|
||||
this.Features.hasFeature.withArgs('saml').returns(true)
|
||||
@@ -535,7 +535,7 @@ describe('ProjectController', function() {
|
||||
this.Features.hasFeature.withArgs('overleaf-integration').returns(true)
|
||||
done()
|
||||
})
|
||||
it('should show institution SSO available notification for confirmed domains', function() {
|
||||
it('should show institution SSO available notification for confirmed domains', function () {
|
||||
this.UserGetter.getUserFullEmails.yields(null, [
|
||||
{
|
||||
email: 'test@overleaf.com',
|
||||
@@ -560,7 +560,7 @@ describe('ProjectController', function() {
|
||||
}
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
it('should show a linked notification', function() {
|
||||
it('should show a linked notification', function () {
|
||||
this.req.session.saml = {
|
||||
institutionEmail: this.institutionEmail,
|
||||
linked: {
|
||||
@@ -577,7 +577,7 @@ describe('ProjectController', function() {
|
||||
}
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
it('should show a linked another email notification', function() {
|
||||
it('should show a linked another email notification', function () {
|
||||
// when they request to link an email but the institution returns
|
||||
// a different email
|
||||
this.res.render = (pageName, opts) => {
|
||||
@@ -599,7 +599,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should show a notification when intent was to register via SSO but account existed', function() {
|
||||
it('should show a notification when intent was to register via SSO but account existed', function () {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.notificationsInstitution).to.deep.include({
|
||||
email: this.institutionEmail,
|
||||
@@ -620,7 +620,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should not show a register notification if the flow was abandoned', function() {
|
||||
it('should not show a register notification if the flow was abandoned', function () {
|
||||
// could initially start to register with an SSO email and then
|
||||
// abandon flow and login with an existing non-institution SSO email
|
||||
this.res.render = (pageName, opts) => {
|
||||
@@ -638,7 +638,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should show error notification', function() {
|
||||
it('should show error notification', function () {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.notificationsInstitution.length).to.equal(1)
|
||||
expect(opts.notificationsInstitution[0].templateKey).to.equal(
|
||||
@@ -655,8 +655,8 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('for an unconfirmed domain for an SSO institution', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('for an unconfirmed domain for an SSO institution', function () {
|
||||
beforeEach(function (done) {
|
||||
this.UserGetter.getUserFullEmails.yields(null, [
|
||||
{
|
||||
email: 'test@overleaf-uncofirmed.com',
|
||||
@@ -673,15 +673,15 @@ describe('ProjectController', function() {
|
||||
])
|
||||
done()
|
||||
})
|
||||
it('should not show institution SSO available notification', function() {
|
||||
it('should not show institution SSO available notification', function () {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.notificationsInstitution.length).to.equal(0)
|
||||
}
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
})
|
||||
describe('when linking/logging in initiated on institution side', function() {
|
||||
it('should not show a linked another email notification', function() {
|
||||
describe('when linking/logging in initiated on institution side', function () {
|
||||
it('should not show a linked another email notification', function () {
|
||||
// this is only used when initated on Overleaf,
|
||||
// because we keep track of the requested email they tried to link
|
||||
this.res.render = (pageName, opts) => {
|
||||
@@ -702,8 +702,8 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
})
|
||||
describe('Institution with SSO beta testable', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('Institution with SSO beta testable', function () {
|
||||
beforeEach(function (done) {
|
||||
this.UserGetter.getUserFullEmails.yields(null, [
|
||||
{
|
||||
email: 'beta@beta.com',
|
||||
@@ -720,7 +720,7 @@ describe('ProjectController', function() {
|
||||
])
|
||||
done()
|
||||
})
|
||||
it('should show institution SSO available notification when on a beta testing session', function() {
|
||||
it('should show institution SSO available notification when on a beta testing session', function () {
|
||||
this.req.session.samlBeta = true
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.notificationsInstitution).to.deep.include({
|
||||
@@ -732,7 +732,7 @@ describe('ProjectController', function() {
|
||||
}
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
it('should not show institution SSO available notification when not on a beta testing session', function() {
|
||||
it('should not show institution SSO available notification when not on a beta testing session', function () {
|
||||
this.req.session.samlBeta = false
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.notificationsInstitution).to.deep.not.include({
|
||||
@@ -747,12 +747,12 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Without Institution SSO feature', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('Without Institution SSO feature', function () {
|
||||
beforeEach(function (done) {
|
||||
this.Features.hasFeature.withArgs('saml').returns(false)
|
||||
done()
|
||||
})
|
||||
it('should not show institution sso available notification', function() {
|
||||
it('should not show institution sso available notification', function () {
|
||||
this.res.render = (pageName, opts) => {
|
||||
expect(opts.notificationsInstitution).to.deep.not.include({
|
||||
email: 'test@overleaf.com',
|
||||
@@ -766,8 +766,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('projectListPage with duplicate projects', function() {
|
||||
beforeEach(function() {
|
||||
describe('projectListPage with duplicate projects', function () {
|
||||
beforeEach(function () {
|
||||
this.tags = [
|
||||
{ name: 1, project_ids: ['1', '2', '3'] },
|
||||
{ name: 2, project_ids: ['a', '1'] },
|
||||
@@ -820,7 +820,7 @@ describe('ProjectController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should render the project/list page', function(done) {
|
||||
it('should render the project/list page', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
pageName.should.equal('project/list')
|
||||
done()
|
||||
@@ -828,7 +828,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.projectListPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should omit one of the projects', function(done) {
|
||||
it('should omit one of the projects', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.projects.length.should.equal(
|
||||
this.projects.length +
|
||||
@@ -844,13 +844,13 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('renameProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('renameProject', function () {
|
||||
beforeEach(function () {
|
||||
this.newProjectName = 'my supper great new project'
|
||||
this.req.body.newProjectName = this.newProjectName
|
||||
})
|
||||
|
||||
it('should call the editor controller', function(done) {
|
||||
it('should call the editor controller', function (done) {
|
||||
this.EditorController.renameProject.callsArgWith(2)
|
||||
this.res.sendStatus = code => {
|
||||
code.should.equal(200)
|
||||
@@ -862,7 +862,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.renameProject(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send an error to next() if there is a problem', function(done) {
|
||||
it('should send an error to next() if there is a problem', function (done) {
|
||||
let error
|
||||
this.EditorController.renameProject.callsArgWith(
|
||||
2,
|
||||
@@ -876,8 +876,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('loadEditor', function() {
|
||||
beforeEach(function() {
|
||||
describe('loadEditor', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.editorIsOpen = true
|
||||
this.project = {
|
||||
name: 'my proj',
|
||||
@@ -911,7 +911,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectUpdateHandler.markAsOpened.callsArgWith(1)
|
||||
})
|
||||
|
||||
it('should render the project/editor page', function(done) {
|
||||
it('should render the project/editor page', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
pageName.should.equal('project/editor')
|
||||
done()
|
||||
@@ -919,7 +919,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should add user', function(done) {
|
||||
it('should add user', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.user.email.should.equal(this.user.email)
|
||||
done()
|
||||
@@ -927,7 +927,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should add on userSettings', function(done) {
|
||||
it('should add on userSettings', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.userSettings.fontSize.should.equal(this.user.ace.fontSize)
|
||||
opts.userSettings.editorTheme.should.equal(this.user.ace.theme)
|
||||
@@ -936,7 +936,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should add isRestrictedTokenMember', function(done) {
|
||||
it('should add isRestrictedTokenMember', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.isRestrictedTokenMember.should.exist
|
||||
opts.isRestrictedTokenMember.should.equal(false)
|
||||
@@ -945,7 +945,7 @@ describe('ProjectController', function() {
|
||||
return this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set isRestrictedTokenMember when appropriate', function(done) {
|
||||
it('should set isRestrictedTokenMember when appropriate', function (done) {
|
||||
this.AuthorizationManager.isRestrictedUser.returns(true)
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.isRestrictedTokenMember.should.exist
|
||||
@@ -955,7 +955,7 @@ describe('ProjectController', function() {
|
||||
return this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should render the closed page if the editor is closed', function(done) {
|
||||
it('should render the closed page if the editor is closed', function (done) {
|
||||
this.settings.editorIsOpen = false
|
||||
this.res.render = (pageName, opts) => {
|
||||
pageName.should.equal('general/closed')
|
||||
@@ -964,7 +964,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should not render the page if the project can not be accessed', function(done) {
|
||||
it('should not render the page if the project can not be accessed', function (done) {
|
||||
this.AuthorizationManager.getPrivilegeLevelForProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(3, null, null)
|
||||
@@ -975,7 +975,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should reactivateProjectIfRequired', function(done) {
|
||||
it('should reactivateProjectIfRequired', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
this.InactiveProjectManager.reactivateProjectIfRequired
|
||||
.calledWith(this.project_id)
|
||||
@@ -985,7 +985,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should mark project as opened', function(done) {
|
||||
it('should mark project as opened', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
this.ProjectUpdateHandler.markAsOpened
|
||||
.calledWith(this.project_id)
|
||||
@@ -995,7 +995,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should call the brand variations handler for branded projects', function(done) {
|
||||
it('should call the brand variations handler for branded projects', function (done) {
|
||||
this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
|
||||
this.res.render = (pageName, opts) => {
|
||||
this.BrandVariationsHandler.getBrandVariationById
|
||||
@@ -1006,7 +1006,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should not call the brand variations handler for unbranded projects', function(done) {
|
||||
it('should not call the brand variations handler for unbranded projects', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
this.BrandVariationsHandler.getBrandVariationById.called.should.equal(
|
||||
false
|
||||
@@ -1016,7 +1016,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should expose the brand variation details as locals for branded projects', function(done) {
|
||||
it('should expose the brand variation details as locals for branded projects', function (done) {
|
||||
this.ProjectGetter.getProject.callsArgWith(2, null, this.brandedProject)
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.brandVariation.should.deep.equal(this.brandVariationDetails)
|
||||
@@ -1025,7 +1025,7 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('flushes the project to TPDS if a flush is pending', function(done) {
|
||||
it('flushes the project to TPDS if a flush is pending', function (done) {
|
||||
this.res.render = () => {
|
||||
this.TpdsProjectFlusher.flushProjectToTpdsIfNeeded.should.have.been.calledWith(
|
||||
this.project_id
|
||||
@@ -1035,9 +1035,9 @@ describe('ProjectController', function() {
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('wsUrl', function() {
|
||||
describe('wsUrl', function () {
|
||||
function checkLoadEditorWsMetric(metric) {
|
||||
it(`should inc metric ${metric}`, function(done) {
|
||||
it(`should inc metric ${metric}`, function (done) {
|
||||
this.res.render = () => {
|
||||
this.Metrics.inc.calledWith(metric).should.equal(true)
|
||||
done()
|
||||
@@ -1046,12 +1046,12 @@ describe('ProjectController', function() {
|
||||
})
|
||||
}
|
||||
function checkWsFallback(isBeta, isV2) {
|
||||
describe('with ws=fallback', function() {
|
||||
beforeEach(function() {
|
||||
describe('with ws=fallback', function () {
|
||||
beforeEach(function () {
|
||||
this.req.query = {}
|
||||
this.req.query.ws = 'fallback'
|
||||
})
|
||||
it('should unset the wsUrl', function(done) {
|
||||
it('should unset the wsUrl', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
;(opts.wsUrl || '/socket.io').should.equal('/socket.io')
|
||||
done()
|
||||
@@ -1066,10 +1066,10 @@ describe('ProjectController', function() {
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.settings.wsUrl = '/other.socket.io'
|
||||
})
|
||||
it('should set the custom wsUrl', function(done) {
|
||||
it('should set the custom wsUrl', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.wsUrl.should.equal('/other.socket.io')
|
||||
done()
|
||||
@@ -1079,12 +1079,12 @@ describe('ProjectController', function() {
|
||||
checkLoadEditorWsMetric('load-editor-ws')
|
||||
checkWsFallback(false)
|
||||
|
||||
describe('beta program', function() {
|
||||
beforeEach(function() {
|
||||
describe('beta program', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.wsUrlBeta = '/beta.socket.io'
|
||||
})
|
||||
describe('for a normal user', function() {
|
||||
it('should set the normal custom wsUrl', function(done) {
|
||||
describe('for a normal user', function () {
|
||||
it('should set the normal custom wsUrl', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.wsUrl.should.equal('/other.socket.io')
|
||||
done()
|
||||
@@ -1095,11 +1095,11 @@ describe('ProjectController', function() {
|
||||
checkWsFallback(false)
|
||||
})
|
||||
|
||||
describe('for a beta user', function() {
|
||||
beforeEach(function() {
|
||||
describe('for a beta user', function () {
|
||||
beforeEach(function () {
|
||||
this.user.betaProgram = true
|
||||
})
|
||||
it('should set the beta wsUrl', function(done) {
|
||||
it('should set the beta wsUrl', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.wsUrl.should.equal('/beta.socket.io')
|
||||
done()
|
||||
@@ -1111,14 +1111,14 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('v2-rollout', function() {
|
||||
beforeEach(function() {
|
||||
describe('v2-rollout', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.wsUrlBeta = '/beta.socket.io'
|
||||
this.settings.wsUrlV2 = '/socket.io.v2'
|
||||
})
|
||||
|
||||
function checkNonMatch() {
|
||||
it('should set the normal custom wsUrl', function(done) {
|
||||
it('should set the normal custom wsUrl', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.wsUrl.should.equal('/other.socket.io')
|
||||
done()
|
||||
@@ -1129,7 +1129,7 @@ describe('ProjectController', function() {
|
||||
checkWsFallback(false)
|
||||
}
|
||||
function checkMatch() {
|
||||
it('should set the v2 wsUrl', function(done) {
|
||||
it('should set the v2 wsUrl', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.wsUrl.should.equal('/socket.io.v2')
|
||||
done()
|
||||
@@ -1140,11 +1140,11 @@ describe('ProjectController', function() {
|
||||
checkWsFallback(false, true)
|
||||
}
|
||||
function checkForBetaUser() {
|
||||
describe('for a beta user', function() {
|
||||
beforeEach(function() {
|
||||
describe('for a beta user', function () {
|
||||
beforeEach(function () {
|
||||
this.user.betaProgram = true
|
||||
})
|
||||
it('should set the beta wsUrl', function(done) {
|
||||
it('should set the beta wsUrl', function (done) {
|
||||
this.res.render = (pageName, opts) => {
|
||||
opts.wsUrl.should.equal('/beta.socket.io')
|
||||
done()
|
||||
@@ -1156,105 +1156,105 @@ describe('ProjectController', function() {
|
||||
})
|
||||
}
|
||||
|
||||
describe('when the roll out percentage is 0', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the roll out percentage is 0', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.wsUrlV2Percentage = 0
|
||||
})
|
||||
describe('when the projectId does not match (0)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId does not match (0)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(0)
|
||||
})
|
||||
checkNonMatch()
|
||||
})
|
||||
describe('when the projectId does not match (42)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId does not match (42)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(42)
|
||||
})
|
||||
checkNonMatch()
|
||||
})
|
||||
checkForBetaUser()
|
||||
})
|
||||
describe('when the roll out percentage is 1', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the roll out percentage is 1', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.wsUrlV2Percentage = 1
|
||||
})
|
||||
describe('when the projectId matches (0)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId matches (0)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(0)
|
||||
})
|
||||
checkMatch()
|
||||
checkForBetaUser()
|
||||
})
|
||||
describe('when the projectId does not match (1)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId does not match (1)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(1)
|
||||
})
|
||||
checkNonMatch()
|
||||
checkForBetaUser()
|
||||
})
|
||||
describe('when the projectId does not match (42)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId does not match (42)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(42)
|
||||
})
|
||||
checkNonMatch()
|
||||
})
|
||||
})
|
||||
describe('when the roll out percentage is 10', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the roll out percentage is 10', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.wsUrlV2Percentage = 10
|
||||
})
|
||||
describe('when the projectId matches (0)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId matches (0)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(0)
|
||||
})
|
||||
checkMatch()
|
||||
})
|
||||
describe('when the projectId matches (9)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId matches (9)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(9)
|
||||
})
|
||||
checkMatch()
|
||||
checkForBetaUser()
|
||||
})
|
||||
describe('when the projectId does not match (10)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId does not match (10)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(10)
|
||||
})
|
||||
checkNonMatch()
|
||||
})
|
||||
describe('when the projectId does not match (42)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId does not match (42)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(42)
|
||||
})
|
||||
checkNonMatch()
|
||||
checkForBetaUser()
|
||||
})
|
||||
})
|
||||
describe('when the roll out percentage is 100', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the roll out percentage is 100', function () {
|
||||
beforeEach(function () {
|
||||
this.settings.wsUrlV2Percentage = 100
|
||||
})
|
||||
describe('when the projectId matches (0)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId matches (0)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(0)
|
||||
})
|
||||
checkMatch()
|
||||
checkForBetaUser()
|
||||
})
|
||||
describe('when the projectId matches (10)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId matches (10)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(10)
|
||||
})
|
||||
checkMatch()
|
||||
})
|
||||
describe('when the projectId matches (42)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId matches (42)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(42)
|
||||
})
|
||||
checkMatch()
|
||||
})
|
||||
describe('when the projectId matches (99)', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the projectId matches (99)', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params.Project_id = ObjectId.createFromTime(99)
|
||||
})
|
||||
checkMatch()
|
||||
@@ -1264,8 +1264,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('userProjectsJson', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('userProjectsJson', function () {
|
||||
beforeEach(function (done) {
|
||||
const projects = [
|
||||
{
|
||||
archived: true,
|
||||
@@ -1323,7 +1323,7 @@ describe('ProjectController', function() {
|
||||
done()
|
||||
})
|
||||
|
||||
it('should produce a list of projects', function(done) {
|
||||
it('should produce a list of projects', function (done) {
|
||||
this.res.json = data => {
|
||||
expect(data).to.deep.equal({
|
||||
projects: [
|
||||
@@ -1337,8 +1337,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('projectEntitiesJson', function() {
|
||||
beforeEach(function() {
|
||||
describe('projectEntitiesJson', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationController.getLoggedInUserId = sinon
|
||||
.stub()
|
||||
.returns('abc')
|
||||
@@ -1357,7 +1357,7 @@ describe('ProjectController', function() {
|
||||
.callsArgWith(1, null, this.docs, this.files)
|
||||
})
|
||||
|
||||
it('should produce a list of entities', function(done) {
|
||||
it('should produce a list of entities', function (done) {
|
||||
this.res.json = data => {
|
||||
expect(data).to.deep.equal({
|
||||
project_id: 'abcd',
|
||||
@@ -1377,8 +1377,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_buildProjectViewModel', function() {
|
||||
beforeEach(function() {
|
||||
describe('_buildProjectViewModel', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectHelper.isArchived.returns(false)
|
||||
this.ProjectHelper.isTrashed.returns(false)
|
||||
|
||||
@@ -1398,8 +1398,8 @@ describe('ProjectController', function() {
|
||||
}
|
||||
})
|
||||
|
||||
describe('project not being archived or trashed', function() {
|
||||
it('should produce a model of the project', function() {
|
||||
describe('project not being archived or trashed', function () {
|
||||
it('should produce a model of the project', function () {
|
||||
const result = this.ProjectController._buildProjectViewModel(
|
||||
this.project,
|
||||
'readAndWrite',
|
||||
@@ -1424,13 +1424,13 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('project being simultaneously archived and trashed', function() {
|
||||
beforeEach(function() {
|
||||
describe('project being simultaneously archived and trashed', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectHelper.isArchived.returns(true)
|
||||
this.ProjectHelper.isTrashed.returns(true)
|
||||
})
|
||||
|
||||
it('should produce a model of the project', function() {
|
||||
it('should produce a model of the project', function () {
|
||||
const result = this.ProjectController._buildProjectViewModel(
|
||||
this.project,
|
||||
'readAndWrite',
|
||||
@@ -1455,8 +1455,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when token-read-only access', function() {
|
||||
it('should redact the owner and last-updated data', function() {
|
||||
describe('when token-read-only access', function () {
|
||||
it('should redact the owner and last-updated data', function () {
|
||||
const result = this.ProjectController._buildProjectViewModel(
|
||||
this.project,
|
||||
'readOnly',
|
||||
@@ -1481,8 +1481,8 @@ describe('ProjectController', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('_isInPercentageRollout', function() {
|
||||
before(function() {
|
||||
describe('_isInPercentageRollout', function () {
|
||||
before(function () {
|
||||
this.ids = [
|
||||
'5a05cd7621f9fe22be131740',
|
||||
'5a05cd7821f9fe22be131741',
|
||||
@@ -1507,7 +1507,7 @@ describe('ProjectController', function() {
|
||||
]
|
||||
})
|
||||
|
||||
it('should produce the expected results', function() {
|
||||
it('should produce the expected results', function () {
|
||||
expect(
|
||||
this.ids.map(i =>
|
||||
this.ProjectController._isInPercentageRollout('abcd', i, 50)
|
||||
|
||||
@@ -6,14 +6,14 @@ const SandboxedModule = require('sandboxed-module')
|
||||
const Path = require('path')
|
||||
const { ObjectId } = require('mongodb')
|
||||
|
||||
describe('ProjectCreationHandler', function() {
|
||||
describe('ProjectCreationHandler', function () {
|
||||
const ownerId = '4eecb1c1bffa66588e0000a1'
|
||||
const projectName = 'project name goes here'
|
||||
const projectId = '4eecaffcbffa66588e000008'
|
||||
const docId = '4eecb17ebffa66588e00003f'
|
||||
const rootFolderId = '234adfa3r2afe'
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel = class Project {
|
||||
constructor(options) {
|
||||
if (options == null) {
|
||||
@@ -81,8 +81,8 @@ describe('ProjectCreationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Creating a Blank project', function() {
|
||||
beforeEach(function() {
|
||||
describe('Creating a Blank project', function () {
|
||||
beforeEach(function () {
|
||||
this.overleafId = 1234
|
||||
this.HistoryManager.initializeProject = sinon
|
||||
.stub()
|
||||
@@ -90,15 +90,15 @@ describe('ProjectCreationHandler', function() {
|
||||
this.ProjectModel.prototype.save = sinon.stub().callsArg(0)
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
it('should save the project', function(done) {
|
||||
describe('successfully', function () {
|
||||
it('should save the project', function (done) {
|
||||
this.handler.createBlankProject(ownerId, projectName, () => {
|
||||
this.ProjectModel.prototype.save.called.should.equal(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return the project in the callback', function(done) {
|
||||
it('should return the project in the callback', function (done) {
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
@@ -114,12 +114,12 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should initialize the project overleaf if history id not provided', function(done) {
|
||||
it('should initialize the project overleaf if history id not provided', function (done) {
|
||||
this.handler.createBlankProject(ownerId, projectName, done)
|
||||
this.HistoryManager.initializeProject.calledWith().should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the overleaf id if overleaf id not provided', function(done) {
|
||||
it('should set the overleaf id if overleaf id not provided', function (done) {
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
@@ -133,7 +133,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the overleaf id if overleaf id provided', function(done) {
|
||||
it('should set the overleaf id if overleaf id provided', function (done) {
|
||||
const overleafId = 2345
|
||||
const attributes = {
|
||||
overleaf: {
|
||||
@@ -156,7 +156,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the language from the user', function(done) {
|
||||
it('should set the language from the user', function (done) {
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
@@ -170,7 +170,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the imageName to currentImageName if set and no imageName attribute', function(done) {
|
||||
it('should set the imageName to currentImageName if set and no imageName attribute', function (done) {
|
||||
this.Settings.currentImageName = 'mock-image-name'
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
@@ -185,7 +185,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the imageName if no currentImageName', function(done) {
|
||||
it('should not set the imageName if no currentImageName', function (done) {
|
||||
this.Settings.currentImageName = null
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
@@ -200,7 +200,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the imageName to the attribute value if set and not overwrite it with the currentImageName', function(done) {
|
||||
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' }
|
||||
this.handler.createBlankProject(
|
||||
@@ -217,7 +217,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the overleaf.history.display if not configured in settings', function(done) {
|
||||
it('should not set the overleaf.history.display if not configured in settings', function (done) {
|
||||
this.Settings.apis.project_history.displayHistoryForNewProjects = false
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
@@ -232,7 +232,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the overleaf.history.display if configured in settings', function(done) {
|
||||
it('should set the overleaf.history.display if configured in settings', function (done) {
|
||||
this.Settings.apis.project_history.displayHistoryForNewProjects = true
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
@@ -247,7 +247,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a project-created event to analytics', function(done) {
|
||||
it('should send a project-created event to analytics', function (done) {
|
||||
this.handler.createBlankProject(
|
||||
ownerId,
|
||||
projectName,
|
||||
@@ -267,7 +267,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a project-created event with template information if provided', function(done) {
|
||||
it('should send a project-created event with template information if provided', function (done) {
|
||||
const attributes = {
|
||||
fromV1TemplateId: 100
|
||||
}
|
||||
@@ -292,7 +292,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a project-imported event when importing a project', function(done) {
|
||||
it('should send a project-imported event when importing a project', function (done) {
|
||||
const attributes = {
|
||||
overleaf: {
|
||||
history: {
|
||||
@@ -321,41 +321,41 @@ describe('ProjectCreationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('with an error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModel.prototype.save = sinon
|
||||
.stub()
|
||||
.callsArgWith(0, new Error('something went wrong'))
|
||||
this.handler.createBlankProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should return the error to the callback', function() {
|
||||
it('should return the error to the callback', function () {
|
||||
expect(this.callback.args[0][0]).to.exist
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an invalid name', function() {
|
||||
beforeEach(function() {
|
||||
describe('with an invalid name', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectDetailsHandler.validateProjectName = sinon
|
||||
.stub()
|
||||
.yields(new Error('bad name'))
|
||||
this.handler.createBlankProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should return the error to the callback', function() {
|
||||
it('should return the error to the callback', function () {
|
||||
expect(this.callback.args[0][0]).to.exist
|
||||
})
|
||||
|
||||
it('should not try to create the project', function() {
|
||||
it('should not try to create the project', function () {
|
||||
this.ProjectModel.prototype.save.called.should.equal(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Creating a basic project', function() {
|
||||
beforeEach(function() {
|
||||
describe('Creating a basic project', function () {
|
||||
beforeEach(function () {
|
||||
this.project = new this.ProjectModel()
|
||||
this.handler._buildTemplate = function(
|
||||
this.handler._buildTemplate = function (
|
||||
templateName,
|
||||
user,
|
||||
projectName,
|
||||
@@ -376,27 +376,27 @@ describe('ProjectCreationHandler', function() {
|
||||
this.handler.createBasicProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should create a blank project first', function() {
|
||||
it('should create a blank project first', function () {
|
||||
this.handler.createBlankProject
|
||||
.calledWith(ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should create the root document', function() {
|
||||
it('should create the root document', function () {
|
||||
this.handler._createRootDoc
|
||||
.calledWith(this.project, ownerId, ['mainbasic.tex', 'lines'])
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should build the mainbasic.tex template', function() {
|
||||
it('should build the mainbasic.tex template', function () {
|
||||
this.handler._buildTemplate
|
||||
.calledWith('mainbasic.tex', ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Creating a project from a snippet', function() {
|
||||
beforeEach(function() {
|
||||
describe('Creating a project from a snippet', function () {
|
||||
beforeEach(function () {
|
||||
this.project = new this.ProjectModel()
|
||||
this.handler.createBlankProject = sinon
|
||||
.stub()
|
||||
@@ -412,23 +412,23 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should create a blank project first', function() {
|
||||
it('should create a blank project first', function () {
|
||||
this.handler.createBlankProject
|
||||
.calledWith(ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should create the root document', function() {
|
||||
it('should create the root document', function () {
|
||||
this.handler._createRootDoc
|
||||
.calledWith(this.project, ownerId, ['snippet line 1', 'snippet line 2'])
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Creating an example project', function() {
|
||||
beforeEach(function() {
|
||||
describe('Creating an example project', function () {
|
||||
beforeEach(function () {
|
||||
this.project = new this.ProjectModel()
|
||||
this.handler._buildTemplate = function(
|
||||
this.handler._buildTemplate = function (
|
||||
templateName,
|
||||
user,
|
||||
projectName,
|
||||
@@ -452,19 +452,19 @@ describe('ProjectCreationHandler', function() {
|
||||
this.handler.createExampleProject(ownerId, projectName, this.callback)
|
||||
})
|
||||
|
||||
it('should create a blank project first', function() {
|
||||
it('should create a blank project first', function () {
|
||||
this.handler.createBlankProject
|
||||
.calledWith(ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should create the root document', function() {
|
||||
it('should create the root document', function () {
|
||||
this.handler._createRootDoc
|
||||
.calledWith(this.project, ownerId, ['main.tex', 'lines'])
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should insert references.bib', function() {
|
||||
it('should insert references.bib', function () {
|
||||
this.ProjectEntityUpdateHandler.addDoc
|
||||
.calledWith(
|
||||
projectId,
|
||||
@@ -476,7 +476,7 @@ describe('ProjectCreationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should insert universe.jpg', function() {
|
||||
it('should insert universe.jpg', function () {
|
||||
this.ProjectEntityUpdateHandler.addFile
|
||||
.calledWith(
|
||||
projectId,
|
||||
@@ -494,21 +494,21 @@ describe('ProjectCreationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should build the main.tex template', function() {
|
||||
it('should build the main.tex template', function () {
|
||||
this.handler._buildTemplate
|
||||
.calledWith('main.tex', ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should build the references.bib template', function() {
|
||||
it('should build the references.bib template', function () {
|
||||
this.handler._buildTemplate
|
||||
.calledWith('references.bib', ownerId, projectName)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('_buildTemplate', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('_buildTemplate', function () {
|
||||
beforeEach(function (done) {
|
||||
this.handler._buildTemplate(
|
||||
'main.tex',
|
||||
this.user_id,
|
||||
@@ -525,36 +525,36 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should insert the project name into the template', function(done) {
|
||||
it('should insert the project name into the template', function (done) {
|
||||
this.template.indexOf(projectName).should.not.equal(-1)
|
||||
done()
|
||||
})
|
||||
|
||||
it('should insert the users name into the template', function(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)
|
||||
done()
|
||||
})
|
||||
|
||||
it('should not have undefined in the template', function(done) {
|
||||
it('should not have undefined in the template', function (done) {
|
||||
this.template.indexOf('undefined').should.equal(-1)
|
||||
done()
|
||||
})
|
||||
|
||||
it('should not have any underscore brackets in the output', function(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)
|
||||
done()
|
||||
})
|
||||
|
||||
it('should put the year in', function(done) {
|
||||
it('should put the year in', function (done) {
|
||||
this.template.indexOf(new Date().getUTCFullYear()).should.not.equal(-1)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('_createRootDoc', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('_createRootDoc', function () {
|
||||
beforeEach(function (done) {
|
||||
this.project = new this.ProjectModel()
|
||||
|
||||
this.handler._createRootDoc(
|
||||
@@ -565,7 +565,7 @@ describe('ProjectCreationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should insert main.tex', function() {
|
||||
it('should insert main.tex', function () {
|
||||
this.ProjectEntityUpdateHandler.addDoc
|
||||
.calledWith(
|
||||
projectId,
|
||||
@@ -577,7 +577,7 @@ describe('ProjectCreationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the main doc id', function() {
|
||||
it('should set the main doc id', function () {
|
||||
this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(projectId, docId)
|
||||
.should.equal(true)
|
||||
|
||||
@@ -9,8 +9,8 @@ const { DeletedProject } = require('../helpers/models/DeletedProject')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
|
||||
describe('ProjectDeleter', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectDeleter', function () {
|
||||
beforeEach(function () {
|
||||
tk.freeze(Date.now())
|
||||
this.ip = '192.170.18.1'
|
||||
this.project = dummyProject()
|
||||
@@ -32,9 +32,7 @@ describe('ProjectDeleter', function() {
|
||||
_id: '5cf7f145c1401f0ca0eb1aaa',
|
||||
deleterData: {
|
||||
_id: '5cf7f145c1401f0ca0eb1aac',
|
||||
deletedAt: moment()
|
||||
.subtract(95, 'days')
|
||||
.toDate(),
|
||||
deletedAt: moment().subtract(95, 'days').toDate(),
|
||||
deleterId: '588f3ddae8ebc1bac07c9fa4',
|
||||
deleterIpAddress: '172.19.0.1',
|
||||
deletedProjectId: '5cf9270b4eff6e186cf8b05e'
|
||||
@@ -52,9 +50,7 @@ describe('ProjectDeleter', function() {
|
||||
_id: '5cf8eb11c1401f0ca0eb1ad7',
|
||||
deleterData: {
|
||||
_id: '5b74360c0fbe57011ae9938f',
|
||||
deletedAt: moment()
|
||||
.subtract(95, 'days')
|
||||
.toDate(),
|
||||
deletedAt: moment().subtract(95, 'days').toDate(),
|
||||
deleterId: '588f3ddae8ebc1bac07c9fa4',
|
||||
deleterIpAddress: '172.20.0.1',
|
||||
deletedProjectId: '5cf8f95a0c87371362c23919'
|
||||
@@ -152,14 +148,14 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
tk.reset()
|
||||
this.DeletedProjectMock.restore()
|
||||
this.ProjectMock.restore()
|
||||
})
|
||||
|
||||
describe('mark as deleted by external source', function() {
|
||||
beforeEach(function() {
|
||||
describe('mark as deleted by external source', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectMock.expects('updateOne')
|
||||
.withArgs(
|
||||
{ _id: this.project._id },
|
||||
@@ -169,14 +165,14 @@ describe('ProjectDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should update the project with the flag set to true', async function() {
|
||||
it('should update the project with the flag set to true', async function () {
|
||||
await this.ProjectDeleter.promises.markAsDeletedByExternalSource(
|
||||
this.project._id
|
||||
)
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should tell the editor controler so users are notified', async function() {
|
||||
it('should tell the editor controler so users are notified', async function () {
|
||||
await this.ProjectDeleter.promises.markAsDeletedByExternalSource(
|
||||
this.project._id
|
||||
)
|
||||
@@ -187,8 +183,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('unmarkAsDeletedByExternalSource', function() {
|
||||
beforeEach(async function() {
|
||||
describe('unmarkAsDeletedByExternalSource', function () {
|
||||
beforeEach(async function () {
|
||||
this.ProjectMock.expects('updateOne')
|
||||
.withArgs(
|
||||
{ _id: this.project._id },
|
||||
@@ -201,13 +197,13 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should remove the flag from the project', function() {
|
||||
it('should remove the flag from the project', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteUsersProjects', function() {
|
||||
beforeEach(function() {
|
||||
describe('deleteUsersProjects', function () {
|
||||
beforeEach(function () {
|
||||
this.projects = [dummyProject(), dummyProject()]
|
||||
this.ProjectMock.expects('find')
|
||||
.withArgs({ owner_ref: this.user._id })
|
||||
@@ -235,13 +231,13 @@ describe('ProjectDeleter', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('should delete all projects owned by the user', async function() {
|
||||
it('should delete all projects owned by the user', async function () {
|
||||
await this.ProjectDeleter.promises.deleteUsersProjects(this.user._id)
|
||||
this.ProjectMock.verify()
|
||||
this.DeletedProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should remove any collaboration from this user', async function() {
|
||||
it('should remove any collaboration from this user', async function () {
|
||||
await this.ProjectDeleter.promises.deleteUsersProjects(this.user._id)
|
||||
sinon.assert.calledWith(
|
||||
this.CollaboratorsHandler.promises.removeUserFromAllProjects,
|
||||
@@ -253,8 +249,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('deleteProject', function () {
|
||||
beforeEach(function () {
|
||||
this.deleterData = {
|
||||
deletedAt: new Date(),
|
||||
deletedProjectId: this.project._id,
|
||||
@@ -278,13 +274,11 @@ describe('ProjectDeleter', function() {
|
||||
.resolves(this.project)
|
||||
})
|
||||
|
||||
it('should save a DeletedProject with additional deleterData', async function() {
|
||||
it('should save a DeletedProject with additional deleterData', async function () {
|
||||
this.deleterData.deleterIpAddress = this.ip
|
||||
this.deleterData.deleterId = this.user._id
|
||||
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
this.ProjectMock.expects('deleteOne').chain('exec').resolves()
|
||||
this.DeletedProjectMock.expects('updateOne')
|
||||
.withArgs(
|
||||
{ 'deleterData.deletedProjectId': this.project._id },
|
||||
@@ -303,10 +297,8 @@ describe('ProjectDeleter', function() {
|
||||
this.DeletedProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should flushProjectToMongoAndDelete in doc updater', async function() {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
it('should flushProjectToMongoAndDelete in doc updater', async function () {
|
||||
this.ProjectMock.expects('deleteOne').chain('exec').resolves()
|
||||
this.DeletedProjectMock.expects('updateOne').resolves()
|
||||
|
||||
await this.ProjectDeleter.promises.deleteProject(this.project._id, {
|
||||
@@ -318,10 +310,8 @@ describe('ProjectDeleter', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should flush docs out of mongo', async function() {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
it('should flush docs out of mongo', async function () {
|
||||
this.ProjectMock.expects('deleteOne').chain('exec').resolves()
|
||||
this.DeletedProjectMock.expects('updateOne').resolves()
|
||||
await this.ProjectDeleter.promises.deleteProject(this.project._id, {
|
||||
deleterUser: this.user,
|
||||
@@ -332,10 +322,8 @@ describe('ProjectDeleter', function() {
|
||||
).to.have.been.calledWith(this.project._id)
|
||||
})
|
||||
|
||||
it('should flush docs out of mongo and ignore errors', async function() {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
it('should flush docs out of mongo and ignore errors', async function () {
|
||||
this.ProjectMock.expects('deleteOne').chain('exec').resolves()
|
||||
this.DeletedProjectMock.expects('updateOne').resolves()
|
||||
this.DocstoreManager.promises.archiveProject.rejects(new Error('foo'))
|
||||
await this.ProjectDeleter.promises.deleteProject(this.project._id, {
|
||||
@@ -344,10 +332,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should removeProjectFromAllTags', async function() {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
it('should removeProjectFromAllTags', async function () {
|
||||
this.ProjectMock.expects('deleteOne').chain('exec').resolves()
|
||||
this.DeletedProjectMock.expects('updateOne').resolves()
|
||||
|
||||
await this.ProjectDeleter.promises.deleteProject(this.project._id)
|
||||
@@ -363,7 +349,7 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should remove the project from Mongo', async function() {
|
||||
it('should remove the project from Mongo', async function () {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.withArgs({ _id: this.project._id })
|
||||
.chain('exec')
|
||||
@@ -375,8 +361,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('expireDeletedProjectsAfterDuration', function() {
|
||||
beforeEach(async function() {
|
||||
describe('expireDeletedProjectsAfterDuration', function () {
|
||||
beforeEach(async function () {
|
||||
this.DeletedProjectMock.expects('find')
|
||||
.withArgs({
|
||||
'deleterData.deletedAt': {
|
||||
@@ -415,13 +401,13 @@ describe('ProjectDeleter', function() {
|
||||
await this.ProjectDeleter.promises.expireDeletedProjectsAfterDuration()
|
||||
})
|
||||
|
||||
it('should expire projects older than 90 days', function() {
|
||||
it('should expire projects older than 90 days', function () {
|
||||
this.DeletedProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('expireDeletedProject', function() {
|
||||
beforeEach(async function() {
|
||||
describe('expireDeletedProject', function () {
|
||||
beforeEach(async function () {
|
||||
this.DeletedProjectMock.expects('updateOne')
|
||||
.withArgs(
|
||||
{
|
||||
@@ -449,17 +435,17 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should find the specified deletedProject and remove its project and ip address', function() {
|
||||
it('should find the specified deletedProject and remove its project and ip address', function () {
|
||||
this.DeletedProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should destroy the docs in docstore', function() {
|
||||
it('should destroy the docs in docstore', function () {
|
||||
expect(
|
||||
this.DocstoreManager.promises.destroyProject
|
||||
).to.have.been.calledWith(this.deletedProjects[0].project._id)
|
||||
})
|
||||
|
||||
it('should delete the project in history', function() {
|
||||
it('should delete the project in history', function () {
|
||||
expect(
|
||||
this.HistoryManager.promises.deleteProject
|
||||
).to.have.been.calledWith(
|
||||
@@ -468,15 +454,15 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should destroy the files in filestore', function() {
|
||||
it('should destroy the files in filestore', function () {
|
||||
expect(
|
||||
this.FileStoreHandler.promises.deleteProject
|
||||
).to.have.been.calledWith(this.deletedProjects[0].project._id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('archiveProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('archiveProject', function () {
|
||||
beforeEach(function () {
|
||||
let archived = [ObjectId(this.user._id)]
|
||||
this.ProjectHelper.calculateArchivedArray.returns(archived)
|
||||
|
||||
@@ -496,7 +482,7 @@ describe('ProjectDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should update the project', async function() {
|
||||
it('should update the project', async function () {
|
||||
await this.ProjectDeleter.promises.archiveProject(
|
||||
this.project._id,
|
||||
this.user._id
|
||||
@@ -504,7 +490,7 @@ describe('ProjectDeleter', function() {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('calculates the archived array', async function() {
|
||||
it('calculates the archived array', async function () {
|
||||
await this.ProjectDeleter.promises.archiveProject(
|
||||
this.project._id,
|
||||
this.user._id
|
||||
@@ -517,8 +503,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('unarchiveProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('unarchiveProject', function () {
|
||||
beforeEach(function () {
|
||||
let archived = [ObjectId(this.user._id)]
|
||||
this.ProjectHelper.calculateArchivedArray.returns(archived)
|
||||
|
||||
@@ -532,7 +518,7 @@ describe('ProjectDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should update the project', async function() {
|
||||
it('should update the project', async function () {
|
||||
await this.ProjectDeleter.promises.unarchiveProject(
|
||||
this.project._id,
|
||||
this.user._id
|
||||
@@ -540,7 +526,7 @@ describe('ProjectDeleter', function() {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('calculates the archived array', async function() {
|
||||
it('calculates the archived array', async function () {
|
||||
await this.ProjectDeleter.promises.unarchiveProject(
|
||||
this.project._id,
|
||||
this.user._id
|
||||
@@ -553,8 +539,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('trashProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('trashProject', function () {
|
||||
beforeEach(function () {
|
||||
let archived = [ObjectId(this.user._id)]
|
||||
this.ProjectHelper.calculateArchivedArray.returns(archived)
|
||||
|
||||
@@ -574,7 +560,7 @@ describe('ProjectDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should update the project', async function() {
|
||||
it('should update the project', async function () {
|
||||
await this.ProjectDeleter.promises.trashProject(
|
||||
this.project._id,
|
||||
this.user._id
|
||||
@@ -582,7 +568,7 @@ describe('ProjectDeleter', function() {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('unarchives the project', async function() {
|
||||
it('unarchives the project', async function () {
|
||||
await this.ProjectDeleter.promises.trashProject(
|
||||
this.project._id,
|
||||
this.user._id
|
||||
@@ -595,8 +581,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('untrashProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('untrashProject', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectMock.expects('findOne')
|
||||
.withArgs({ _id: this.project._id })
|
||||
.chain('exec')
|
||||
@@ -610,7 +596,7 @@ describe('ProjectDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should update the project', async function() {
|
||||
it('should update the project', async function () {
|
||||
await this.ProjectDeleter.promises.untrashProject(
|
||||
this.project._id,
|
||||
this.user._id
|
||||
@@ -619,8 +605,8 @@ describe('ProjectDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('restoreProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('restoreProject', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectMock.expects('updateOne')
|
||||
.withArgs(
|
||||
{
|
||||
@@ -634,13 +620,13 @@ describe('ProjectDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should unset the archive attribute', async function() {
|
||||
it('should unset the archive attribute', async function () {
|
||||
await this.ProjectDeleter.promises.restoreProject(this.project._id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('undeleteProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('undeleteProject', function () {
|
||||
beforeEach(function () {
|
||||
this.deletedProject = {
|
||||
_id: 'deleted',
|
||||
project: this.project,
|
||||
@@ -669,24 +655,22 @@ describe('ProjectDeleter', function() {
|
||||
.withArgs({ 'deleterData.deletedProjectId': 'wombat' })
|
||||
.chain('exec')
|
||||
.resolves(null)
|
||||
this.DeletedProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
this.DeletedProjectMock.expects('deleteOne').chain('exec').resolves()
|
||||
})
|
||||
|
||||
it('should return not found if the project does not exist', async function() {
|
||||
it('should return not found if the project does not exist', async function () {
|
||||
await expect(
|
||||
this.ProjectDeleter.promises.undeleteProject('wombat')
|
||||
).to.be.rejectedWith(Errors.NotFoundError, 'project_not_found')
|
||||
})
|
||||
|
||||
it('should return not found if the project has been expired', async function() {
|
||||
it('should return not found if the project has been expired', async function () {
|
||||
await expect(
|
||||
this.ProjectDeleter.promises.undeleteProject('purgedProject')
|
||||
).to.be.rejectedWith(Errors.NotFoundError, 'project_too_old_to_restore')
|
||||
})
|
||||
|
||||
it('should insert the project into the collection', async function() {
|
||||
it('should insert the project into the collection', async function () {
|
||||
await this.ProjectDeleter.promises.undeleteProject(this.project._id)
|
||||
sinon.assert.calledWith(
|
||||
this.db.projects.insertOne,
|
||||
@@ -697,7 +681,7 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should clear the archive bit', async function() {
|
||||
it('should clear the archive bit', async function () {
|
||||
this.project.archived = true
|
||||
await this.ProjectDeleter.promises.undeleteProject(this.project._id)
|
||||
sinon.assert.calledWith(
|
||||
@@ -706,7 +690,7 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should generate a unique name for the project', async function() {
|
||||
it('should generate a unique name for the project', async function () {
|
||||
await this.ProjectDeleter.promises.undeleteProject(this.project._id)
|
||||
sinon.assert.calledWith(
|
||||
this.ProjectDetailsHandler.promises.generateUniqueName,
|
||||
@@ -714,7 +698,7 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should add a suffix to the project name', async function() {
|
||||
it('should add a suffix to the project name', async function () {
|
||||
await this.ProjectDeleter.promises.undeleteProject(this.project._id)
|
||||
sinon.assert.calledWith(
|
||||
this.ProjectDetailsHandler.promises.generateUniqueName,
|
||||
@@ -723,7 +707,7 @@ describe('ProjectDeleter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should remove the DeletedProject', async function() {
|
||||
it('should remove the DeletedProject', async function () {
|
||||
// need to change the mock just to include the methods we want
|
||||
this.DeletedProjectMock.restore()
|
||||
this.DeletedProjectMock = sinon.mock(DeletedProject)
|
||||
|
||||
@@ -7,8 +7,8 @@ const ProjectHelper = require('../../../../app/src/Features/Project/ProjectHelpe
|
||||
|
||||
const MODULE_PATH = '../../../../app/src/Features/Project/ProjectDetailsHandler'
|
||||
|
||||
describe('ProjectDetailsHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectDetailsHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
_id: ObjectId(),
|
||||
email: 'user@example.com',
|
||||
@@ -80,8 +80,8 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getDetails', function() {
|
||||
it('should find the project and owner', async function() {
|
||||
describe('getDetails', function () {
|
||||
it('should find the project and owner', async function () {
|
||||
const details = await this.handler.promises.getDetails(this.project._id)
|
||||
details.name.should.equal(this.project.name)
|
||||
details.description.should.equal(this.project.description)
|
||||
@@ -90,35 +90,35 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(details.something).to.be.undefined
|
||||
})
|
||||
|
||||
it('should find overleaf metadata if it exists', async function() {
|
||||
it('should find overleaf metadata if it exists', async function () {
|
||||
this.project.overleaf = { id: 'id' }
|
||||
const details = await this.handler.promises.getDetails(this.project._id)
|
||||
details.overleaf.should.equal(this.project.overleaf)
|
||||
expect(details.something).to.be.undefined
|
||||
})
|
||||
|
||||
it('should return an error for a non-existent project', async function() {
|
||||
it('should return an error for a non-existent project', async function () {
|
||||
this.ProjectGetter.promises.getProject.resolves(null)
|
||||
await expect(
|
||||
this.handler.promises.getDetails('0123456789012345678901234')
|
||||
).to.be.rejectedWith(Errors.NotFoundError)
|
||||
})
|
||||
|
||||
it('should return the default features if no owner found', async function() {
|
||||
it('should return the default features if no owner found', async function () {
|
||||
this.UserGetter.promises.getUser.resolves(null)
|
||||
const details = await this.handler.promises.getDetails(this.project._id)
|
||||
details.features.should.equal(this.settings.defaultFeatures)
|
||||
})
|
||||
|
||||
it('should rethrow any error', async function() {
|
||||
it('should rethrow any error', async function () {
|
||||
this.ProjectGetter.promises.getProject.rejects(new Error('boom'))
|
||||
await expect(this.handler.promises.getDetails(this.project._id)).to.be
|
||||
.rejected
|
||||
})
|
||||
})
|
||||
|
||||
describe('getProjectDescription', function() {
|
||||
it('should make a call to mongo just for the description', async function() {
|
||||
describe('getProjectDescription', function () {
|
||||
it('should make a call to mongo just for the description', async function () {
|
||||
this.ProjectGetter.promises.getProject.resolves()
|
||||
await this.handler.promises.getProjectDescription(this.project._id)
|
||||
expect(
|
||||
@@ -126,7 +126,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
).to.have.been.calledWith(this.project._id, { description: true })
|
||||
})
|
||||
|
||||
it('should return what the mongo call returns', async function() {
|
||||
it('should return what the mongo call returns', async function () {
|
||||
const expectedDescription = 'cool project'
|
||||
this.ProjectGetter.promises.getProject.resolves({
|
||||
description: expectedDescription
|
||||
@@ -138,12 +138,12 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setProjectDescription', function() {
|
||||
beforeEach(function() {
|
||||
describe('setProjectDescription', function () {
|
||||
beforeEach(function () {
|
||||
this.description = 'updated teh description'
|
||||
})
|
||||
|
||||
it('should update the project detials', async function() {
|
||||
it('should update the project detials', async function () {
|
||||
await this.handler.promises.setProjectDescription(
|
||||
this.project._id,
|
||||
this.description
|
||||
@@ -155,12 +155,12 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('renameProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('renameProject', function () {
|
||||
beforeEach(function () {
|
||||
this.newName = 'new name here'
|
||||
})
|
||||
|
||||
it('should update the project with the new name', async function() {
|
||||
it('should update the project with the new name', async function () {
|
||||
await this.handler.promises.renameProject(this.project._id, this.newName)
|
||||
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
|
||||
{ _id: this.project._id },
|
||||
@@ -168,7 +168,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should tell the TpdsUpdateSender', async function() {
|
||||
it('should tell the TpdsUpdateSender', async function () {
|
||||
await this.handler.promises.renameProject(this.project._id, this.newName)
|
||||
expect(this.TpdsUpdateSender.promises.moveEntity).to.have.been.calledWith(
|
||||
{
|
||||
@@ -179,7 +179,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not do anything with an invalid name', async function() {
|
||||
it('should not do anything with an invalid name', async function () {
|
||||
await expect(this.handler.promises.renameProject(this.project._id)).to.be
|
||||
.rejected
|
||||
expect(this.TpdsUpdateSender.promises.moveEntity).not.to.have.been.called
|
||||
@@ -187,40 +187,40 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('validateProjectName', function() {
|
||||
it('should reject undefined names', async function() {
|
||||
describe('validateProjectName', function () {
|
||||
it('should reject undefined names', async function () {
|
||||
await expect(this.handler.promises.validateProjectName(undefined)).to.be
|
||||
.rejected
|
||||
})
|
||||
|
||||
it('should reject empty names', async function() {
|
||||
it('should reject empty names', async function () {
|
||||
await expect(this.handler.promises.validateProjectName('')).to.be.rejected
|
||||
})
|
||||
|
||||
it('should reject names with /s', async function() {
|
||||
it('should reject names with /s', async function () {
|
||||
await expect(this.handler.promises.validateProjectName('foo/bar')).to.be
|
||||
.rejected
|
||||
})
|
||||
|
||||
it('should reject names with \\s', async function() {
|
||||
it('should reject names with \\s', async function () {
|
||||
await expect(this.handler.promises.validateProjectName('foo\\bar')).to.be
|
||||
.rejected
|
||||
})
|
||||
|
||||
it('should reject long names', async function() {
|
||||
it('should reject long names', async function () {
|
||||
await expect(this.handler.promises.validateProjectName('a'.repeat(1000)))
|
||||
.to.be.rejected
|
||||
})
|
||||
|
||||
it('should accept normal names', async function() {
|
||||
it('should accept normal names', async function () {
|
||||
await expect(this.handler.promises.validateProjectName('foobar')).to.be
|
||||
.fulfilled
|
||||
})
|
||||
})
|
||||
|
||||
describe('generateUniqueName', function() {
|
||||
describe('generateUniqueName', function () {
|
||||
// actually testing `ProjectHelper.promises.ensureNameIsUnique()`
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.longName = 'x'.repeat(this.handler.MAX_PROJECT_NAME_LENGTH - 5)
|
||||
const usersProjects = {
|
||||
owned: [
|
||||
@@ -281,7 +281,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
this.ProjectGetter.promises.findAllUsersProjects.resolves(usersProjects)
|
||||
})
|
||||
|
||||
it('should leave a unique name unchanged', async function() {
|
||||
it('should leave a unique name unchanged', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'unique-name',
|
||||
@@ -290,7 +290,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(name).to.equal('unique-name')
|
||||
})
|
||||
|
||||
it('should append a suffix to an existing name', async function() {
|
||||
it('should append a suffix to an existing name', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'name1',
|
||||
@@ -299,7 +299,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(name).to.equal('name1-test-suffix')
|
||||
})
|
||||
|
||||
it('should fallback to a second suffix when needed', async function() {
|
||||
it('should fallback to a second suffix when needed', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'name1',
|
||||
@@ -308,7 +308,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(name).to.equal('name1-test-suffix')
|
||||
})
|
||||
|
||||
it('should truncate the name when append a suffix if the result is too long', async function() {
|
||||
it('should truncate the name when append a suffix if the result is too long', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
this.longName,
|
||||
@@ -320,7 +320,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should use a numeric index if no suffix is supplied', async function() {
|
||||
it('should use a numeric index if no suffix is supplied', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'name1',
|
||||
@@ -329,7 +329,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(name).to.equal('name1 (1)')
|
||||
})
|
||||
|
||||
it('should use a numeric index if all suffixes are exhausted', async function() {
|
||||
it('should use a numeric index if all suffixes are exhausted', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'name',
|
||||
@@ -338,7 +338,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(name).to.equal('name (1)')
|
||||
})
|
||||
|
||||
it('should find the next lowest available numeric index for the base name', async function() {
|
||||
it('should find the next lowest available numeric index for the base name', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'numeric',
|
||||
@@ -347,7 +347,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(name).to.equal('numeric (21)')
|
||||
})
|
||||
|
||||
it('should find the next available numeric index when a numeric index is already present', async function() {
|
||||
it('should find the next available numeric index when a numeric index is already present', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'numeric (5)',
|
||||
@@ -356,7 +356,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
expect(name).to.equal('numeric (21)')
|
||||
})
|
||||
|
||||
it('should not find a numeric index lower than the one already present', async function() {
|
||||
it('should not find a numeric index lower than the one already present', async function () {
|
||||
const name = await this.handler.promises.generateUniqueName(
|
||||
this.user._id,
|
||||
'numeric (31)',
|
||||
@@ -366,36 +366,36 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('fixProjectName', function() {
|
||||
it('should change empty names to Untitled', function() {
|
||||
describe('fixProjectName', function () {
|
||||
it('should change empty names to Untitled', function () {
|
||||
expect(this.handler.fixProjectName('')).to.equal('Untitled')
|
||||
})
|
||||
|
||||
it('should replace / with -', function() {
|
||||
it('should replace / with -', function () {
|
||||
expect(this.handler.fixProjectName('foo/bar')).to.equal('foo-bar')
|
||||
})
|
||||
|
||||
it("should replace \\ with ''", function() {
|
||||
it("should replace \\ with ''", function () {
|
||||
expect(this.handler.fixProjectName('foo \\ bar')).to.equal('foo bar')
|
||||
})
|
||||
|
||||
it('should truncate long names', function() {
|
||||
it('should truncate long names', function () {
|
||||
expect(this.handler.fixProjectName('a'.repeat(1000))).to.equal(
|
||||
'a'.repeat(150)
|
||||
)
|
||||
})
|
||||
|
||||
it('should accept normal names', function() {
|
||||
it('should accept normal names', function () {
|
||||
expect(this.handler.fixProjectName('foobar')).to.equal('foobar')
|
||||
})
|
||||
})
|
||||
|
||||
describe('setPublicAccessLevel', function() {
|
||||
beforeEach(function() {
|
||||
describe('setPublicAccessLevel', function () {
|
||||
beforeEach(function () {
|
||||
this.accessLevel = 'readOnly'
|
||||
})
|
||||
|
||||
it('should update the project with the new level', async function() {
|
||||
it('should update the project with the new level', async function () {
|
||||
await this.handler.promises.setPublicAccessLevel(
|
||||
this.project._id,
|
||||
this.accessLevel
|
||||
@@ -406,7 +406,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not produce an error', async function() {
|
||||
it('should not produce an error', async function () {
|
||||
await expect(
|
||||
this.handler.promises.setPublicAccessLevel(
|
||||
this.project._id,
|
||||
@@ -415,12 +415,12 @@ describe('ProjectDetailsHandler', function() {
|
||||
).to.be.fulfilled
|
||||
})
|
||||
|
||||
describe('when update produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when update produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectModelUpdateQuery.exec.rejects(new Error('woops'))
|
||||
})
|
||||
|
||||
it('should produce an error', async function() {
|
||||
it('should produce an error', async function () {
|
||||
await expect(
|
||||
this.handler.promises.setPublicAccessLevel(
|
||||
this.project._id,
|
||||
@@ -431,9 +431,9 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ensureTokensArePresent', function() {
|
||||
describe('when the project has tokens', function() {
|
||||
beforeEach(function() {
|
||||
describe('ensureTokensArePresent', function () {
|
||||
describe('when the project has tokens', function () {
|
||||
beforeEach(function () {
|
||||
this.project = {
|
||||
_id: this.project._id,
|
||||
tokens: {
|
||||
@@ -445,7 +445,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
this.ProjectGetter.promises.getProject.resolves(this.project)
|
||||
})
|
||||
|
||||
it('should get the project', async function() {
|
||||
it('should get the project', async function () {
|
||||
await this.handler.promises.ensureTokensArePresent(this.project._id)
|
||||
expect(this.ProjectGetter.promises.getProject).to.have.been.calledOnce
|
||||
expect(this.ProjectGetter.promises.getProject).to.have.been.calledWith(
|
||||
@@ -456,12 +456,12 @@ describe('ProjectDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not update the project with new tokens', async function() {
|
||||
it('should not update the project with new tokens', async function () {
|
||||
await this.handler.promises.ensureTokensArePresent(this.project._id)
|
||||
expect(this.ProjectModel.updateOne).not.to.have.been.called
|
||||
})
|
||||
|
||||
it('should produce the tokens without error', async function() {
|
||||
it('should produce the tokens without error', async function () {
|
||||
const tokens = await this.handler.promises.ensureTokensArePresent(
|
||||
this.project._id
|
||||
)
|
||||
@@ -469,8 +469,8 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when tokens are missing', function() {
|
||||
beforeEach(function() {
|
||||
describe('when tokens are missing', function () {
|
||||
beforeEach(function () {
|
||||
this.project = { _id: this.project._id }
|
||||
this.ProjectGetter.promises.getProject.resolves(this.project)
|
||||
this.readOnlyToken = 'abc'
|
||||
@@ -485,7 +485,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should get the project', async function() {
|
||||
it('should get the project', async function () {
|
||||
await this.handler.promises.ensureTokensArePresent(this.project._id)
|
||||
expect(this.ProjectGetter.promises.getProject).to.have.been.calledOnce
|
||||
expect(this.ProjectGetter.promises.getProject).to.have.been.calledWith(
|
||||
@@ -496,7 +496,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the project with new tokens', async function() {
|
||||
it('should update the project with new tokens', async function () {
|
||||
await this.handler.promises.ensureTokensArePresent(this.project._id)
|
||||
expect(this.TokenGenerator.promises.generateUniqueReadOnlyToken).to.have
|
||||
.been.calledOnce
|
||||
@@ -516,7 +516,7 @@ describe('ProjectDetailsHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should produce the tokens without error', async function() {
|
||||
it('should produce the tokens without error', async function () {
|
||||
const tokens = await this.handler.promises.ensureTokensArePresent(
|
||||
this.project._id
|
||||
)
|
||||
@@ -529,8 +529,8 @@ describe('ProjectDetailsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('clearTokens', function() {
|
||||
it('clears the tokens from the project', async function() {
|
||||
describe('clearTokens', function () {
|
||||
it('clears the tokens from the project', async function () {
|
||||
await this.handler.promises.clearTokens(this.project._id)
|
||||
expect(this.ProjectModel.updateOne).to.have.been.calledWith(
|
||||
{ _id: this.project._id },
|
||||
|
||||
@@ -5,8 +5,8 @@ const { ObjectId } = require('mongodb')
|
||||
|
||||
const MODULE_PATH = '../../../../app/src/Features/Project/ProjectDuplicator.js'
|
||||
|
||||
describe('ProjectDuplicator', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectDuplicator', function () {
|
||||
beforeEach(function () {
|
||||
this.doc0 = { _id: 'doc0_id', name: 'rootDocHere' }
|
||||
this.doc1 = { _id: 'doc1_id', name: 'level1folderDocName' }
|
||||
this.doc2 = { _id: 'doc2_id', name: 'level2folderDocName' }
|
||||
@@ -220,8 +220,8 @@ describe('ProjectDuplicator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the copy succeeds', function() {
|
||||
beforeEach(async function() {
|
||||
describe('when the copy succeeds', function () {
|
||||
beforeEach(async function () {
|
||||
this.newProjectName = 'New project name'
|
||||
this.newProject = await this.ProjectDuplicator.promises.duplicate(
|
||||
this.owner,
|
||||
@@ -230,13 +230,13 @@ describe('ProjectDuplicator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should flush the original project to mongo', function() {
|
||||
it('should flush the original project to mongo', function () {
|
||||
this.DocumentUpdaterHandler.promises.flushProjectToMongo.should.have.been.calledWith(
|
||||
this.project._id
|
||||
)
|
||||
})
|
||||
|
||||
it('should copy docs to docstore', function() {
|
||||
it('should copy docs to docstore', function () {
|
||||
for (const docLines of [this.doc0Lines, this.doc1Lines, this.doc2Lines]) {
|
||||
this.DocstoreManager.promises.updateDoc.should.have.been.calledWith(
|
||||
this.newProject._id.toString(),
|
||||
@@ -248,7 +248,7 @@ describe('ProjectDuplicator', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('should copy files to the filestore', function() {
|
||||
it('should copy files to the filestore', function () {
|
||||
for (const file of [this.file0, this.file1, this.file2]) {
|
||||
this.FileStoreHandler.promises.copyFile.should.have.been.calledWith(
|
||||
this.project._id,
|
||||
@@ -259,7 +259,7 @@ describe('ProjectDuplicator', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('should create a blank project', function() {
|
||||
it('should create a blank project', function () {
|
||||
this.ProjectCreationHandler.promises.createBlankProject.should.have.been.calledWith(
|
||||
this.owner._id,
|
||||
this.newProjectName
|
||||
@@ -267,26 +267,26 @@ describe('ProjectDuplicator', function() {
|
||||
this.newProject._id.should.equal(this.newBlankProject._id)
|
||||
})
|
||||
|
||||
it('should use the same compiler', function() {
|
||||
it('should use the same compiler', function () {
|
||||
this.ProjectOptionsHandler.promises.setCompiler.should.have.been.calledWith(
|
||||
this.newProject._id,
|
||||
this.project.compiler
|
||||
)
|
||||
})
|
||||
|
||||
it('should use the same root doc', function() {
|
||||
it('should use the same root doc', function () {
|
||||
this.ProjectEntityUpdateHandler.promises.setRootDoc.should.have.been.calledWith(
|
||||
this.newProject._id,
|
||||
this.rootFolder.docs[0]._id
|
||||
)
|
||||
})
|
||||
|
||||
it('should not copy the collaborators or read only refs', function() {
|
||||
it('should not copy the collaborators or read only refs', function () {
|
||||
this.newProject.collaberator_refs.length.should.equal(0)
|
||||
this.newProject.readOnly_refs.length.should.equal(0)
|
||||
})
|
||||
|
||||
it('should copy all documents and files', function() {
|
||||
it('should copy all documents and files', function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.createNewFolderStructure.should.have.been.calledWith(
|
||||
this.newProject._id,
|
||||
this.docEntries,
|
||||
@@ -294,7 +294,7 @@ describe('ProjectDuplicator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should notify document updater of changes', function() {
|
||||
it('should notify document updater of changes', function () {
|
||||
this.DocumentUpdaterHandler.promises.updateProjectStructure.should.have.been.calledWith(
|
||||
this.newProject._id,
|
||||
this.newProject.overleaf.history.id,
|
||||
@@ -307,15 +307,15 @@ describe('ProjectDuplicator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should flush the project to TPDS', function() {
|
||||
it('should flush the project to TPDS', function () {
|
||||
this.TpdsProjectFlusher.promises.flushProjectToTpds.should.have.been.calledWith(
|
||||
this.newProject._id
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('without a root doc', function() {
|
||||
beforeEach(async function() {
|
||||
describe('without a root doc', function () {
|
||||
beforeEach(async function () {
|
||||
this.ProjectLocator.promises.findRootDoc.resolves({
|
||||
element: null,
|
||||
path: null
|
||||
@@ -327,14 +327,14 @@ describe('ProjectDuplicator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the root doc on the copy', function() {
|
||||
it('should not set the root doc on the copy', function () {
|
||||
this.ProjectEntityUpdateHandler.promises.setRootDoc.should.not.have.been
|
||||
.called
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an invalid root doc', function() {
|
||||
beforeEach(async function() {
|
||||
describe('with an invalid root doc', function () {
|
||||
beforeEach(async function () {
|
||||
this.ProjectEntityUpdateHandler.isPathValidForRootDoc.returns(false)
|
||||
this.newProject = await this.ProjectDuplicator.promises.duplicate(
|
||||
this.owner,
|
||||
@@ -343,14 +343,14 @@ describe('ProjectDuplicator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the root doc on the copy', function() {
|
||||
it('should not set the root doc on the copy', function () {
|
||||
this.ProjectEntityUpdateHandler.promises.setRootDoc.should.not.have.been
|
||||
.called
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is an error', function() {
|
||||
beforeEach(async function() {
|
||||
describe('when there is an error', function () {
|
||||
beforeEach(async function () {
|
||||
this.ProjectEntityMongoUpdateHandler.promises.createNewFolderStructure.rejects()
|
||||
await expect(
|
||||
this.ProjectDuplicator.promises.duplicate(
|
||||
@@ -361,13 +361,13 @@ describe('ProjectDuplicator', function() {
|
||||
).to.be.rejected
|
||||
})
|
||||
|
||||
it('should delete the broken cloned project', function() {
|
||||
it('should delete the broken cloned project', function () {
|
||||
this.ProjectDeleter.promises.deleteProject.should.have.been.calledWith(
|
||||
this.newBlankProject._id
|
||||
)
|
||||
})
|
||||
|
||||
it('should not delete the original project', function() {
|
||||
it('should not delete the original project', function () {
|
||||
this.ProjectDeleter.promises.deleteProject.should.not.have.been.calledWith(
|
||||
this.project._id
|
||||
)
|
||||
|
||||
@@ -15,8 +15,8 @@ const { expect } = require('chai')
|
||||
const modulePath = '../../../../app/src/Features/Project/ProjectEditorHandler'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('ProjectEditorHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectEditorHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.project = {
|
||||
_id: 'project-id',
|
||||
name: 'Project Name',
|
||||
@@ -112,9 +112,9 @@ describe('ProjectEditorHandler', function() {
|
||||
return (this.handler = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
describe('buildProjectModelView', function() {
|
||||
describe('with owner, members and invites included', function() {
|
||||
beforeEach(function() {
|
||||
describe('buildProjectModelView', function () {
|
||||
describe('with owner, members and invites included', function () {
|
||||
beforeEach(function () {
|
||||
return (this.result = this.handler.buildProjectModelView(
|
||||
this.project,
|
||||
this.members,
|
||||
@@ -123,27 +123,27 @@ describe('ProjectEditorHandler', function() {
|
||||
))
|
||||
})
|
||||
|
||||
it('should include the id', function() {
|
||||
it('should include the id', function () {
|
||||
expect(this.result._id).to.exist
|
||||
return this.result._id.should.equal('project-id')
|
||||
})
|
||||
|
||||
it('should include the name', function() {
|
||||
it('should include the name', function () {
|
||||
expect(this.result.name).to.exist
|
||||
return this.result.name.should.equal('Project Name')
|
||||
})
|
||||
|
||||
it('should include the root doc id', function() {
|
||||
it('should include the root doc id', function () {
|
||||
expect(this.result.rootDoc_id).to.exist
|
||||
return this.result.rootDoc_id.should.equal('file-id')
|
||||
})
|
||||
|
||||
it('should include the public access level', function() {
|
||||
it('should include the public access level', function () {
|
||||
expect(this.result.publicAccesLevel).to.exist
|
||||
return this.result.publicAccesLevel.should.equal('private')
|
||||
})
|
||||
|
||||
it('should include the owner', function() {
|
||||
it('should include the owner', function () {
|
||||
expect(this.result.owner).to.exist
|
||||
this.result.owner._id.should.equal('owner-id')
|
||||
this.result.owner.email.should.equal('owner@sharelatex.com')
|
||||
@@ -152,7 +152,7 @@ describe('ProjectEditorHandler', function() {
|
||||
return this.result.owner.privileges.should.equal('owner')
|
||||
})
|
||||
|
||||
it('should include the deletedDocs', function() {
|
||||
it('should include the deletedDocs', function () {
|
||||
expect(this.result.deletedDocs).to.exist
|
||||
this.result.deletedDocs.should.deep.equal([
|
||||
{
|
||||
@@ -164,12 +164,12 @@ describe('ProjectEditorHandler', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('invites should not include the token', function() {
|
||||
it('invites should not include the token', function () {
|
||||
expect(this.result.invites[0].token).not.to.exist
|
||||
expect(this.result.invites[1].token).not.to.exist
|
||||
})
|
||||
|
||||
it('should gather readOnly_refs and collaberators_refs into a list of members', function() {
|
||||
it('should gather readOnly_refs and collaberators_refs into a list of members', function () {
|
||||
const findMember = id => {
|
||||
for (let member of Array.from(this.result.members)) {
|
||||
if (member._id === id) {
|
||||
@@ -198,7 +198,7 @@ describe('ProjectEditorHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should include folders in the project', function() {
|
||||
it('should include folders in the project', function () {
|
||||
this.result.rootFolder[0]._id.should.equal('root-folder-id')
|
||||
this.result.rootFolder[0].name.should.equal('')
|
||||
|
||||
@@ -206,12 +206,12 @@ describe('ProjectEditorHandler', function() {
|
||||
return this.result.rootFolder[0].folders[0].name.should.equal('folder')
|
||||
})
|
||||
|
||||
it('should not duplicate folder contents', function() {
|
||||
it('should not duplicate folder contents', function () {
|
||||
this.result.rootFolder[0].docs.length.should.equal(0)
|
||||
return this.result.rootFolder[0].fileRefs.length.should.equal(0)
|
||||
})
|
||||
|
||||
it('should include files in the project', function() {
|
||||
it('should include files in the project', function () {
|
||||
this.result.rootFolder[0].folders[0].fileRefs[0]._id.should.equal(
|
||||
'file-id'
|
||||
)
|
||||
@@ -225,7 +225,7 @@ describe('ProjectEditorHandler', function() {
|
||||
.to.exist
|
||||
})
|
||||
|
||||
it('should include docs in the project but not the lines', function() {
|
||||
it('should include docs in the project but not the lines', function () {
|
||||
this.result.rootFolder[0].folders[0].docs[0]._id.should.equal('doc-id')
|
||||
this.result.rootFolder[0].folders[0].docs[0].name.should.equal(
|
||||
'main.tex'
|
||||
@@ -234,14 +234,14 @@ describe('ProjectEditorHandler', function() {
|
||||
.exist
|
||||
})
|
||||
|
||||
it('should include invites', function() {
|
||||
it('should include invites', function () {
|
||||
expect(this.result.invites).to.exist
|
||||
return this.result.invites.should.deep.equal(this.invites)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when docstore sends a deleted doc that is also present in the project', function() {
|
||||
beforeEach(function() {
|
||||
describe('when docstore sends a deleted doc that is also present in the project', function () {
|
||||
beforeEach(function () {
|
||||
this.deletedDocsFromDocstore.push(this.project.deletedDocs[0])
|
||||
this.result = this.handler.buildProjectModelView(
|
||||
this.project,
|
||||
@@ -251,7 +251,7 @@ describe('ProjectEditorHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not send any duplicate', function() {
|
||||
it('should not send any duplicate', function () {
|
||||
expect(this.result.deletedDocs).to.exist
|
||||
this.result.deletedDocs.should.deep.equal([
|
||||
this.project.deletedDocs[0],
|
||||
@@ -260,8 +260,8 @@ describe('ProjectEditorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('deletedByExternalDataSource', function() {
|
||||
it('should set the deletedByExternalDataSource flag to false when it is not there', function() {
|
||||
describe('deletedByExternalDataSource', function () {
|
||||
it('should set the deletedByExternalDataSource flag to false when it is not there', function () {
|
||||
delete this.project.deletedByExternalDataSource
|
||||
const result = this.handler.buildProjectModelView(
|
||||
this.project,
|
||||
@@ -272,7 +272,7 @@ describe('ProjectEditorHandler', function() {
|
||||
return result.deletedByExternalDataSource.should.equal(false)
|
||||
})
|
||||
|
||||
it('should set the deletedByExternalDataSource flag to false when it is false', function() {
|
||||
it('should set the deletedByExternalDataSource flag to false when it is false', function () {
|
||||
const result = this.handler.buildProjectModelView(
|
||||
this.project,
|
||||
this.members,
|
||||
@@ -282,7 +282,7 @@ describe('ProjectEditorHandler', function() {
|
||||
return result.deletedByExternalDataSource.should.equal(false)
|
||||
})
|
||||
|
||||
it('should set the deletedByExternalDataSource flag to true when it is true', function() {
|
||||
it('should set the deletedByExternalDataSource flag to true when it is true', function () {
|
||||
this.project.deletedByExternalDataSource = true
|
||||
const result = this.handler.buildProjectModelView(
|
||||
this.project,
|
||||
@@ -294,8 +294,8 @@ describe('ProjectEditorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('features', function() {
|
||||
beforeEach(function() {
|
||||
describe('features', function () {
|
||||
beforeEach(function () {
|
||||
this.owner.features = {
|
||||
versioning: true,
|
||||
collaborators: 3,
|
||||
@@ -310,7 +310,7 @@ describe('ProjectEditorHandler', function() {
|
||||
))
|
||||
})
|
||||
|
||||
it('should copy the owner features to the project', function() {
|
||||
it('should copy the owner features to the project', function () {
|
||||
this.result.features.versioning.should.equal(
|
||||
this.owner.features.versioning
|
||||
)
|
||||
@@ -326,9 +326,9 @@ describe('ProjectEditorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('trackChangesState', function() {
|
||||
describe('when the owner does not have the trackChanges feature', function() {
|
||||
beforeEach(function() {
|
||||
describe('trackChangesState', function () {
|
||||
describe('when the owner does not have the trackChanges feature', function () {
|
||||
beforeEach(function () {
|
||||
this.owner.features = {
|
||||
trackChanges: false
|
||||
}
|
||||
@@ -339,13 +339,13 @@ describe('ProjectEditorHandler', function() {
|
||||
[]
|
||||
)
|
||||
})
|
||||
it('should not emit trackChangesState', function() {
|
||||
it('should not emit trackChangesState', function () {
|
||||
expect(this.result.trackChangesState).to.not.exist
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the owner has got the trackChanges feature', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the owner has got the trackChanges feature', function () {
|
||||
beforeEach(function () {
|
||||
this.owner.features = {
|
||||
trackChanges: true
|
||||
}
|
||||
@@ -354,8 +354,8 @@ describe('ProjectEditorHandler', function() {
|
||||
function genCase([dbEntry, expected]) {
|
||||
describe(`when track_changes is ${JSON.stringify(
|
||||
dbEntry
|
||||
)}`, function() {
|
||||
beforeEach(function() {
|
||||
)}`, function () {
|
||||
beforeEach(function () {
|
||||
this.project.track_changes = dbEntry
|
||||
this.result = this.handler.buildProjectModelView(
|
||||
this.project,
|
||||
@@ -364,7 +364,7 @@ describe('ProjectEditorHandler', function() {
|
||||
[]
|
||||
)
|
||||
})
|
||||
it(`should set trackChangesState=${expected}`, function() {
|
||||
it(`should set trackChangesState=${expected}`, function () {
|
||||
expect(this.result.trackChangesState).to.deep.equal(expected)
|
||||
})
|
||||
})
|
||||
@@ -381,8 +381,8 @@ describe('ProjectEditorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildOwnerAndMembersViews', function() {
|
||||
beforeEach(function() {
|
||||
describe('buildOwnerAndMembersViews', function () {
|
||||
beforeEach(function () {
|
||||
this.owner.features = {
|
||||
versioning: true,
|
||||
collaborators: 3,
|
||||
@@ -394,7 +394,7 @@ describe('ProjectEditorHandler', function() {
|
||||
))
|
||||
})
|
||||
|
||||
it('should produce an object with the right keys', function() {
|
||||
it('should produce an object with the right keys', function () {
|
||||
return expect(this.result).to.have.all.keys([
|
||||
'owner',
|
||||
'ownerFeatures',
|
||||
@@ -402,7 +402,7 @@ describe('ProjectEditorHandler', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('should separate the owner from the members', function() {
|
||||
it('should separate the owner from the members', function () {
|
||||
this.result.members.length.should.equal(this.members.length - 1)
|
||||
expect(this.result.owner._id).to.equal(this.owner._id)
|
||||
expect(this.result.owner.email).to.equal(this.owner.email)
|
||||
@@ -411,14 +411,14 @@ describe('ProjectEditorHandler', function() {
|
||||
).to.equal(0)
|
||||
})
|
||||
|
||||
it('should extract the ownerFeatures from the owner object', function() {
|
||||
it('should extract the ownerFeatures from the owner object', function () {
|
||||
return expect(this.result.ownerFeatures).to.deep.equal(
|
||||
this.owner.features
|
||||
)
|
||||
})
|
||||
|
||||
describe('when there is no owner', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there is no owner', function () {
|
||||
beforeEach(function () {
|
||||
// remove the owner from members list
|
||||
this.membersWithoutOwner = this.members.filter(
|
||||
m => m.user._id !== this.owner._id
|
||||
@@ -428,7 +428,7 @@ describe('ProjectEditorHandler', function() {
|
||||
))
|
||||
})
|
||||
|
||||
it('should produce an object with the right keys', function() {
|
||||
it('should produce an object with the right keys', function () {
|
||||
return expect(this.result).to.have.all.keys([
|
||||
'owner',
|
||||
'ownerFeatures',
|
||||
@@ -436,12 +436,12 @@ describe('ProjectEditorHandler', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('should not separate out an owner', function() {
|
||||
it('should not separate out an owner', function () {
|
||||
this.result.members.length.should.equal(this.membersWithoutOwner.length)
|
||||
return expect(this.result.owner).to.equal(null)
|
||||
})
|
||||
|
||||
it('should not extract the ownerFeatures from the owner object', function() {
|
||||
it('should not extract the ownerFeatures from the owner object', function () {
|
||||
return expect(this.result.ownerFeatures).to.equal(null)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -19,20 +19,20 @@ const modulePath = '../../../../app/src/Features/Project/ProjectEntityHandler'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
|
||||
describe('ProjectEntityHandler', function() {
|
||||
describe('ProjectEntityHandler', function () {
|
||||
const project_id = '4eecb1c1bffa66588e0000a1'
|
||||
const doc_id = '4eecb1c1bffa66588e0000a2'
|
||||
const folder_id = '4eecaffcbffa66588e000008'
|
||||
const rootFolderId = '4eecaffcbffa66588e000007'
|
||||
const userId = 1234
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
let Project
|
||||
this.TpdsUpdateSender = {
|
||||
addDoc: sinon.stub().callsArg(1),
|
||||
addFile: sinon.stub().callsArg(1)
|
||||
}
|
||||
this.ProjectModel = Project = (function() {
|
||||
this.ProjectModel = Project = (function () {
|
||||
Project = class Project {
|
||||
static initClass() {
|
||||
this.prototype.rootFolder = [this.rootFolder]
|
||||
@@ -71,8 +71,8 @@ describe('ProjectEntityHandler', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('getting folders, docs and files', function() {
|
||||
beforeEach(function() {
|
||||
describe('getting folders, docs and files', function () {
|
||||
beforeEach(function () {
|
||||
this.project.rootFolder = [
|
||||
{
|
||||
docs: [
|
||||
@@ -114,8 +114,8 @@ describe('ProjectEntityHandler', function() {
|
||||
.yields(null, this.project)
|
||||
})
|
||||
|
||||
describe('getAllDocs', function() {
|
||||
beforeEach(function() {
|
||||
describe('getAllDocs', function () {
|
||||
beforeEach(function () {
|
||||
this.docs = [
|
||||
{
|
||||
_id: this.doc1._id,
|
||||
@@ -134,13 +134,13 @@ describe('ProjectEntityHandler', function() {
|
||||
this.ProjectEntityHandler.getAllDocs(project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should get the doc lines and rev from the docstore', function() {
|
||||
it('should get the doc lines and rev from the docstore', function () {
|
||||
this.DocstoreManager.getAllDocs
|
||||
.calledWith(project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with the docs with the lines and rev included', function() {
|
||||
it('should call the callback with the docs with the lines and rev included', function () {
|
||||
this.callback
|
||||
.calledWith(null, {
|
||||
'/doc1': {
|
||||
@@ -160,13 +160,13 @@ describe('ProjectEntityHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAllFiles', function() {
|
||||
beforeEach(function() {
|
||||
describe('getAllFiles', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
this.ProjectEntityHandler.getAllFiles(project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with the files', function() {
|
||||
it('should call the callback with the files', function () {
|
||||
this.callback
|
||||
.calledWith(null, {
|
||||
'/file1': this.file1,
|
||||
@@ -176,8 +176,8 @@ describe('ProjectEntityHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAllDocPathsFromProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('getAllDocPathsFromProject', function () {
|
||||
beforeEach(function () {
|
||||
this.docs = [
|
||||
{
|
||||
_id: this.doc1._id,
|
||||
@@ -197,7 +197,7 @@ describe('ProjectEntityHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with the path for each doc_id', function() {
|
||||
it('should call the callback with the path for each doc_id', function () {
|
||||
this.expected = {}
|
||||
this.expected[this.doc1._id] = `/${this.doc1.name}`
|
||||
this.expected[this.doc2._id] = `/folder1/${this.doc2.name}`
|
||||
@@ -205,11 +205,11 @@ describe('ProjectEntityHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getDocPathByProjectIdAndDocId', function() {
|
||||
beforeEach(function() {
|
||||
describe('getDocPathByProjectIdAndDocId', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
})
|
||||
it('should call the callback with the path for an existing doc id at the root level', function() {
|
||||
it('should call the callback with the path for an existing doc id at the root level', function () {
|
||||
this.ProjectEntityHandler.getDocPathByProjectIdAndDocId(
|
||||
project_id,
|
||||
this.doc1._id,
|
||||
@@ -218,7 +218,7 @@ describe('ProjectEntityHandler', function() {
|
||||
this.callback.calledWith(null, `/${this.doc1.name}`).should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with the path for an existing doc id nested within a folder', function() {
|
||||
it('should call the callback with the path for an existing doc id nested within a folder', function () {
|
||||
this.ProjectEntityHandler.getDocPathByProjectIdAndDocId(
|
||||
project_id,
|
||||
this.doc2._id,
|
||||
@@ -229,7 +229,7 @@ describe('ProjectEntityHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with a NotFoundError for a non-existing doc', function() {
|
||||
it('should call the callback with a NotFoundError for a non-existing doc', function () {
|
||||
this.ProjectEntityHandler.getDocPathByProjectIdAndDocId(
|
||||
project_id,
|
||||
'non-existing-id',
|
||||
@@ -240,7 +240,7 @@ describe('ProjectEntityHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a NotFoundError for an existing file', function() {
|
||||
it('should call the callback with a NotFoundError for an existing file', function () {
|
||||
this.ProjectEntityHandler.getDocPathByProjectIdAndDocId(
|
||||
project_id,
|
||||
this.file1._id,
|
||||
@@ -252,19 +252,19 @@ describe('ProjectEntityHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_getAllFolders', function() {
|
||||
beforeEach(function() {
|
||||
describe('_getAllFolders', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
this.ProjectEntityHandler._getAllFolders(project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should get the project without the docs lines', function() {
|
||||
it('should get the project without the docs lines', function () {
|
||||
this.ProjectGetter.getProjectWithoutDocLines
|
||||
.calledWith(project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with the folders', function() {
|
||||
it('should call the callback with the folders', function () {
|
||||
this.callback
|
||||
.calledWith(null, {
|
||||
'/': this.project.rootFolder[0],
|
||||
@@ -274,8 +274,8 @@ describe('ProjectEntityHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_getAllFoldersFromProject', function() {
|
||||
beforeEach(function() {
|
||||
describe('_getAllFoldersFromProject', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
this.ProjectEntityHandler._getAllFoldersFromProject(
|
||||
this.project,
|
||||
@@ -283,7 +283,7 @@ describe('ProjectEntityHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with the folders', function() {
|
||||
it('should call the callback with the folders', function () {
|
||||
this.callback
|
||||
.calledWith(null, {
|
||||
'/': this.project.rootFolder[0],
|
||||
@@ -294,8 +294,8 @@ describe('ProjectEntityHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getDoc', function() {
|
||||
beforeEach(function() {
|
||||
describe('getDoc', function () {
|
||||
beforeEach(function () {
|
||||
this.lines = ['mock', 'doc', 'lines']
|
||||
this.rev = 5
|
||||
this.version = 42
|
||||
@@ -307,23 +307,23 @@ describe('ProjectEntityHandler', function() {
|
||||
this.ProjectEntityHandler.getDoc(project_id, doc_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the docstore', function() {
|
||||
it('should call the docstore', function () {
|
||||
this.DocstoreManager.getDoc
|
||||
.calledWith(project_id, doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with the lines, version and rev', function() {
|
||||
it('should call the callback with the lines, version and rev', function () {
|
||||
this.callback
|
||||
.calledWith(null, this.lines, this.rev, this.version, this.ranges)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('promises.getDoc', function() {
|
||||
describe('promises.getDoc', function () {
|
||||
let result
|
||||
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
this.lines = ['mock', 'doc', 'lines']
|
||||
this.rev = 5
|
||||
this.version = 42
|
||||
@@ -338,13 +338,13 @@ describe('ProjectEntityHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the docstore', function() {
|
||||
it('should call the docstore', function () {
|
||||
this.DocstoreManager.getDoc
|
||||
.calledWith(project_id, doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return the lines, rev, version and ranges', function() {
|
||||
it('should return the lines, rev, version and ranges', function () {
|
||||
expect(result.lines).to.equal(this.lines)
|
||||
expect(result.rev).to.equal(this.rev)
|
||||
expect(result.version).to.equal(this.version)
|
||||
|
||||
@@ -10,8 +10,8 @@ const { Project } = require('../helpers/models/Project')
|
||||
const MODULE_PATH =
|
||||
'../../../../app/src/Features/Project/ProjectEntityMongoUpdateHandler'
|
||||
|
||||
describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectEntityMongoUpdateHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.doc = {
|
||||
_id: ObjectId(),
|
||||
name: 'test-doc.txt',
|
||||
@@ -194,21 +194,21 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
this.DeletedFileMock.restore()
|
||||
this.ProjectMock.restore()
|
||||
})
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
tk.freeze(Date.now())
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
tk.reset()
|
||||
})
|
||||
|
||||
describe('addDoc', function() {
|
||||
beforeEach(async function() {
|
||||
describe('addDoc', function () {
|
||||
beforeEach(async function () {
|
||||
const doc = { _id: ObjectId(), name: 'other.txt' }
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
@@ -227,11 +227,11 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('adds the document in Mongo', function() {
|
||||
it('adds the document in Mongo', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('returns path info and the project', function() {
|
||||
it('returns path info and the project', function () {
|
||||
expect(this.result).to.deep.equal({
|
||||
result: {
|
||||
path: {
|
||||
@@ -244,8 +244,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('addFile', function() {
|
||||
beforeEach(function() {
|
||||
describe('addFile', function () {
|
||||
beforeEach(function () {
|
||||
this.newFile = { _id: ObjectId(), name: 'picture.jpg' }
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
@@ -259,8 +259,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
.resolves(this.project)
|
||||
})
|
||||
|
||||
describe('happy path', function() {
|
||||
beforeEach(async function() {
|
||||
describe('happy path', function () {
|
||||
beforeEach(async function () {
|
||||
this.result = await this.subject.promises.addFile(
|
||||
this.project._id,
|
||||
this.folder._id,
|
||||
@@ -268,11 +268,11 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('adds the file in Mongo', function() {
|
||||
it('adds the file in Mongo', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('returns path info and the project', function() {
|
||||
it('returns path info and the project', function () {
|
||||
expect(this.result).to.deep.equal({
|
||||
result: {
|
||||
path: {
|
||||
@@ -285,17 +285,17 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when entity limit is reached', function() {
|
||||
beforeEach(function() {
|
||||
describe('when entity limit is reached', function () {
|
||||
beforeEach(function () {
|
||||
this.savedMaxEntities = this.Settings.maxEntitiesPerProject
|
||||
this.Settings.maxEntitiesPerProject = 3
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
this.Settings.maxEntitiesPerProject = this.savedMaxEntities
|
||||
})
|
||||
|
||||
it('should throw an error', async function() {
|
||||
it('should throw an error', async function () {
|
||||
await expect(
|
||||
this.subject.promises.addFile(
|
||||
this.project._id,
|
||||
@@ -307,8 +307,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('addFolder', function() {
|
||||
beforeEach(async function() {
|
||||
describe('addFolder', function () {
|
||||
beforeEach(async function () {
|
||||
const folderName = 'New folder'
|
||||
this.FolderModel.withArgs({ name: folderName }).returns({
|
||||
_id: ObjectId(),
|
||||
@@ -335,13 +335,13 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('adds the folder in Mongo', function() {
|
||||
it('adds the folder in Mongo', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('replaceFileWithNew', function() {
|
||||
beforeEach(async function() {
|
||||
describe('replaceFileWithNew', function () {
|
||||
beforeEach(async function () {
|
||||
const newFile = {
|
||||
_id: ObjectId(),
|
||||
name: 'some-other-file.png',
|
||||
@@ -385,56 +385,56 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('updates the database', function() {
|
||||
it('updates the database', function () {
|
||||
this.DeletedFileMock.verify()
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('mkdirp', function() {
|
||||
describe('when the path is just a slash', function() {
|
||||
beforeEach(async function() {
|
||||
describe('mkdirp', function () {
|
||||
describe('when the path is just a slash', function () {
|
||||
beforeEach(async function () {
|
||||
this.result = await this.subject.promises.mkdirp(this.project._id, '/')
|
||||
})
|
||||
|
||||
it('should return the root folder', function() {
|
||||
it('should return the root folder', function () {
|
||||
expect(this.result.folder).to.deep.equal(this.rootFolder)
|
||||
})
|
||||
|
||||
it('should not report a parent folder', function() {
|
||||
it('should not report a parent folder', function () {
|
||||
expect(this.result.folder.parentFolder_id).not.to.exist
|
||||
})
|
||||
|
||||
it('should not return new folders', function() {
|
||||
it('should not return new folders', function () {
|
||||
expect(this.result.newFolders).to.have.length(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the folder already exists', function() {
|
||||
beforeEach(async function() {
|
||||
describe('when the folder already exists', function () {
|
||||
beforeEach(async function () {
|
||||
this.result = await this.subject.promises.mkdirp(
|
||||
this.project._id,
|
||||
'/test-folder'
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the existing folder', function() {
|
||||
it('should return the existing folder', function () {
|
||||
expect(this.result.folder).to.deep.equal(this.folder)
|
||||
})
|
||||
|
||||
it('should report the parent folder', function() {
|
||||
it('should report the parent folder', function () {
|
||||
expect(this.result.folder.parentFolder_id).not.equal(
|
||||
this.rootFolder._id
|
||||
)
|
||||
})
|
||||
|
||||
it('should not return new folders', function() {
|
||||
it('should not return new folders', function () {
|
||||
expect(this.result.newFolders).to.have.length(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the path is a new folder at the top level', function() {
|
||||
beforeEach(async function() {
|
||||
describe('when the path is a new folder at the top level', function () {
|
||||
beforeEach(async function () {
|
||||
this.newFolder = { _id: ObjectId(), name: 'new-folder' }
|
||||
this.FolderModel.returns(this.newFolder)
|
||||
this.exactCaseMatch = false
|
||||
@@ -454,31 +454,31 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
{ exactCaseMatch: this.exactCaseMatch }
|
||||
)
|
||||
})
|
||||
it('should update the database', function() {
|
||||
it('should update the database', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should make just one folder', function() {
|
||||
it('should make just one folder', function () {
|
||||
expect(this.result.newFolders).to.have.length(1)
|
||||
})
|
||||
|
||||
it('should return the new folder', function() {
|
||||
it('should return the new folder', function () {
|
||||
expect(this.result.folder.name).to.equal('new-folder')
|
||||
})
|
||||
|
||||
it('should return the parent folder', function() {
|
||||
it('should return the parent folder', function () {
|
||||
expect(this.result.folder.parentFolder_id).to.equal(this.rootFolder._id)
|
||||
})
|
||||
|
||||
it('should pass the exactCaseMatch option to ProjectLocator', function() {
|
||||
it('should pass the exactCaseMatch option to ProjectLocator', function () {
|
||||
expect(
|
||||
this.ProjectLocator.promises.findElementByPath
|
||||
).to.have.been.calledWithMatch({ exactCaseMatch: this.exactCaseMatch })
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding a subfolder', function() {
|
||||
beforeEach(async function() {
|
||||
describe('adding a subfolder', function () {
|
||||
beforeEach(async function () {
|
||||
this.newFolder = { _id: ObjectId(), name: 'new-folder' }
|
||||
this.FolderModel.returns(this.newFolder)
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
@@ -501,25 +501,25 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the database', function() {
|
||||
it('should update the database', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should create one folder', function() {
|
||||
it('should create one folder', function () {
|
||||
expect(this.result.newFolders).to.have.length(1)
|
||||
})
|
||||
|
||||
it('should return the new folder', function() {
|
||||
it('should return the new folder', function () {
|
||||
expect(this.result.folder.name).to.equal('new-folder')
|
||||
})
|
||||
|
||||
it('should return the parent folder', function() {
|
||||
it('should return the parent folder', function () {
|
||||
expect(this.result.folder.parentFolder_id).to.equal(this.folder._id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when mutliple folders are missing', async function() {
|
||||
beforeEach(function() {
|
||||
describe('when mutliple folders are missing', async function () {
|
||||
beforeEach(function () {
|
||||
this.folder1 = { _id: ObjectId(), name: 'folder1' }
|
||||
this.folder1Path = {
|
||||
fileSystem: '/test-folder/folder1',
|
||||
@@ -591,30 +591,30 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
path: '/test-folder/folder1/folder2/'
|
||||
}
|
||||
].forEach(({ description, path }) => {
|
||||
describe(description, function() {
|
||||
beforeEach(async function() {
|
||||
describe(description, function () {
|
||||
beforeEach(async function () {
|
||||
this.result = await this.subject.promises.mkdirp(
|
||||
this.project._id,
|
||||
path
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the database', function() {
|
||||
it('should update the database', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should add multiple folders', function() {
|
||||
it('should add multiple folders', function () {
|
||||
const newFolders = this.result.newFolders
|
||||
expect(newFolders).to.have.length(2)
|
||||
expect(newFolders[0].name).to.equal('folder1')
|
||||
expect(newFolders[1].name).to.equal('folder2')
|
||||
})
|
||||
|
||||
it('should return the last folder', function() {
|
||||
it('should return the last folder', function () {
|
||||
expect(this.result.folder.name).to.equal('folder2')
|
||||
})
|
||||
|
||||
it('should return the parent folder', function() {
|
||||
it('should return the parent folder', function () {
|
||||
expect(this.result.folder.parentFolder_id).to.equal(
|
||||
this.folder1._id
|
||||
)
|
||||
@@ -624,9 +624,9 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('moveEntity', function() {
|
||||
describe('moving a doc into a different folder', function() {
|
||||
beforeEach(async function() {
|
||||
describe('moveEntity', function () {
|
||||
describe('moving a doc into a different folder', function () {
|
||||
beforeEach(async function () {
|
||||
this.pathAfterMove = {
|
||||
fileSystem: '/somewhere/else.txt'
|
||||
}
|
||||
@@ -670,11 +670,11 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the database', function() {
|
||||
it('should update the database', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should report what changed', function() {
|
||||
it('should report what changed', function () {
|
||||
expect(this.result).to.deep.equal({
|
||||
project: this.project,
|
||||
startPath: '/test-doc.txt',
|
||||
@@ -691,8 +691,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when moving a folder inside itself', function() {
|
||||
it('throws an error', async function() {
|
||||
describe('when moving a folder inside itself', function () {
|
||||
it('throws an error', async function () {
|
||||
await expect(
|
||||
this.subject.promises.moveEntity(
|
||||
this.project._id,
|
||||
@@ -704,8 +704,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when moving a folder to a subfolder of itself', function() {
|
||||
it('throws an error', async function() {
|
||||
describe('when moving a folder to a subfolder of itself', function () {
|
||||
it('throws an error', async function () {
|
||||
await expect(
|
||||
this.subject.promises.moveEntity(
|
||||
this.project._id,
|
||||
@@ -718,8 +718,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteEntity', function() {
|
||||
beforeEach(async function() {
|
||||
describe('deleteEntity', function () {
|
||||
beforeEach(async function () {
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
{ _id: this.project._id },
|
||||
@@ -737,14 +737,14 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the database', function() {
|
||||
it('should update the database', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('renameEntity', function() {
|
||||
describe('happy path', function() {
|
||||
beforeEach(async function() {
|
||||
describe('renameEntity', function () {
|
||||
describe('happy path', function () {
|
||||
beforeEach(async function () {
|
||||
this.newName = 'new.tex'
|
||||
this.oldDocs = ['old-doc']
|
||||
this.oldFiles = ['old-file']
|
||||
@@ -776,11 +776,11 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the database', function() {
|
||||
it('should update the database', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('returns info', function() {
|
||||
it('returns info', function () {
|
||||
expect(this.result).to.deep.equal({
|
||||
project: this.project,
|
||||
startPath: '/test-doc.txt',
|
||||
@@ -797,8 +797,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('name already exists', function() {
|
||||
it('should throw an error', async function() {
|
||||
describe('name already exists', function () {
|
||||
it('should throw an error', async function () {
|
||||
await expect(
|
||||
this.subject.promises.renameEntity(
|
||||
this.project._id,
|
||||
@@ -811,10 +811,10 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_putElement', function() {
|
||||
describe('updating the project', function() {
|
||||
describe('when the parent folder is given', function() {
|
||||
beforeEach(function() {
|
||||
describe('_putElement', function () {
|
||||
describe('updating the project', function () {
|
||||
describe('when the parent folder is given', function () {
|
||||
beforeEach(function () {
|
||||
this.newFile = { _id: ObjectId(), name: 'new file.png' }
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
@@ -828,7 +828,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
.resolves(this.project)
|
||||
})
|
||||
|
||||
it('should update the database', async function() {
|
||||
it('should update the database', async function () {
|
||||
await this.subject.promises._putElement(
|
||||
this.project,
|
||||
this.folder._id,
|
||||
@@ -838,7 +838,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
|
||||
it('should add an s onto the type if not included', async function() {
|
||||
it('should add an s onto the type if not included', async function () {
|
||||
await this.subject.promises._putElement(
|
||||
this.project,
|
||||
this.folder._id,
|
||||
@@ -849,8 +849,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('error cases', function() {
|
||||
it('should throw an error if element is null', async function() {
|
||||
describe('error cases', function () {
|
||||
it('should throw an error if element is null', async function () {
|
||||
await expect(
|
||||
this.subject.promises._putElement(
|
||||
this.project,
|
||||
@@ -861,7 +861,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
).to.be.rejected
|
||||
})
|
||||
|
||||
it('should error if the element has no _id', async function() {
|
||||
it('should error if the element has no _id', async function () {
|
||||
const file = { name: 'something' }
|
||||
await expect(
|
||||
this.subject.promises._putElement(
|
||||
@@ -873,7 +873,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
).to.be.rejected
|
||||
})
|
||||
|
||||
it('should error if element name contains invalid characters', async function() {
|
||||
it('should error if element name contains invalid characters', async function () {
|
||||
const file = { _id: ObjectId(), name: 'something*bad' }
|
||||
await expect(
|
||||
this.subject.promises._putElement(
|
||||
@@ -885,7 +885,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
).to.be.rejected
|
||||
})
|
||||
|
||||
it('should error if element name is too long', async function() {
|
||||
it('should error if element name is too long', async function () {
|
||||
const file = {
|
||||
_id: ObjectId(),
|
||||
name: 'long-'.repeat(1000) + 'something'
|
||||
@@ -900,7 +900,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
).to.be.rejectedWith(Errors.InvalidNameError)
|
||||
})
|
||||
|
||||
it('should error if the folder name is too long', async function() {
|
||||
it('should error if the folder name is too long', async function () {
|
||||
const file = {
|
||||
_id: ObjectId(),
|
||||
name: 'something'
|
||||
@@ -925,7 +925,7 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
).to.be.rejectedWith(Errors.InvalidNameError)
|
||||
})
|
||||
;['file', 'doc', 'folder'].forEach(entityType => {
|
||||
it(`should error if a ${entityType} already exists with the same name`, async function() {
|
||||
it(`should error if a ${entityType} already exists with the same name`, async function () {
|
||||
const file = {
|
||||
_id: ObjectId(),
|
||||
name: this[entityType].name
|
||||
@@ -943,8 +943,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the parent folder is not given', function() {
|
||||
it('should default to root folder insert', async function() {
|
||||
describe('when the parent folder is not given', function () {
|
||||
it('should default to root folder insert', async function () {
|
||||
this.newFile = { _id: ObjectId(), name: 'new file.png' }
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
@@ -966,8 +966,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_insertDeletedFileReference', function() {
|
||||
beforeEach(async function() {
|
||||
describe('_insertDeletedFileReference', function () {
|
||||
beforeEach(async function () {
|
||||
this.DeletedFileMock.expects('create')
|
||||
.withArgs({
|
||||
projectId: this.project._id,
|
||||
@@ -984,13 +984,13 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update the database', function() {
|
||||
it('should update the database', function () {
|
||||
this.DeletedFileMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('createNewFolderStructure', function() {
|
||||
beforeEach(function() {
|
||||
describe('createNewFolderStructure', function () {
|
||||
beforeEach(function () {
|
||||
this.mockRootFolder = 'MOCK_ROOT_FOLDER'
|
||||
this.docUploads = ['MOCK_DOC_UPLOAD']
|
||||
this.fileUploads = ['MOCK_FILE_UPLOAD']
|
||||
@@ -1011,8 +1011,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
.chain('exec')
|
||||
})
|
||||
|
||||
describe('happy path', function() {
|
||||
beforeEach(async function() {
|
||||
describe('happy path', function () {
|
||||
beforeEach(async function () {
|
||||
this.updateExpectation.resolves({ version: 1 })
|
||||
await this.subject.promises.createNewFolderStructure(
|
||||
this.project._id,
|
||||
@@ -1021,17 +1021,17 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('updates the database', function() {
|
||||
it('updates the database', function () {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the update doesn't find a matching document", function() {
|
||||
beforeEach(async function() {
|
||||
describe("when the update doesn't find a matching document", function () {
|
||||
beforeEach(async function () {
|
||||
this.updateExpectation.resolves(null)
|
||||
})
|
||||
|
||||
it('throws an error', async function() {
|
||||
it('throws an error', async function () {
|
||||
await expect(
|
||||
this.subject.promises.createNewFolderStructure(
|
||||
this.project._id,
|
||||
@@ -1043,8 +1043,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('replaceDocWithFile', function() {
|
||||
it('should simultaneously remove the doc and add the file', async function() {
|
||||
describe('replaceDocWithFile', function () {
|
||||
it('should simultaneously remove the doc and add the file', async function () {
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
{ _id: this.project._id },
|
||||
@@ -1066,8 +1066,8 @@ describe('ProjectEntityMongoUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('replaceFileWithDoc', function() {
|
||||
it('should simultaneously remove the file and add the doc', async function() {
|
||||
describe('replaceFileWithDoc', function () {
|
||||
it('should simultaneously remove the file and add the doc', async function () {
|
||||
this.ProjectMock.expects('findOneAndUpdate')
|
||||
.withArgs(
|
||||
{ _id: this.project._id },
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,8 +4,8 @@ const modulePath = '../../../../app/src/Features/Project/ProjectGetter.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { ObjectId } = require('mongodb')
|
||||
|
||||
describe('ProjectGetter', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectGetter', function () {
|
||||
beforeEach(function () {
|
||||
this.callback = sinon.stub()
|
||||
this.project = { _id: new ObjectId() }
|
||||
this.projectIdStr = this.project._id.toString()
|
||||
@@ -61,26 +61,26 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getProjectWithoutDocLines', function() {
|
||||
beforeEach(function() {
|
||||
describe('getProjectWithoutDocLines', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject = sinon.stub().yields()
|
||||
})
|
||||
|
||||
describe('passing an id', function() {
|
||||
beforeEach(function() {
|
||||
describe('passing an id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProjectWithoutDocLines(
|
||||
this.project._id,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should call find with the project id', function() {
|
||||
it('should call find with the project id', function () {
|
||||
this.ProjectGetter.getProject
|
||||
.calledWith(this.project._id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should exclude the doc lines', function() {
|
||||
it('should exclude the doc lines', function () {
|
||||
const excludes = {
|
||||
'rootFolder.docs.lines': 0,
|
||||
'rootFolder.folders.docs.lines': 0,
|
||||
@@ -97,32 +97,32 @@ describe('ProjectGetter', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getProjectWithOnlyFolders', function() {
|
||||
beforeEach(function() {
|
||||
describe('getProjectWithOnlyFolders', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject = sinon.stub().yields()
|
||||
})
|
||||
|
||||
describe('passing an id', function() {
|
||||
beforeEach(function() {
|
||||
describe('passing an id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProjectWithOnlyFolders(
|
||||
this.project._id,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should call find with the project id', function() {
|
||||
it('should call find with the project id', function () {
|
||||
this.ProjectGetter.getProject
|
||||
.calledWith(this.project._id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should exclude the docs and files linesaaaa', function() {
|
||||
it('should exclude the docs and files linesaaaa', function () {
|
||||
const excludes = {
|
||||
'rootFolder.docs': 0,
|
||||
'rootFolder.fileRefs': 0,
|
||||
@@ -146,20 +146,20 @@ describe('ProjectGetter', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback with the project', function() {
|
||||
it('should call the callback with the project', function () {
|
||||
this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getProject', function() {
|
||||
describe('without projection', function() {
|
||||
describe('with project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('getProject', function () {
|
||||
describe('without projection', function () {
|
||||
describe('with project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject(this.projectIdStr, this.callback)
|
||||
})
|
||||
|
||||
it('should call findOne with the project id', function() {
|
||||
it('should call findOne with the project id', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(1)
|
||||
expect(
|
||||
this.db.projects.findOne.lastCall.args[0]._id.toString()
|
||||
@@ -167,25 +167,25 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('without project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('without project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject(null, this.callback)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(0)
|
||||
expect(this.callback.lastCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with projection', function() {
|
||||
beforeEach(function() {
|
||||
describe('with projection', function () {
|
||||
beforeEach(function () {
|
||||
this.projection = { _id: 1 }
|
||||
})
|
||||
|
||||
describe('with project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('with project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject(
|
||||
this.projectIdStr,
|
||||
this.projection,
|
||||
@@ -193,7 +193,7 @@ describe('ProjectGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call findOne with the project id', function() {
|
||||
it('should call findOne with the project id', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(1)
|
||||
expect(
|
||||
this.db.projects.findOne.lastCall.args[0]._id.toString()
|
||||
@@ -204,12 +204,12 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('without project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('without project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject(null, this.callback)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(0)
|
||||
expect(this.callback.lastCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
@@ -217,17 +217,17 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getProjectWithoutLock', function() {
|
||||
describe('without projection', function() {
|
||||
describe('with project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('getProjectWithoutLock', function () {
|
||||
describe('without projection', function () {
|
||||
describe('with project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProjectWithoutLock(
|
||||
this.projectIdStr,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should call findOne with the project id', function() {
|
||||
it('should call findOne with the project id', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(1)
|
||||
expect(
|
||||
this.db.projects.findOne.lastCall.args[0]._id.toString()
|
||||
@@ -235,25 +235,25 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('without project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('without project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProjectWithoutLock(null, this.callback)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(0)
|
||||
expect(this.callback.lastCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with projection', function() {
|
||||
beforeEach(function() {
|
||||
describe('with projection', function () {
|
||||
beforeEach(function () {
|
||||
this.projection = { _id: 1 }
|
||||
})
|
||||
|
||||
describe('with project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('with project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProjectWithoutLock(
|
||||
this.project._id,
|
||||
this.projection,
|
||||
@@ -261,7 +261,7 @@ describe('ProjectGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call findOne with the project id', function() {
|
||||
it('should call findOne with the project id', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(1)
|
||||
expect(
|
||||
this.db.projects.findOne.lastCall.args[0]._id.toString()
|
||||
@@ -272,12 +272,12 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('without project id', function() {
|
||||
beforeEach(function() {
|
||||
describe('without project id', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProjectWithoutLock(null, this.callback)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
expect(this.db.projects.findOne.callCount).to.equal(0)
|
||||
expect(this.callback.lastCall.args[0]).to.be.instanceOf(Error)
|
||||
})
|
||||
@@ -285,8 +285,8 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('findAllUsersProjects', function() {
|
||||
beforeEach(function() {
|
||||
describe('findAllUsersProjects', function () {
|
||||
beforeEach(function () {
|
||||
this.fields = { mock: 'fields' }
|
||||
this.Project.find
|
||||
.withArgs({ owner_ref: this.userId }, this.fields)
|
||||
@@ -304,7 +304,7 @@ describe('ProjectGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with all the projects', function() {
|
||||
it('should call the callback with all the projects', function () {
|
||||
this.callback
|
||||
.calledWith(null, {
|
||||
owned: ['mock-owned-projects'],
|
||||
@@ -317,28 +317,28 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getProjectIdByReadAndWriteToken', function() {
|
||||
describe('when project find returns project', function() {
|
||||
this.beforeEach(function() {
|
||||
describe('getProjectIdByReadAndWriteToken', function () {
|
||||
describe('when project find returns project', function () {
|
||||
this.beforeEach(function () {
|
||||
this.ProjectGetter.getProjectIdByReadAndWriteToken(
|
||||
'token',
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should find project with token', function() {
|
||||
it('should find project with token', function () {
|
||||
this.Project.findOne
|
||||
.calledWithMatch({ 'tokens.readAndWrite': 'token' })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should callback with project id', function() {
|
||||
it('should callback with project id', function () {
|
||||
this.callback.calledWith(null, this.project._id).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when project not found', function() {
|
||||
this.beforeEach(function() {
|
||||
describe('when project not found', function () {
|
||||
this.beforeEach(function () {
|
||||
this.Project.findOne.yields(null, null)
|
||||
this.ProjectGetter.getProjectIdByReadAndWriteToken(
|
||||
'token',
|
||||
@@ -346,13 +346,13 @@ describe('ProjectGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback empty', function() {
|
||||
it('should callback empty', function () {
|
||||
expect(this.callback.firstCall.args.length).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when project find returns error', function() {
|
||||
this.beforeEach(function() {
|
||||
describe('when project find returns error', function () {
|
||||
this.beforeEach(function () {
|
||||
this.Project.findOne.yields('error')
|
||||
this.ProjectGetter.getProjectIdByReadAndWriteToken(
|
||||
'token',
|
||||
@@ -360,14 +360,14 @@ describe('ProjectGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
this.callback.calledWith('error').should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('findUsersProjectsByName', function() {
|
||||
it('should perform a case-insensitive search', function(done) {
|
||||
describe('findUsersProjectsByName', function () {
|
||||
it('should perform a case-insensitive search', function (done) {
|
||||
this.Project.find
|
||||
.withArgs({ owner_ref: this.userId })
|
||||
.yields(null, [
|
||||
@@ -391,7 +391,7 @@ describe('ProjectGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should search collaborations as well', function(done) {
|
||||
it('should search collaborations as well', function (done) {
|
||||
this.Project.find
|
||||
.withArgs({ owner_ref: this.userId })
|
||||
.yields(null, [{ name: 'find me!' }])
|
||||
@@ -418,8 +418,8 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUsersDeletedProjects', function() {
|
||||
it('should look up the deleted projects by deletedProjectOwnerId', function(done) {
|
||||
describe('getUsersDeletedProjects', function () {
|
||||
it('should look up the deleted projects by deletedProjectOwnerId', function (done) {
|
||||
this.ProjectGetter.getUsersDeletedProjects('giraffe', err => {
|
||||
if (err) {
|
||||
return done(err)
|
||||
@@ -431,7 +431,7 @@ describe('ProjectGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should pass the found projects to the callback', function(done) {
|
||||
it('should pass the found projects to the callback', function (done) {
|
||||
this.ProjectGetter.getUsersDeletedProjects('giraffe', (err, docs) => {
|
||||
if (err) {
|
||||
return done(err)
|
||||
|
||||
@@ -4,8 +4,8 @@ const { ObjectId } = require('mongodb')
|
||||
|
||||
const MODULE_PATH = '../../../../app/src/Features/Project/ProjectHelper.js'
|
||||
|
||||
describe('ProjectHelper', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectHelper', function () {
|
||||
beforeEach(function () {
|
||||
this.project = {
|
||||
_id: '123213jlkj9kdlsaj'
|
||||
}
|
||||
@@ -41,9 +41,9 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('isArchived', function() {
|
||||
describe('project.archived being an array', function() {
|
||||
it('returns true if user id is found', function() {
|
||||
describe('isArchived', function () {
|
||||
describe('project.archived being an array', function () {
|
||||
it('returns true if user id is found', function () {
|
||||
this.project.archived = [
|
||||
ObjectId('588f3ddae8ebc1bac07c9fa4'),
|
||||
ObjectId('5c41deb2b4ca500153340809')
|
||||
@@ -53,7 +53,7 @@ describe('ProjectHelper', function() {
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if user id is not found', function() {
|
||||
it('returns false if user id is not found', function () {
|
||||
this.project.archived = []
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
@@ -61,15 +61,15 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being a boolean', function() {
|
||||
it('returns true if archived is true', function() {
|
||||
describe('project.archived being a boolean', function () {
|
||||
it('returns true if archived is true', function () {
|
||||
this.project.archived = true
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if archived is false', function() {
|
||||
it('returns false if archived is false', function () {
|
||||
this.project.archived = false
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
@@ -77,8 +77,8 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being undefined', function() {
|
||||
it('returns false if archived is undefined', function() {
|
||||
describe('project.archived being undefined', function () {
|
||||
it('returns false if archived is undefined', function () {
|
||||
this.project.archived = undefined
|
||||
expect(
|
||||
this.ProjectHelper.isArchived(this.project, this.user._id)
|
||||
@@ -87,8 +87,8 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('isTrashed', function() {
|
||||
it('returns true if user id is found', function() {
|
||||
describe('isTrashed', function () {
|
||||
it('returns true if user id is found', function () {
|
||||
this.project.trashed = [
|
||||
ObjectId('588f3ddae8ebc1bac07c9fa4'),
|
||||
ObjectId('5c41deb2b4ca500153340809')
|
||||
@@ -98,15 +98,15 @@ describe('ProjectHelper', function() {
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('returns false if user id is not found', function() {
|
||||
it('returns false if user id is not found', function () {
|
||||
this.project.trashed = []
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
).to.equal(false)
|
||||
})
|
||||
|
||||
describe('project.trashed being undefined', function() {
|
||||
it('returns false if trashed is undefined', function() {
|
||||
describe('project.trashed being undefined', function () {
|
||||
it('returns false if trashed is undefined', function () {
|
||||
this.project.trashed = undefined
|
||||
expect(
|
||||
this.ProjectHelper.isTrashed(this.project, this.user._id)
|
||||
@@ -115,9 +115,9 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('calculateArchivedArray', function() {
|
||||
describe('project.archived being an array', function() {
|
||||
it('returns an array adding the current user id when archiving', function() {
|
||||
describe('calculateArchivedArray', function () {
|
||||
describe('project.archived being an array', function () {
|
||||
it('returns an array adding the current user id when archiving', function () {
|
||||
const project = { archived: [] }
|
||||
const result = this.ProjectHelper.calculateArchivedArray(
|
||||
project,
|
||||
@@ -127,7 +127,7 @@ describe('ProjectHelper', function() {
|
||||
expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')])
|
||||
})
|
||||
|
||||
it('returns an array without the current user id when unarchiving', function() {
|
||||
it('returns an array without the current user id when unarchiving', function () {
|
||||
const project = { archived: [ObjectId('5c922599cdb09e014aa7d499')] }
|
||||
const result = this.ProjectHelper.calculateArchivedArray(
|
||||
project,
|
||||
@@ -138,8 +138,8 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being a boolean and being true', function() {
|
||||
it('returns an array of all associated user ids when archiving', function() {
|
||||
describe('project.archived being a boolean and being true', function () {
|
||||
it('returns an array of all associated user ids when archiving', function () {
|
||||
const project = {
|
||||
archived: true,
|
||||
owner_ref: this.user._id,
|
||||
@@ -166,7 +166,7 @@ describe('ProjectHelper', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('returns an array of all associated users without the current user id when unarchived', function() {
|
||||
it('returns an array of all associated users without the current user id when unarchived', function () {
|
||||
const project = {
|
||||
archived: true,
|
||||
owner_ref: this.user._id,
|
||||
@@ -194,8 +194,8 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived being a boolean and being false', function() {
|
||||
it('returns an array adding the current user id when archiving', function() {
|
||||
describe('project.archived being a boolean and being false', function () {
|
||||
it('returns an array adding the current user id when archiving', function () {
|
||||
const project = { archived: false }
|
||||
const result = this.ProjectHelper.calculateArchivedArray(
|
||||
project,
|
||||
@@ -205,7 +205,7 @@ describe('ProjectHelper', function() {
|
||||
expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')])
|
||||
})
|
||||
|
||||
it('returns an empty array when unarchiving', function() {
|
||||
it('returns an empty array when unarchiving', function () {
|
||||
const project = { archived: false }
|
||||
const result = this.ProjectHelper.calculateArchivedArray(
|
||||
project,
|
||||
@@ -216,8 +216,8 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('project.archived not being set', function() {
|
||||
it('returns an array adding the current user id when archiving', function() {
|
||||
describe('project.archived not being set', function () {
|
||||
it('returns an array adding the current user id when archiving', function () {
|
||||
const project = { archived: undefined }
|
||||
const result = this.ProjectHelper.calculateArchivedArray(
|
||||
project,
|
||||
@@ -227,7 +227,7 @@ describe('ProjectHelper', function() {
|
||||
expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')])
|
||||
})
|
||||
|
||||
it('returns an empty array when unarchiving', function() {
|
||||
it('returns an empty array when unarchiving', function () {
|
||||
const project = { archived: undefined }
|
||||
const result = this.ProjectHelper.calculateArchivedArray(
|
||||
project,
|
||||
@@ -239,34 +239,34 @@ describe('ProjectHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('compilerFromV1Engine', function() {
|
||||
it('returns the correct engine for latex_dvipdf', function() {
|
||||
describe('compilerFromV1Engine', function () {
|
||||
it('returns the correct engine for latex_dvipdf', function () {
|
||||
expect(this.ProjectHelper.compilerFromV1Engine('latex_dvipdf')).to.equal(
|
||||
'latex'
|
||||
)
|
||||
})
|
||||
|
||||
it('returns the correct engine for pdflatex', function() {
|
||||
it('returns the correct engine for pdflatex', function () {
|
||||
expect(this.ProjectHelper.compilerFromV1Engine('pdflatex')).to.equal(
|
||||
'pdflatex'
|
||||
)
|
||||
})
|
||||
|
||||
it('returns the correct engine for xelatex', function() {
|
||||
it('returns the correct engine for xelatex', function () {
|
||||
expect(this.ProjectHelper.compilerFromV1Engine('xelatex')).to.equal(
|
||||
'xelatex'
|
||||
)
|
||||
})
|
||||
|
||||
it('returns the correct engine for lualatex', function() {
|
||||
it('returns the correct engine for lualatex', function () {
|
||||
expect(this.ProjectHelper.compilerFromV1Engine('lualatex')).to.equal(
|
||||
'lualatex'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAllowedImagesForUser', function() {
|
||||
it('filters out admin-only images when the user is anonymous', function() {
|
||||
describe('getAllowedImagesForUser', function () {
|
||||
it('filters out admin-only images when the user is anonymous', function () {
|
||||
const images = this.ProjectHelper.getAllowedImagesForUser(null)
|
||||
const imageNames = images.map(image => image.imageName)
|
||||
expect(imageNames).to.deep.equal([
|
||||
@@ -275,7 +275,7 @@ describe('ProjectHelper', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('filters out admin-only images when the user is not admin', function() {
|
||||
it('filters out admin-only images when the user is not admin', function () {
|
||||
const images = this.ProjectHelper.getAllowedImagesForUser(this.user)
|
||||
const imageNames = images.map(image => image.imageName)
|
||||
expect(imageNames).to.deep.equal([
|
||||
@@ -284,7 +284,7 @@ describe('ProjectHelper', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('returns all images when the user is admin', function() {
|
||||
it('returns all images when the user is admin', function () {
|
||||
const images = this.ProjectHelper.getAllowedImagesForUser(this.adminUser)
|
||||
const imageNames = images.map(image => image.imageName)
|
||||
expect(imageNames).to.deep.equal([
|
||||
|
||||
@@ -17,13 +17,13 @@ const sinon = require('sinon')
|
||||
const modulePath = '../../../../app/src/Features/Project/ProjectHistoryHandler'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('ProjectHistoryHandler', function() {
|
||||
describe('ProjectHistoryHandler', function () {
|
||||
const project_id = '4eecb1c1bffa66588e0000a1'
|
||||
const userId = 1234
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
let Project
|
||||
this.ProjectModel = Project = (function() {
|
||||
this.ProjectModel = Project = (function () {
|
||||
Project = class Project {
|
||||
static initClass() {
|
||||
this.prototype.rootFolder = [this.rootFolder]
|
||||
@@ -55,8 +55,8 @@ describe('ProjectHistoryHandler', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('starting history for an existing project', function() {
|
||||
beforeEach(function() {
|
||||
describe('starting history for an existing project', function () {
|
||||
beforeEach(function () {
|
||||
this.newHistoryId = 123456789
|
||||
this.HistoryManager.initializeProject = sinon
|
||||
.stub()
|
||||
@@ -67,8 +67,8 @@ describe('ProjectHistoryHandler', function() {
|
||||
.callsArg(1))
|
||||
})
|
||||
|
||||
describe('when the history does not already exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the history does not already exist', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectDetailsHandler.getDetails = sinon
|
||||
.stub()
|
||||
.withArgs(project_id)
|
||||
@@ -82,17 +82,17 @@ describe('ProjectHistoryHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should get any existing history id for the project', function() {
|
||||
it('should get any existing history id for the project', function () {
|
||||
return this.ProjectDetailsHandler.getDetails
|
||||
.calledWith(project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should initialize a new history in the v1 history service', function() {
|
||||
it('should initialize a new history in the v1 history service', function () {
|
||||
return this.HistoryManager.initializeProject.called.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the new history id on the project', function() {
|
||||
it('should set the new history id on the project', function () {
|
||||
return this.ProjectModel.updateOne
|
||||
.calledWith(
|
||||
{ _id: project_id, 'overleaf.history.id': { $exists: false } },
|
||||
@@ -101,25 +101,25 @@ describe('ProjectHistoryHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should resync the project history', function() {
|
||||
it('should resync the project history', function () {
|
||||
return this.ProjectEntityUpdateHandler.resyncProjectHistory
|
||||
.calledWith(project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should flush the project history', function() {
|
||||
it('should flush the project history', function () {
|
||||
return this.HistoryManager.flushProject
|
||||
.calledWith(project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback without an error', function() {
|
||||
it('should call the callback without an error', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the history already exists', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the history already exists', function () {
|
||||
beforeEach(function () {
|
||||
this.project.overleaf = { history: { id: 1234 } }
|
||||
this.ProjectDetailsHandler.getDetails = sinon
|
||||
.stub()
|
||||
@@ -132,31 +132,31 @@ describe('ProjectHistoryHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should get any existing history id for the project', function() {
|
||||
it('should get any existing history id for the project', function () {
|
||||
return this.ProjectDetailsHandler.getDetails
|
||||
.calledWith(project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not initialize a new history in the v1 history service', function() {
|
||||
it('should not initialize a new history in the v1 history service', function () {
|
||||
return this.HistoryManager.initializeProject.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not set the new history id on the project', function() {
|
||||
it('should not set the new history id on the project', function () {
|
||||
return this.ProjectModel.updateOne.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not resync the project history', function() {
|
||||
it('should not resync the project history', function () {
|
||||
return this.ProjectEntityUpdateHandler.resyncProjectHistory.called.should.equal(
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
it('should not flush the project history', function() {
|
||||
it('should not flush the project history', function () {
|
||||
return this.HistoryManager.flushProject.called.should.equal(false)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.calledWith().should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -38,8 +38,8 @@ const rootFolder = {
|
||||
project.rootFolder[0] = rootFolder
|
||||
project.rootDoc_id = rootDoc._id
|
||||
|
||||
describe('ProjectLocator', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectLocator', function () {
|
||||
beforeEach(function () {
|
||||
Project.findById = (projectId, callback) => {
|
||||
callback(null, project)
|
||||
}
|
||||
@@ -61,8 +61,8 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('finding a doc', function() {
|
||||
it('finds one at the root level', function(done) {
|
||||
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) => {
|
||||
@@ -78,7 +78,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('when it is nested', function(done) {
|
||||
it('when it is nested', function (done) {
|
||||
this.locator.findElement(
|
||||
{ project_id: project._id, element_id: subSubDoc._id, type: 'doc' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
@@ -96,7 +96,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should give error if element could not be found', function(done) {
|
||||
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) => {
|
||||
@@ -108,8 +108,8 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('finding a folder', function() {
|
||||
it('should return root folder when looking for root folder', function(done) {
|
||||
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) => {
|
||||
@@ -122,7 +122,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('when at root', function(done) {
|
||||
it('when at root', function (done) {
|
||||
this.locator.findElement(
|
||||
{ project_id: project._id, element_id: subFolder._id, type: 'folder' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
@@ -138,7 +138,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('when deeply nested', function(done) {
|
||||
it('when deeply nested', function (done) {
|
||||
this.locator.findElement(
|
||||
{
|
||||
project_id: project._id,
|
||||
@@ -161,8 +161,8 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('finding a file', function() {
|
||||
it('when at root', function(done) {
|
||||
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) => {
|
||||
@@ -178,7 +178,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('when deeply nested', function(done) {
|
||||
it('when deeply nested', function (done) {
|
||||
this.locator.findElement(
|
||||
{
|
||||
project_id: project._id,
|
||||
@@ -201,8 +201,8 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('finding an element with wrong element type', function() {
|
||||
it('should add an s onto the element type', function(done) {
|
||||
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) => {
|
||||
@@ -215,7 +215,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should convert file to fileRefs', function(done) {
|
||||
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) => {
|
||||
@@ -229,7 +229,7 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('should be able to take actual project as well as id', function() {
|
||||
describe('should be able to take actual project as well as id', function () {
|
||||
const doc3 = {
|
||||
_id: '123dsdj3',
|
||||
name: 'doc3'
|
||||
@@ -242,7 +242,7 @@ describe('ProjectLocator', function() {
|
||||
_id: '1234566',
|
||||
rootFolder: [rootFolder2]
|
||||
}
|
||||
it('should find doc in project', function(done) {
|
||||
it('should find doc in project', function (done) {
|
||||
this.locator.findElement(
|
||||
{ project: project2, element_id: doc3._id, type: 'docs' },
|
||||
(err, foundElement, path, parentFolder) => {
|
||||
@@ -259,8 +259,8 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('finding root doc', function() {
|
||||
it('should return root doc when passed project', function(done) {
|
||||
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)
|
||||
@@ -270,7 +270,7 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should return root doc when passed project_id', function(done) {
|
||||
it('should return root doc when passed project_id', function (done) {
|
||||
this.locator.findRootDoc(project._id, (err, doc) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
@@ -280,7 +280,7 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should return null when the project has no rootDoc', function(done) {
|
||||
it('should return null when the project has no rootDoc', function (done) {
|
||||
project.rootDoc_id = null
|
||||
this.locator.findRootDoc(project, (err, doc) => {
|
||||
if (err != null) {
|
||||
@@ -291,7 +291,7 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should return null when the rootDoc_id no longer exists', function(done) {
|
||||
it('should return null when the rootDoc_id no longer exists', function (done) {
|
||||
project.rootDoc_id = 'doesntexist'
|
||||
this.locator.findRootDoc(project, (err, doc) => {
|
||||
if (err != null) {
|
||||
@@ -303,8 +303,8 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('findElementByPath', function() {
|
||||
it('should take a doc path and return the element for a root level document', function(done) {
|
||||
describe('findElementByPath', function () {
|
||||
it('should take a doc path and return the element for a root level document', function (done) {
|
||||
const path = `${doc1.name}`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -319,7 +319,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a doc path and return the element for a root level document with a starting slash', function(done) {
|
||||
it('should take a doc path and return the element for a root level document with a starting slash', function (done) {
|
||||
const path = `/${doc1.name}`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -334,7 +334,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a doc path and return the element for a nested document', function(done) {
|
||||
it('should take a doc path and return the element for a nested document', function (done) {
|
||||
const path = `${subFolder.name}/${secondSubFolder.name}/${subSubDoc.name}`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -349,7 +349,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a file path and return the element for a root level document', function(done) {
|
||||
it('should take a file path and return the element for a root level document', function (done) {
|
||||
const path = `${file1.name}`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -364,7 +364,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
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', function (done) {
|
||||
const path = `${subFolder.name}/${secondSubFolder.name}/${subSubFile.name}`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -379,7 +379,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a file path and return the element for a nested document case insenstive', function(done) {
|
||||
it('should take a file path and return the element for a nested document case insenstive', function (done) {
|
||||
const path = `${subFolder.name.toUpperCase()}/${secondSubFolder.name.toUpperCase()}/${subSubFile.name.toUpperCase()}`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -394,7 +394,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a file path and return the element for a nested folder', function(done) {
|
||||
it('should take a file path and return the element for a nested folder', function (done) {
|
||||
const path = `${subFolder.name}/${secondSubFolder.name}`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -409,7 +409,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should take a file path and return the root folder', function(done) {
|
||||
it('should take a file path and return the root folder', function (done) {
|
||||
const path = '/'
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -424,7 +424,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an error if the file can not be found inside know folder', function(done) {
|
||||
it('should return an error if the file can not be found inside know folder', function (done) {
|
||||
const path = `${subFolder.name}/${secondSubFolder.name}/exist.txt`
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -437,7 +437,7 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an error if the file can not be found inside unknown folder', function(done) {
|
||||
it('should return an error if the file can not be found inside unknown folder', function (done) {
|
||||
const path = 'this/does/not/exist.txt'
|
||||
this.locator.findElementByPath(
|
||||
{ project, path },
|
||||
@@ -450,8 +450,8 @@ describe('ProjectLocator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
describe('where duplicate folder exists', function() {
|
||||
beforeEach(function() {
|
||||
describe('where duplicate folder exists', function () {
|
||||
beforeEach(function () {
|
||||
this.duplicateFolder = {
|
||||
name: 'duplicate1',
|
||||
_id: '1234',
|
||||
@@ -477,14 +477,14 @@ describe('ProjectLocator', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('should not call the callback more than once', function(done) {
|
||||
it('should not call the callback more than once', function (done) {
|
||||
const path = `${this.duplicateFolder.name}/${this.doc.name}`
|
||||
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) {
|
||||
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`
|
||||
this.locator.findElementByPath({ project: this.project, path }, () =>
|
||||
done()
|
||||
@@ -492,8 +492,8 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
}) // mocha will throw exception if done called multiple times
|
||||
|
||||
describe('with a null doc', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a null doc', function () {
|
||||
beforeEach(function () {
|
||||
this.project = {
|
||||
rootFolder: [
|
||||
{
|
||||
@@ -505,7 +505,7 @@ describe('ProjectLocator', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('should not crash with a null', function(done) {
|
||||
it('should not crash with a null', function (done) {
|
||||
const path = '/other.tex'
|
||||
this.locator.findElementByPath(
|
||||
{ project: this.project, path },
|
||||
@@ -520,12 +520,12 @@ describe('ProjectLocator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a null project', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a null project', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter = { getProject: sinon.stub().callsArg(2) }
|
||||
})
|
||||
|
||||
it('should not crash with a null', function(done) {
|
||||
it('should not crash with a null', function (done) {
|
||||
const path = '/other.tex'
|
||||
this.locator.findElementByPath(
|
||||
{ project_id: project._id, path },
|
||||
@@ -537,8 +537,8 @@ 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) {
|
||||
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}`
|
||||
this.locator.findElementByPath(
|
||||
{ project_id: project._id, path },
|
||||
|
||||
@@ -19,10 +19,10 @@ const modulePath =
|
||||
'../../../../app/src/Features/Project/ProjectOptionsHandler.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('ProjectOptionsHandler', function() {
|
||||
describe('ProjectOptionsHandler', function () {
|
||||
const project_id = '4eecaffcbffa66588e000008'
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
let Project
|
||||
this.projectModel = Project = class Project {
|
||||
constructor(options) {}
|
||||
@@ -47,8 +47,8 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Setting the compiler', function() {
|
||||
it('should perform and update on mongo', function(done) {
|
||||
describe('Setting the compiler', function () {
|
||||
it('should perform and update on mongo', function (done) {
|
||||
this.handler.setCompiler(project_id, 'xeLaTeX', err => {
|
||||
const args = this.projectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(project_id)
|
||||
@@ -57,15 +57,15 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not perform and update on mongo if it is not a recognised compiler', function(done) {
|
||||
it('should not perform and update on mongo if it is not a recognised compiler', function (done) {
|
||||
this.handler.setCompiler(project_id, 'something', err => {
|
||||
this.projectModel.updateOne.called.should.equal(false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when called without arg', function() {
|
||||
it('should callback with null', function(done) {
|
||||
describe('when called without arg', function () {
|
||||
it('should callback with null', function (done) {
|
||||
this.handler.setCompiler(project_id, null, err => {
|
||||
expect(err).to.be.undefined
|
||||
this.projectModel.updateOne.callCount.should.equal(0)
|
||||
@@ -74,12 +74,12 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when mongo update error occurs', function() {
|
||||
beforeEach(function() {
|
||||
describe('when mongo update error occurs', function () {
|
||||
beforeEach(function () {
|
||||
this.projectModel.updateOne = sinon.stub().yields('error')
|
||||
})
|
||||
|
||||
it('should callback with error', function(done) {
|
||||
it('should callback with error', function (done) {
|
||||
this.handler.setCompiler(project_id, 'xeLaTeX', err => {
|
||||
err.should.equal('error')
|
||||
done()
|
||||
@@ -88,8 +88,8 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Setting the imageName', function() {
|
||||
it('should perform and update on mongo', function(done) {
|
||||
describe('Setting the imageName', function () {
|
||||
it('should perform and update on mongo', function (done) {
|
||||
this.handler.setImageName(project_id, 'texlive-1234.5', err => {
|
||||
const args = this.projectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(project_id)
|
||||
@@ -98,15 +98,15 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
|
||||
it('should not perform and update on mongo if it is not a reconised compiler', function (done) {
|
||||
this.handler.setImageName(project_id, 'something', err => {
|
||||
this.projectModel.updateOne.called.should.equal(false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when called without arg', function() {
|
||||
it('should callback with null', function(done) {
|
||||
describe('when called without arg', function () {
|
||||
it('should callback with null', function (done) {
|
||||
this.handler.setImageName(project_id, null, err => {
|
||||
expect(err).to.be.undefined
|
||||
this.projectModel.updateOne.callCount.should.equal(0)
|
||||
@@ -115,12 +115,12 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when mongo update error occurs', function() {
|
||||
beforeEach(function() {
|
||||
describe('when mongo update error occurs', function () {
|
||||
beforeEach(function () {
|
||||
this.projectModel.updateOne = sinon.stub().yields('error')
|
||||
})
|
||||
|
||||
it('should callback with error', function(done) {
|
||||
it('should callback with error', function (done) {
|
||||
this.handler.setImageName(project_id, 'texlive-1234.5', err => {
|
||||
err.should.equal('error')
|
||||
done()
|
||||
@@ -129,8 +129,8 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setting the spellCheckLanguage', function() {
|
||||
it('should perform and update on mongo', function(done) {
|
||||
describe('setting the spellCheckLanguage', function () {
|
||||
it('should perform and update on mongo', function (done) {
|
||||
this.handler.setSpellCheckLanguage(project_id, 'fr', err => {
|
||||
const args = this.projectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(project_id)
|
||||
@@ -139,26 +139,26 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
|
||||
it('should not perform and update on mongo if it is not a reconised compiler', function (done) {
|
||||
this.handler.setSpellCheckLanguage(project_id, 'no a lang', err => {
|
||||
this.projectModel.updateOne.called.should.equal(false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should perform and update on mongo if the language is blank (means turn it off)', function(done) {
|
||||
it('should perform and update on mongo if the language is blank (means turn it off)', function (done) {
|
||||
this.handler.setSpellCheckLanguage(project_id, '', err => {
|
||||
this.projectModel.updateOne.called.should.equal(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when mongo update error occurs', function() {
|
||||
beforeEach(function() {
|
||||
describe('when mongo update error occurs', function () {
|
||||
beforeEach(function () {
|
||||
this.projectModel.updateOne = sinon.stub().yields('error')
|
||||
})
|
||||
|
||||
it('should callback with error', function(done) {
|
||||
it('should callback with error', function (done) {
|
||||
this.handler.setSpellCheckLanguage(project_id, 'fr', err => {
|
||||
err.should.equal('error')
|
||||
done()
|
||||
@@ -167,8 +167,8 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setting the brandVariationId', function() {
|
||||
it('should perform and update on mongo', function(done) {
|
||||
describe('setting the brandVariationId', function () {
|
||||
it('should perform and update on mongo', function (done) {
|
||||
this.handler.setBrandVariationId(project_id, '123', err => {
|
||||
const args = this.projectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(project_id)
|
||||
@@ -177,26 +177,26 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not perform and update on mongo if there is no brand variation', function(done) {
|
||||
it('should not perform and update on mongo if there is no brand variation', function (done) {
|
||||
this.handler.setBrandVariationId(project_id, null, err => {
|
||||
this.projectModel.updateOne.called.should.equal(false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not perform and update on mongo if brand variation is an empty string', function(done) {
|
||||
it('should not perform and update on mongo if brand variation is an empty string', function (done) {
|
||||
this.handler.setBrandVariationId(project_id, '', err => {
|
||||
this.projectModel.updateOne.called.should.equal(false)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when mongo update error occurs', function() {
|
||||
beforeEach(function() {
|
||||
describe('when mongo update error occurs', function () {
|
||||
beforeEach(function () {
|
||||
this.projectModel.updateOne = sinon.stub().yields('error')
|
||||
})
|
||||
|
||||
it('should callback with error', function(done) {
|
||||
it('should callback with error', function (done) {
|
||||
this.handler.setBrandVariationId(project_id, '123', err => {
|
||||
err.should.equal('error')
|
||||
done()
|
||||
@@ -205,8 +205,8 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('unsetting the brandVariationId', function() {
|
||||
it('should perform and update on mongo', function(done) {
|
||||
describe('unsetting the brandVariationId', function () {
|
||||
it('should perform and update on mongo', function (done) {
|
||||
this.handler.unsetBrandVariationId(project_id, err => {
|
||||
const args = this.projectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(project_id)
|
||||
@@ -215,12 +215,12 @@ describe('ProjectOptionsHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when mongo update error occurs', function() {
|
||||
beforeEach(function() {
|
||||
describe('when mongo update error occurs', function () {
|
||||
beforeEach(function () {
|
||||
this.projectModel.updateOne = sinon.stub().yields('error')
|
||||
})
|
||||
|
||||
it('should callback with error', function(done) {
|
||||
it('should callback with error', function (done) {
|
||||
this.handler.unsetBrandVariationId(project_id, err => {
|
||||
err.should.equal('error')
|
||||
done()
|
||||
|
||||
@@ -17,8 +17,8 @@ const modulePath =
|
||||
'../../../../app/src/Features/Project/ProjectRootDocManager.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('ProjectRootDocManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectRootDocManager', function () {
|
||||
beforeEach(function () {
|
||||
this.project_id = 'project-123'
|
||||
this.docPaths = {
|
||||
'doc-id-1': '/chapter1.tex',
|
||||
@@ -49,15 +49,15 @@ describe('ProjectRootDocManager', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('setRootDocAutomatically', function() {
|
||||
beforeEach(function() {
|
||||
describe('setRootDocAutomatically', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
||||
this.ProjectEntityUpdateHandler.isPathValidForRootDoc = sinon
|
||||
.stub()
|
||||
.returns(true)
|
||||
})
|
||||
describe('when there is a suitable root doc', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when there is a suitable root doc', function () {
|
||||
beforeEach(function (done) {
|
||||
this.docs = {
|
||||
'/chapter1.tex': {
|
||||
_id: 'doc-id-1',
|
||||
@@ -94,21 +94,21 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check the docs of the project', function() {
|
||||
it('should check the docs of the project', function () {
|
||||
return this.ProjectEntityHandler.getAllDocs
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the root doc to the doc containing a documentclass', function() {
|
||||
it('should set the root doc to the doc containing a documentclass', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(this.project_id, 'doc-id-2')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the root doc is an Rtex file', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when the root doc is an Rtex file', function () {
|
||||
beforeEach(function (done) {
|
||||
this.docs = {
|
||||
'/chapter1.tex': {
|
||||
_id: 'doc-id-1',
|
||||
@@ -128,15 +128,15 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the root doc to the doc containing a documentclass', function() {
|
||||
it('should set the root doc to the doc containing a documentclass', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(this.project_id, 'doc-id-2')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is no suitable root doc', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when there is no suitable root doc', function () {
|
||||
beforeEach(function (done) {
|
||||
this.docs = {
|
||||
'/chapter1.tex': {
|
||||
_id: 'doc-id-1',
|
||||
@@ -156,7 +156,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the root doc to the doc containing a documentclass', function() {
|
||||
it('should not set the root doc to the doc containing a documentclass', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc.called.should.equal(
|
||||
false
|
||||
)
|
||||
@@ -164,8 +164,8 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('findRootDocFileFromDirectory', function() {
|
||||
beforeEach(function() {
|
||||
describe('findRootDocFileFromDirectory', function () {
|
||||
beforeEach(function () {
|
||||
this.fs.readFile
|
||||
.withArgs('/foo/a.tex')
|
||||
.callsArgWith(2, null, 'Hello World!')
|
||||
@@ -184,8 +184,8 @@ describe('ProjectRootDocManager', function() {
|
||||
return (this.documentclassContent = '% test\n\\documentclass\n% test')
|
||||
})
|
||||
|
||||
describe('when there is a file in a subfolder', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there is a file in a subfolder', function () {
|
||||
beforeEach(function () {
|
||||
// have to splice globbyFiles weirdly because of the way the stubbed globby method handles references
|
||||
return this.globbyFiles.splice(
|
||||
0,
|
||||
@@ -197,7 +197,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('processes the root folder files first, and then the subfolder, in alphabetical order', function(done) {
|
||||
it('processes the root folder files first, and then the subfolder, in alphabetical order', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
(error, path) => {
|
||||
@@ -214,7 +214,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('processes smaller files first', function(done) {
|
||||
it('processes smaller files first', function (done) {
|
||||
this.fs.stat.withArgs('/foo/c.tex').callsArgWith(1, null, { size: 1 })
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
@@ -233,14 +233,14 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when main.tex contains a documentclass', function() {
|
||||
beforeEach(function() {
|
||||
describe('when main.tex contains a documentclass', function () {
|
||||
beforeEach(function () {
|
||||
return this.fs.readFile
|
||||
.withArgs('/foo/main.tex')
|
||||
.callsArgWith(2, null, this.documentclassContent)
|
||||
})
|
||||
|
||||
it('returns main.tex', function(done) {
|
||||
it('returns main.tex', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
(error, path, content) => {
|
||||
@@ -252,7 +252,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('processes main.text first and stops processing when it finds the content', function(done) {
|
||||
it('processes main.text first and stops processing when it finds the content', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
() => {
|
||||
@@ -264,14 +264,14 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a.tex contains a documentclass', function() {
|
||||
beforeEach(function() {
|
||||
describe('when a.tex contains a documentclass', function () {
|
||||
beforeEach(function () {
|
||||
return this.fs.readFile
|
||||
.withArgs('/foo/a.tex')
|
||||
.callsArgWith(2, null, this.documentclassContent)
|
||||
})
|
||||
|
||||
it('returns a.tex', function(done) {
|
||||
it('returns a.tex', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
(error, path, content) => {
|
||||
@@ -283,7 +283,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('processes main.text first and stops processing when it finds the content', function(done) {
|
||||
it('processes main.text first and stops processing when it finds the content', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
() => {
|
||||
@@ -296,8 +296,8 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is no documentclass', function() {
|
||||
it('returns null with no error', function(done) {
|
||||
describe('when there is no documentclass', function () {
|
||||
it('returns null with no error', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
(error, path, content) => {
|
||||
@@ -309,7 +309,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('processes all the files', function(done) {
|
||||
it('processes all the files', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
() => {
|
||||
@@ -322,14 +322,14 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is an error reading a file', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there is an error reading a file', function () {
|
||||
beforeEach(function () {
|
||||
return this.fs.readFile
|
||||
.withArgs('/foo/a.tex')
|
||||
.callsArgWith(2, new Error('something went wrong'))
|
||||
})
|
||||
|
||||
it('returns an error', function(done) {
|
||||
it('returns an error', function (done) {
|
||||
return this.ProjectRootDocManager.findRootDocFileFromDirectory(
|
||||
'/foo',
|
||||
(error, path, content) => {
|
||||
@@ -343,9 +343,9 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setRootDocFromName', function() {
|
||||
describe('when there is a suitable root doc', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('setRootDocFromName', function () {
|
||||
describe('when there is a suitable root doc', function () {
|
||||
beforeEach(function (done) {
|
||||
this.docPaths = {
|
||||
'doc-id-1': '/chapter1.tex',
|
||||
'doc-id-2': '/main.tex',
|
||||
@@ -365,21 +365,21 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check the docs of the project', function() {
|
||||
it('should check the docs of the project', function () {
|
||||
return this.ProjectEntityHandler.getAllDocPathsFromProjectById
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the root doc to main.tex', function() {
|
||||
it('should set the root doc to main.tex', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(this.project_id, 'doc-id-2')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is a suitable root doc but the leading slash is missing', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when there is a suitable root doc but the leading slash is missing', function () {
|
||||
beforeEach(function (done) {
|
||||
this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.docPaths)
|
||||
@@ -393,21 +393,21 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check the docs of the project', function() {
|
||||
it('should check the docs of the project', function () {
|
||||
return this.ProjectEntityHandler.getAllDocPathsFromProjectById
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the root doc to main.tex', function() {
|
||||
it('should set the root doc to main.tex', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(this.project_id, 'doc-id-2')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is a suitable root doc with a basename match', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when there is a suitable root doc with a basename match', function () {
|
||||
beforeEach(function (done) {
|
||||
this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.docPaths)
|
||||
@@ -421,21 +421,21 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check the docs of the project', function() {
|
||||
it('should check the docs of the project', function () {
|
||||
return this.ProjectEntityHandler.getAllDocPathsFromProjectById
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the root doc using the basename', function() {
|
||||
it('should set the root doc using the basename', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(this.project_id, 'doc-id-3')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is a suitable root doc but the filename is in quotes', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when there is a suitable root doc but the filename is in quotes', function () {
|
||||
beforeEach(function (done) {
|
||||
this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.docPaths)
|
||||
@@ -449,21 +449,21 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should check the docs of the project', function() {
|
||||
it('should check the docs of the project', function () {
|
||||
return this.ProjectEntityHandler.getAllDocPathsFromProjectById
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the root doc to main.tex', function() {
|
||||
it('should set the root doc to main.tex', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc
|
||||
.calledWith(this.project_id, 'doc-id-2')
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is no suitable root doc', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('when there is no suitable root doc', function () {
|
||||
beforeEach(function (done) {
|
||||
this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.docPaths)
|
||||
@@ -477,7 +477,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not set the root doc', function() {
|
||||
it('should not set the root doc', function () {
|
||||
return this.ProjectEntityUpdateHandler.setRootDoc.called.should.equal(
|
||||
false
|
||||
)
|
||||
@@ -485,8 +485,8 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ensureRootDocumentIsSet', function() {
|
||||
beforeEach(function() {
|
||||
describe('ensureRootDocumentIsSet', function () {
|
||||
beforeEach(function () {
|
||||
this.project = {}
|
||||
this.ProjectGetter.getProject = sinon
|
||||
.stub()
|
||||
@@ -496,8 +496,8 @@ describe('ProjectRootDocManager', function() {
|
||||
.callsArgWith(1, null))
|
||||
})
|
||||
|
||||
describe('when the root doc is set', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the root doc is set', function () {
|
||||
beforeEach(function () {
|
||||
this.project.rootDoc_id = 'root-doc-id'
|
||||
return this.ProjectRootDocManager.ensureRootDocumentIsSet(
|
||||
this.project_id,
|
||||
@@ -505,50 +505,50 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should find the project fetching only the rootDoc_id field', function() {
|
||||
it('should find the project fetching only the rootDoc_id field', function () {
|
||||
return this.ProjectGetter.getProject
|
||||
.calledWith(this.project_id, { rootDoc_id: 1 })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not try to update the project rootDoc_id', function() {
|
||||
it('should not try to update the project rootDoc_id', function () {
|
||||
return this.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the root doc is not set', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the root doc is not set', function () {
|
||||
beforeEach(function () {
|
||||
return this.ProjectRootDocManager.ensureRootDocumentIsSet(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should find the project with only the rootDoc_id field', function() {
|
||||
it('should find the project with only the rootDoc_id field', function () {
|
||||
return this.ProjectGetter.getProject
|
||||
.calledWith(this.project_id, { rootDoc_id: 1 })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should update the project rootDoc_id', function() {
|
||||
it('should update the project rootDoc_id', function () {
|
||||
return this.ProjectRootDocManager.setRootDocAutomatically
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the project does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the project does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)
|
||||
return this.ProjectRootDocManager.ensureRootDocumentIsSet(
|
||||
this.project_id,
|
||||
@@ -556,7 +556,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
@@ -568,8 +568,8 @@ describe('ProjectRootDocManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ensureRootDocumentIsValid', function() {
|
||||
beforeEach(function() {
|
||||
describe('ensureRootDocumentIsValid', function () {
|
||||
beforeEach(function () {
|
||||
this.project = {}
|
||||
this.ProjectGetter.getProject = sinon
|
||||
.stub()
|
||||
@@ -584,9 +584,9 @@ describe('ProjectRootDocManager', function() {
|
||||
.callsArgWith(1, null))
|
||||
})
|
||||
|
||||
describe('when the root doc is set', function() {
|
||||
describe('when the root doc is valid', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the root doc is set', function () {
|
||||
describe('when the root doc is valid', function () {
|
||||
beforeEach(function () {
|
||||
this.project.rootDoc_id = 'doc-id-2'
|
||||
return this.ProjectRootDocManager.ensureRootDocumentIsValid(
|
||||
this.project_id,
|
||||
@@ -594,25 +594,25 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should find the project fetching only the rootDoc_id field', function() {
|
||||
it('should find the project fetching only the rootDoc_id field', function () {
|
||||
return this.ProjectGetter.getProject
|
||||
.calledWith(this.project_id, { rootDoc_id: 1 })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not try to update the project rootDoc_id', function() {
|
||||
it('should not try to update the project rootDoc_id', function () {
|
||||
return this.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
|
||||
false
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the root doc is not valid', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the root doc is not valid', function () {
|
||||
beforeEach(function () {
|
||||
this.project.rootDoc_id = 'bogus-doc-id'
|
||||
return this.ProjectRootDocManager.ensureRootDocumentIsValid(
|
||||
this.project_id,
|
||||
@@ -620,57 +620,57 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should find the project fetching only the rootDoc_id field', function() {
|
||||
it('should find the project fetching only the rootDoc_id field', function () {
|
||||
return this.ProjectGetter.getProject
|
||||
.calledWith(this.project_id, { rootDoc_id: 1 })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should unset the root doc', function() {
|
||||
it('should unset the root doc', function () {
|
||||
return this.ProjectEntityUpdateHandler.unsetRootDoc
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should try to find a new rootDoc', function() {
|
||||
it('should try to find a new rootDoc', function () {
|
||||
return this.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the root doc is not set', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the root doc is not set', function () {
|
||||
beforeEach(function () {
|
||||
return this.ProjectRootDocManager.ensureRootDocumentIsSet(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should find the project fetching only the rootDoc_id fiel', function() {
|
||||
it('should find the project fetching only the rootDoc_id fiel', function () {
|
||||
return this.ProjectGetter.getProject
|
||||
.calledWith(this.project_id, { rootDoc_id: 1 })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should update the project rootDoc_id', function() {
|
||||
it('should update the project rootDoc_id', function () {
|
||||
return this.ProjectRootDocManager.setRootDocAutomatically
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the project does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the project does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)
|
||||
return this.ProjectRootDocManager.ensureRootDocumentIsSet(
|
||||
this.project_id,
|
||||
@@ -678,7 +678,7 @@ describe('ProjectRootDocManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function() {
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
|
||||
@@ -17,13 +17,13 @@ const modulePath =
|
||||
'../../../../app/src/Features/Project/ProjectUpdateHandler.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('ProjectUpdateHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('ProjectUpdateHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.fakeTime = new Date()
|
||||
this.clock = sinon.useFakeTimers(this.fakeTime.getTime())
|
||||
})
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
let Project
|
||||
this.ProjectModel = Project = class Project {}
|
||||
this.ProjectModel.updateOne = sinon.stub().callsArg(3)
|
||||
@@ -34,14 +34,14 @@ describe('ProjectUpdateHandler', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('marking a project as recently updated', function() {
|
||||
beforeEach(function() {
|
||||
describe('marking a project as recently updated', function () {
|
||||
beforeEach(function () {
|
||||
this.project_id = 'project_id'
|
||||
this.lastUpdatedAt = 987654321
|
||||
return (this.lastUpdatedBy = 'fake-last-updater-id')
|
||||
})
|
||||
|
||||
it('should send an update to mongo', function(done) {
|
||||
it('should send an update to mongo', function (done) {
|
||||
return this.handler.markAsUpdated(
|
||||
this.project_id,
|
||||
this.lastUpdatedAt,
|
||||
@@ -63,7 +63,7 @@ describe('ProjectUpdateHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should set smart fallbacks', function(done) {
|
||||
it('should set smart fallbacks', function (done) {
|
||||
return this.handler.markAsUpdated(this.project_id, null, null, err => {
|
||||
sinon.assert.calledWithMatch(
|
||||
this.ProjectModel.updateOne,
|
||||
@@ -81,8 +81,8 @@ describe('ProjectUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('markAsOpened', function() {
|
||||
it('should send an update to mongo', function(done) {
|
||||
describe('markAsOpened', function () {
|
||||
it('should send an update to mongo', function (done) {
|
||||
const project_id = 'project_id'
|
||||
return this.handler.markAsOpened(project_id, err => {
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
@@ -95,8 +95,8 @@ describe('ProjectUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('markAsInactive', function() {
|
||||
it('should send an update to mongo', function(done) {
|
||||
describe('markAsInactive', function () {
|
||||
it('should send an update to mongo', function (done) {
|
||||
const project_id = 'project_id'
|
||||
return this.handler.markAsInactive(project_id, err => {
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
@@ -107,8 +107,8 @@ describe('ProjectUpdateHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('markAsActive', function() {
|
||||
it('should send an update to mongo', function(done) {
|
||||
describe('markAsActive', function () {
|
||||
it('should send an update to mongo', function (done) {
|
||||
const project_id = 'project_id'
|
||||
return this.handler.markAsActive(project_id, err => {
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
|
||||
@@ -15,83 +15,83 @@ const sinon = require('sinon')
|
||||
const modulePath = '../../../../app/src/Features/Project/SafePath'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('SafePath', function() {
|
||||
beforeEach(function() {
|
||||
describe('SafePath', function () {
|
||||
beforeEach(function () {
|
||||
return (this.SafePath = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
describe('isCleanFilename', function() {
|
||||
it('should accept a valid filename "main.tex"', function() {
|
||||
describe('isCleanFilename', function () {
|
||||
it('should accept a valid filename "main.tex"', function () {
|
||||
const result = this.SafePath.isCleanFilename('main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept an empty filename', function() {
|
||||
it('should not accept an empty filename', function () {
|
||||
const result = this.SafePath.isCleanFilename('')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept / anywhere', function() {
|
||||
it('should not accept / anywhere', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept .', function() {
|
||||
it('should not accept .', function () {
|
||||
const result = this.SafePath.isCleanFilename('.')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept ..', function() {
|
||||
it('should not accept ..', function () {
|
||||
const result = this.SafePath.isCleanFilename('..')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept * anywhere', function() {
|
||||
it('should not accept * anywhere', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo*bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept leading whitespace', function() {
|
||||
it('should not accept leading whitespace', function () {
|
||||
const result = this.SafePath.isCleanFilename(' foobar.tex')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept trailing whitespace', function() {
|
||||
it('should not accept trailing whitespace', function () {
|
||||
const result = this.SafePath.isCleanFilename('foobar.tex ')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept leading and trailing whitespace', function() {
|
||||
it('should not accept leading and trailing whitespace', function () {
|
||||
const result = this.SafePath.isCleanFilename(' foobar.tex ')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept control characters (0-31)', function() {
|
||||
it('should not accept control characters (0-31)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\u0010bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept control characters (127, delete)', function() {
|
||||
it('should not accept control characters (127, delete)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\u007fbar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept control characters (128-159)', function() {
|
||||
it('should not accept control characters (128-159)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\u0080\u0090bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept surrogate characters (128-159)', function() {
|
||||
it('should not accept surrogate characters (128-159)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\uD800\uDFFFbar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should accept javascript property names', function() {
|
||||
it('should accept javascript property names', function () {
|
||||
const result = this.SafePath.isCleanFilename('prototype')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should accept javascript property names in the prototype', function() {
|
||||
it('should accept javascript property names in the prototype', function () {
|
||||
const result = this.SafePath.isCleanFilename('hasOwnProperty')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
@@ -105,171 +105,171 @@ describe('SafePath', function() {
|
||||
// result = @SafePath.isCleanFilename 'hello.'
|
||||
// result.should.equal false
|
||||
|
||||
it('should not accept \\', function() {
|
||||
it('should not accept \\', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\\bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should reject filenames regardless of order (/g) for bad characters', function() {
|
||||
it('should reject filenames regardless of order (/g) for bad characters', function () {
|
||||
const result1 = this.SafePath.isCleanFilename('foo*bar.tex') // * is not allowed
|
||||
const result2 = this.SafePath.isCleanFilename('*foobar.tex') // bad char location is before previous match
|
||||
return result1.should.equal(false) && result2.should.equal(false)
|
||||
})
|
||||
|
||||
it('should reject filenames regardless of order (/g) for bad filenames', function() {
|
||||
it('should reject filenames regardless of order (/g) for bad filenames', function () {
|
||||
const result1 = this.SafePath.isCleanFilename('foo ') // trailing space
|
||||
const result2 = this.SafePath.isCleanFilename(' foobar') // leading space, match location is before previous match
|
||||
return result1.should.equal(false) && result2.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isCleanPath', function() {
|
||||
it('should accept a valid filename "main.tex"', function() {
|
||||
describe('isCleanPath', function () {
|
||||
it('should accept a valid filename "main.tex"', function () {
|
||||
const result = this.SafePath.isCleanPath('main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should accept a valid path "foo/main.tex"', function() {
|
||||
it('should accept a valid path "foo/main.tex"', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should accept empty path elements', function() {
|
||||
it('should accept empty path elements', function () {
|
||||
const result = this.SafePath.isCleanPath('foo//main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept an empty filename', function() {
|
||||
it('should not accept an empty filename', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/bar/')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should accept a path that starts with a slash', function() {
|
||||
it('should accept a path that starts with a slash', function () {
|
||||
const result = this.SafePath.isCleanPath('/etc/passwd')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept a path that has an asterisk as the 0th element', function() {
|
||||
it('should not accept a path that has an asterisk as the 0th element', function () {
|
||||
const result = this.SafePath.isCleanPath('*/foo/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that has an asterisk as a middle element', function() {
|
||||
it('should not accept a path that has an asterisk as a middle element', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/*/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that has an asterisk as the filename', function() {
|
||||
it('should not accept a path that has an asterisk as the filename', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/bar/*')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that contains an asterisk in the 0th element', function() {
|
||||
it('should not accept a path that contains an asterisk in the 0th element', function () {
|
||||
const result = this.SafePath.isCleanPath('f*o/bar/baz')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that contains an asterisk in a middle element', function() {
|
||||
it('should not accept a path that contains an asterisk in a middle element', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/b*r/baz')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that contains an asterisk in the filename', function() {
|
||||
it('should not accept a path that contains an asterisk in the filename', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/bar/b*z')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept multiple problematic elements', function() {
|
||||
it('should not accept multiple problematic elements', function () {
|
||||
const result = this.SafePath.isCleanPath('f*o/b*r/b*z')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a problematic path with an empty element', function() {
|
||||
it('should not accept a problematic path with an empty element', function () {
|
||||
const result = this.SafePath.isCleanPath('foo//*/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept javascript property names', function() {
|
||||
it('should not accept javascript property names', function () {
|
||||
const result = this.SafePath.isCleanPath('prototype')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept javascript property names in the prototype', function() {
|
||||
it('should not accept javascript property names in the prototype', function () {
|
||||
const result = this.SafePath.isCleanPath('hasOwnProperty')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept javascript property names resulting from substitutions', function() {
|
||||
it('should not accept javascript property names resulting from substitutions', function () {
|
||||
const result = this.SafePath.isCleanPath(' proto ')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isAllowedLength', function() {
|
||||
it('should accept a valid path "main.tex"', function() {
|
||||
describe('isAllowedLength', function () {
|
||||
it('should accept a valid path "main.tex"', function () {
|
||||
const result = this.SafePath.isAllowedLength('main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept an extremely long path', function() {
|
||||
it('should not accept an extremely long path', function () {
|
||||
const longPath = new Array(1000).join('/subdir') + '/main.tex'
|
||||
const result = this.SafePath.isAllowedLength(longPath)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept an empty path', function() {
|
||||
it('should not accept an empty path', function () {
|
||||
const result = this.SafePath.isAllowedLength('')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('clean', function() {
|
||||
it('should not modify a valid filename', function() {
|
||||
describe('clean', function () {
|
||||
it('should not modify a valid filename', function () {
|
||||
const result = this.SafePath.clean('main.tex')
|
||||
return result.should.equal('main.tex')
|
||||
})
|
||||
|
||||
it('should replace invalid characters with _', function() {
|
||||
it('should replace invalid characters with _', function () {
|
||||
const result = this.SafePath.clean('foo/bar*/main.tex')
|
||||
return result.should.equal('foo_bar__main.tex')
|
||||
})
|
||||
|
||||
it('should replace "." with "_"', function() {
|
||||
it('should replace "." with "_"', function () {
|
||||
const result = this.SafePath.clean('.')
|
||||
return result.should.equal('_')
|
||||
})
|
||||
|
||||
it('should replace ".." with "__"', function() {
|
||||
it('should replace ".." with "__"', function () {
|
||||
const result = this.SafePath.clean('..')
|
||||
return result.should.equal('__')
|
||||
})
|
||||
|
||||
it('should replace a single trailing space with _', function() {
|
||||
it('should replace a single trailing space with _', function () {
|
||||
const result = this.SafePath.clean('foo ')
|
||||
return result.should.equal('foo_')
|
||||
})
|
||||
|
||||
it('should replace a multiple trailing spaces with ___', function() {
|
||||
it('should replace a multiple trailing spaces with ___', function () {
|
||||
const result = this.SafePath.clean('foo ')
|
||||
return result.should.equal('foo__')
|
||||
})
|
||||
|
||||
it('should replace a single leading space with _', function() {
|
||||
it('should replace a single leading space with _', function () {
|
||||
const result = this.SafePath.clean(' foo')
|
||||
return result.should.equal('_foo')
|
||||
})
|
||||
|
||||
it('should replace a multiple leading spaces with ___', function() {
|
||||
it('should replace a multiple leading spaces with ___', function () {
|
||||
const result = this.SafePath.clean(' foo')
|
||||
return result.should.equal('__foo')
|
||||
})
|
||||
|
||||
it('should prefix javascript property names with @', function() {
|
||||
it('should prefix javascript property names with @', function () {
|
||||
const result = this.SafePath.clean('prototype')
|
||||
return result.should.equal('@prototype')
|
||||
})
|
||||
|
||||
it('should prefix javascript property names in the prototype with @', function() {
|
||||
it('should prefix javascript property names in the prototype with @', function () {
|
||||
const result = this.SafePath.clean('hasOwnProperty')
|
||||
return result.should.equal('@hasOwnProperty')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user