2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
require('chai').should()
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../../app/src/Features/Editor/EditorHttpController'
|
|
|
|
)
|
2019-07-01 05:16:50 -04:00
|
|
|
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
describe('EditorHttpController', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.EditorHttpController = SandboxedModule.require(modulePath, {
|
2019-07-15 06:33:47 -04:00
|
|
|
globals: {
|
|
|
|
console: console
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../Project/ProjectDeleter': (this.ProjectDeleter = {}),
|
|
|
|
'../Project/ProjectGetter': (this.ProjectGetter = {}),
|
|
|
|
'../Authorization/AuthorizationManager': (this.AuthorizationManager = {}),
|
|
|
|
'../Project/ProjectEditorHandler': (this.ProjectEditorHandler = {}),
|
|
|
|
'logger-sharelatex': (this.logger = {
|
|
|
|
log: sinon.stub(),
|
|
|
|
error: sinon.stub()
|
|
|
|
}),
|
|
|
|
'./EditorController': (this.EditorController = {}),
|
|
|
|
'metrics-sharelatex': (this.Metrics = { inc: sinon.stub() }),
|
2019-10-07 04:30:51 -04:00
|
|
|
'../Collaborators/CollaboratorsGetter': (this.CollaboratorsGetter = {}),
|
2019-10-18 05:32:19 -04:00
|
|
|
'../Collaborators/CollaboratorsHandler': (this.CollaboratorsHandler = {}),
|
2019-05-29 05:21:06 -04:00
|
|
|
'../Collaborators/CollaboratorsInviteHandler': (this.CollaboratorsInviteHandler = {}),
|
|
|
|
'../TokenAccess/TokenAccessHandler': (this.TokenAccessHandler = {}),
|
2019-07-01 05:16:50 -04:00
|
|
|
'../Authentication/AuthenticationController': (this.AuthenticationController = {}),
|
|
|
|
'../Errors/Errors': Errors
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.project_id = 'mock-project-id'
|
|
|
|
this.doc_id = 'mock-doc-id'
|
|
|
|
this.user_id = 'mock-user-id'
|
|
|
|
this.parent_folder_id = 'mock-folder-id'
|
|
|
|
this.userId = 1234
|
|
|
|
this.AuthenticationController.getLoggedInUserId = sinon
|
|
|
|
.stub()
|
|
|
|
.returns(this.userId)
|
2019-07-01 09:54:23 -04:00
|
|
|
this.req = { i18n: { translate: string => string } }
|
2019-05-29 05:21:06 -04:00
|
|
|
this.res = {
|
|
|
|
send: sinon.stub(),
|
|
|
|
sendStatus: sinon.stub(),
|
|
|
|
json: sinon.stub()
|
|
|
|
}
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
this.TokenAccessHandler.getRequestToken = sinon
|
|
|
|
.stub()
|
|
|
|
.returns((this.token = null))
|
2019-10-18 05:32:19 -04:00
|
|
|
this.TokenAccessHandler.protectTokens = sinon.stub()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('joinProject', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.req.params = { Project_id: this.project_id }
|
|
|
|
this.req.query = { user_id: this.user_id }
|
|
|
|
this.projectView = {
|
2019-10-18 05:32:19 -04:00
|
|
|
_id: this.project_id,
|
|
|
|
owner: {
|
|
|
|
_id: 'owner',
|
|
|
|
email: 'owner@example.com',
|
|
|
|
other_property: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.reducedProjectView = {
|
|
|
|
_id: this.project_id,
|
|
|
|
owner: { _id: 'owner' }
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
this.EditorHttpController._buildJoinProjectView = sinon
|
|
|
|
.stub()
|
2019-10-18 05:32:19 -04:00
|
|
|
.callsArgWith(3, null, this.projectView, 'owner', false)
|
|
|
|
this.ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully', function() {
|
|
|
|
beforeEach(function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.AuthorizationManager.isRestrictedUser = sinon.stub().returns(false)
|
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the project view', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController._buildJoinProjectView
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.req, this.project_id, this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the project and privilege level', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.json
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith({
|
|
|
|
project: this.projectView,
|
2019-10-18 05:32:19 -04:00
|
|
|
privilegeLevel: 'owner',
|
|
|
|
isRestrictedUser: false
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not try to unmark the project as deleted', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.ProjectDeleter.unmarkAsDeletedByExternalSource.called.should.equal(
|
2019-05-29 05:21:06 -04:00
|
|
|
false
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send an inc metric', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.Metrics.inc.calledWith('editor.join-project').should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the project is marked as deleted', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.projectView.deletedByExternalDataSource = true
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should unmark the project as deleted', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.ProjectDeleter.unmarkAsDeletedByExternalSource
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-10-18 05:32:19 -04:00
|
|
|
describe('with an restricted user', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.EditorHttpController._buildJoinProjectView = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, this.projectView, 'readOnly', true)
|
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should mark the user as restricted, and hide details of owner', function() {
|
|
|
|
this.res.json
|
|
|
|
.calledWith({
|
|
|
|
project: this.reducedProjectView,
|
|
|
|
privilegeLevel: 'readOnly',
|
|
|
|
isRestrictedUser: true
|
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-11-07 05:28:34 -05:00
|
|
|
describe('when no project', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.EditorHttpController._buildJoinProjectView = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, null, null, false)
|
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should send a 403 response', function() {
|
|
|
|
this.res.json
|
|
|
|
.calledWith({
|
|
|
|
project: null,
|
|
|
|
privilegeLevel: null,
|
|
|
|
isRestrictedUser: null
|
|
|
|
})
|
|
|
|
.should.equal(false)
|
|
|
|
this.res.sendStatus.calledWith(403).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('with an anonymous user', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.req.query = { user_id: 'anonymous-user' }
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController._buildJoinProjectView = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, this.projectView, 'readOnly', true)
|
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should pass the user id as null', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController._buildJoinProjectView
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.req, this.project_id, null)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2019-10-18 05:32:19 -04:00
|
|
|
|
|
|
|
it('should mark the user as restricted', function() {
|
|
|
|
this.res.json
|
|
|
|
.calledWith({
|
|
|
|
project: this.reducedProjectView,
|
|
|
|
privilegeLevel: 'readOnly',
|
|
|
|
isRestrictedUser: true
|
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('_buildJoinProjectView', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.project = {
|
|
|
|
_id: this.project_id,
|
|
|
|
owner_ref: { _id: 'something' }
|
|
|
|
}
|
|
|
|
this.user = {
|
|
|
|
_id: (this.user_id = 'user-id'),
|
|
|
|
projects: {}
|
|
|
|
}
|
|
|
|
this.members = ['members', 'mock']
|
|
|
|
this.tokenMembers = ['one', 'two']
|
|
|
|
this.projectModelView = {
|
|
|
|
_id: this.project_id,
|
|
|
|
owner: { _id: 'something' },
|
|
|
|
view: true
|
|
|
|
}
|
|
|
|
this.invites = [
|
|
|
|
{
|
|
|
|
_id: 'invite_one',
|
|
|
|
email: 'user-one@example.com',
|
|
|
|
privileges: 'readOnly',
|
|
|
|
projectId: this.project._id
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: 'invite_two',
|
|
|
|
email: 'user-two@example.com',
|
|
|
|
privileges: 'readOnly',
|
|
|
|
projectId: this.project._id
|
|
|
|
}
|
|
|
|
]
|
|
|
|
this.ProjectEditorHandler.buildProjectModelView = sinon
|
|
|
|
.stub()
|
|
|
|
.returns(this.projectModelView)
|
|
|
|
this.ProjectGetter.getProjectWithoutDocLines = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.project)
|
2019-10-07 04:30:51 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedMembersWithPrivilegeLevels = sinon
|
2019-05-29 05:21:06 -04:00
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.members)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.CollaboratorsHandler.userIsTokenMember = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, false)
|
|
|
|
this.AuthorizationManager.isRestrictedUser = sinon.stub().returns(false)
|
2019-05-29 05:21:06 -04:00
|
|
|
this.CollaboratorsInviteHandler.getAllInvites = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.invites)
|
|
|
|
})
|
|
|
|
|
2019-07-01 05:16:50 -04:00
|
|
|
describe('when project is not found', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.ProjectGetter.getProjectWithoutDocLines.yields(null, null)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController._buildJoinProjectView(
|
2019-07-01 05:16:50 -04:00
|
|
|
this.req,
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should handle return not found error', function() {
|
|
|
|
let args = this.callback.lastCall.args
|
|
|
|
args.length.should.equal(1)
|
|
|
|
args[0].should.be.instanceof(Errors.NotFoundError)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
describe('when authorized', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.AuthorizationManager.getPrivilegeLevelForProject = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, 'owner')
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController._buildJoinProjectView(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req,
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should find the project without doc lines', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.ProjectGetter.getProjectWithoutDocLines
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the list of users in the project', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.CollaboratorsGetter.getInvitedMembersWithPrivilegeLevels
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should check the privilege level', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.AuthorizationManager.getPrivilegeLevelForProject
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.user_id, this.project_id, this.token)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-10-18 05:32:19 -04:00
|
|
|
it('should check if user is restricted', function() {
|
|
|
|
this.AuthorizationManager.isRestrictedUser.called.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
it('should include the invites', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.CollaboratorsInviteHandler.getAllInvites
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(this.project._id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return the project model view, privilege level and protocol version', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.callback
|
|
|
|
.calledWith(null, this.projectModelView, 'owner', false)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when user is restricted', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.AuthorizationManager.getPrivilegeLevelForProject = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, 'readOnly')
|
|
|
|
this.AuthorizationManager.isRestrictedUser.returns(true)
|
|
|
|
this.EditorHttpController._buildJoinProjectView(
|
|
|
|
this.req,
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set the isRestrictedUser flag', function() {
|
|
|
|
this.callback
|
|
|
|
.calledWith(null, this.projectModelView, 'readOnly', true)
|
2019-05-29 05:21:06 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('when not authorized', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.AuthorizationManager.getPrivilegeLevelForProject = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, null)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController._buildJoinProjectView(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req,
|
|
|
|
this.project_id,
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should return false in the callback', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.callback.calledWith(null, null, false).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('addDoc', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.doc = { mock: 'doc' }
|
|
|
|
this.req.params = { Project_id: this.project_id }
|
|
|
|
this.req.body = {
|
|
|
|
name: (this.name = 'doc-name'),
|
|
|
|
parent_folder_id: this.parent_folder_id
|
|
|
|
}
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorController.addDoc = sinon
|
2019-05-29 05:21:06 -04:00
|
|
|
.stub()
|
2019-10-18 05:32:19 -04:00
|
|
|
.callsArgWith(6, null, this.doc)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully', function() {
|
|
|
|
beforeEach(function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.addDoc(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should call EditorController.addDoc', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorController.addDoc
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.parent_folder_id,
|
|
|
|
this.name,
|
|
|
|
[],
|
|
|
|
'editor',
|
|
|
|
this.userId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send the doc back as JSON', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.json.calledWith(this.doc).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('unsuccesfully', function() {
|
2019-07-01 09:54:23 -04:00
|
|
|
it('handle name too short', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body.name = ''
|
2019-07-01 09:54:23 -04:00
|
|
|
this.EditorHttpController.addDoc(this.req, this.res)
|
|
|
|
this.res.sendStatus.calledWith(400).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-07-01 09:54:23 -04:00
|
|
|
it('handle too many files', function() {
|
|
|
|
this.EditorController.addDoc.yields(
|
2020-02-18 06:37:15 -05:00
|
|
|
new Error('project_has_too_many_files')
|
2019-07-01 09:54:23 -04:00
|
|
|
)
|
|
|
|
let res = {
|
|
|
|
status: status => {
|
|
|
|
status.should.equal(400)
|
|
|
|
return {
|
|
|
|
json: json => {
|
2020-02-18 06:37:15 -05:00
|
|
|
json.should.equal('project_has_too_many_files')
|
2019-07-01 09:54:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.EditorHttpController.addDoc(this.req, res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('addFolder', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.folder = { mock: 'folder' }
|
|
|
|
this.req.params = { Project_id: this.project_id }
|
|
|
|
this.req.body = {
|
|
|
|
name: (this.name = 'folder-name'),
|
|
|
|
parent_folder_id: this.parent_folder_id
|
|
|
|
}
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorController.addFolder = sinon
|
2019-05-29 05:21:06 -04:00
|
|
|
.stub()
|
2019-10-18 05:32:19 -04:00
|
|
|
.callsArgWith(4, null, this.folder)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully', function() {
|
|
|
|
beforeEach(function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.addFolder(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should call EditorController.addFolder', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorController.addFolder
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.parent_folder_id,
|
|
|
|
this.name,
|
|
|
|
'editor'
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send the folder back as JSON', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.json.calledWith(this.folder).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('unsuccesfully', function() {
|
2019-07-01 09:54:23 -04:00
|
|
|
it('handle name too short', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body.name = ''
|
2019-07-01 09:54:23 -04:00
|
|
|
this.EditorHttpController.addFolder(this.req, this.res)
|
|
|
|
this.res.sendStatus.calledWith(400).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-07-01 09:54:23 -04:00
|
|
|
it('handle too many files', function() {
|
|
|
|
this.EditorController.addFolder.yields(
|
2020-02-18 06:37:15 -05:00
|
|
|
new Error('project_has_too_many_files')
|
2019-07-01 09:54:23 -04:00
|
|
|
)
|
|
|
|
let res = {
|
|
|
|
status: status => {
|
|
|
|
status.should.equal(400)
|
|
|
|
return {
|
|
|
|
json: json => {
|
2020-02-18 06:37:15 -05:00
|
|
|
json.should.equal('project_has_too_many_files')
|
2019-07-01 09:54:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.EditorHttpController.addFolder(this.req, res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('handle invalid element name', function() {
|
|
|
|
this.EditorController.addFolder.yields(
|
|
|
|
new Error('invalid element name')
|
|
|
|
)
|
|
|
|
let res = {
|
|
|
|
status: status => {
|
|
|
|
status.should.equal(400)
|
|
|
|
return {
|
|
|
|
json: json => {
|
|
|
|
json.should.equal('invalid_file_name')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.EditorHttpController.addFolder(this.req, res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renameEntity', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.req.params = {
|
|
|
|
Project_id: this.project_id,
|
|
|
|
entity_id: (this.entity_id = 'entity-id-123'),
|
|
|
|
entity_type: (this.entity_type = 'entity-type')
|
|
|
|
}
|
|
|
|
this.req.body = { name: (this.name = 'new-name') }
|
|
|
|
this.EditorController.renameEntity = sinon.stub().callsArg(5)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.renameEntity(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should call EditorController.renameEntity', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorController.renameEntity
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.entity_id,
|
|
|
|
this.entity_type,
|
|
|
|
this.name,
|
|
|
|
this.userId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send back a success response', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.sendStatus.calledWith(204).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renameEntity with long name', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.req.params = {
|
|
|
|
Project_id: this.project_id,
|
|
|
|
entity_id: (this.entity_id = 'entity-id-123'),
|
|
|
|
entity_type: (this.entity_type = 'entity-type')
|
|
|
|
}
|
|
|
|
this.req.body = {
|
|
|
|
name: (this.name =
|
|
|
|
'EDMUBEEBKBXUUUZERMNSXFFWIBHGSDAWGMRIQWJBXGWSBVWSIKLFPRBYSJEKMFHTRZBHVKJSRGKTBHMJRXPHORFHAKRNPZGGYIOTEDMUBEEBKBXUUUZERMNSXFFWIBHGSDAWGMRIQWJBXGWSBVWSIKLFPRBYSJEKMFHTRZBHVKJSRGKTBHMJRXPHORFHAKRNPZGGYIOT')
|
|
|
|
}
|
|
|
|
this.EditorController.renameEntity = sinon.stub().callsArg(4)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.renameEntity(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send back a bad request status code', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.sendStatus.calledWith(400).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('rename entity with 0 length name', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.req.params = {
|
|
|
|
Project_id: this.project_id,
|
|
|
|
entity_id: (this.entity_id = 'entity-id-123'),
|
|
|
|
entity_type: (this.entity_type = 'entity-type')
|
|
|
|
}
|
|
|
|
this.req.body = { name: (this.name = '') }
|
|
|
|
this.EditorController.renameEntity = sinon.stub().callsArg(4)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.renameEntity(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send back a bad request status code', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.sendStatus.calledWith(400).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('moveEntity', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.req.params = {
|
|
|
|
Project_id: this.project_id,
|
|
|
|
entity_id: (this.entity_id = 'entity-id-123'),
|
|
|
|
entity_type: (this.entity_type = 'entity-type')
|
|
|
|
}
|
|
|
|
this.req.body = { folder_id: (this.folder_id = 'folder-id-123') }
|
|
|
|
this.EditorController.moveEntity = sinon.stub().callsArg(5)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.moveEntity(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should call EditorController.moveEntity', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorController.moveEntity
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.entity_id,
|
|
|
|
this.folder_id,
|
|
|
|
this.entity_type,
|
|
|
|
this.userId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send back a success response', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.sendStatus.calledWith(204).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('deleteEntity', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
this.req.params = {
|
|
|
|
Project_id: this.project_id,
|
|
|
|
entity_id: (this.entity_id = 'entity-id-123'),
|
|
|
|
entity_type: (this.entity_type = 'entity-type')
|
|
|
|
}
|
|
|
|
this.EditorController.deleteEntity = sinon.stub().callsArg(5)
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.deleteEntity(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should call EditorController.deleteEntity', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorController.deleteEntity
|
2019-05-29 05:21:06 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.entity_id,
|
|
|
|
this.entity_type,
|
|
|
|
'editor',
|
|
|
|
this.userId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send back a success response', function() {
|
2019-10-18 05:32:19 -04:00
|
|
|
this.res.sendStatus.calledWith(204).should.equal(true)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|