2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
2020-02-27 07:50:29 -05:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const { ObjectId } = require('mongodb')
|
2019-07-01 05:16:50 -04:00
|
|
|
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
2020-03-10 08:36:53 -04:00
|
|
|
const HttpErrors = require('@overleaf/o-error/http')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
const MODULE_PATH = '../../../../app/src/Features/Editor/EditorHttpController'
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
describe('EditorHttpController', function() {
|
|
|
|
beforeEach(function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
this.ownerId = new ObjectId()
|
|
|
|
this.project = {
|
|
|
|
_id: new ObjectId(),
|
|
|
|
owner_ref: this.ownerId
|
|
|
|
}
|
|
|
|
this.user = {
|
|
|
|
_id: new ObjectId(),
|
|
|
|
projects: {}
|
|
|
|
}
|
|
|
|
this.projectView = {
|
|
|
|
_id: this.project._id,
|
|
|
|
owner: {
|
|
|
|
_id: 'owner',
|
|
|
|
email: 'owner@example.com',
|
|
|
|
other_property: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.reducedProjectView = {
|
|
|
|
_id: this.projectView._id,
|
|
|
|
owner: { _id: this.projectView.owner._id }
|
|
|
|
}
|
2020-03-04 04:37:43 -05:00
|
|
|
this.doc = { _id: new ObjectId(), name: 'excellent-original-idea.tex' }
|
|
|
|
this.file = { _id: new ObjectId() }
|
|
|
|
this.folder = { _id: new ObjectId() }
|
2020-02-27 07:50:29 -05:00
|
|
|
|
|
|
|
this.parentFolderId = 'mock-folder-id'
|
|
|
|
this.req = { i18n: { translate: string => string } }
|
|
|
|
this.res = {
|
|
|
|
send: sinon.stub().returns(this.res),
|
|
|
|
status: sinon.stub().returns(this.res),
|
|
|
|
sendStatus: sinon.stub().returns(this.res),
|
|
|
|
json: sinon.stub().returns(this.res)
|
|
|
|
}
|
|
|
|
this.next = sinon.stub()
|
|
|
|
this.token = null
|
2020-03-04 04:37:43 -05:00
|
|
|
this.docLines = ['hello', 'overleaf']
|
2020-02-27 07:50:29 -05:00
|
|
|
|
|
|
|
this.AuthorizationManager = {
|
|
|
|
isRestrictedUser: sinon.stub().returns(false),
|
|
|
|
promises: {
|
|
|
|
getPrivilegeLevelForProject: sinon.stub().resolves('owner')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.CollaboratorsGetter = {
|
|
|
|
promises: {
|
|
|
|
getInvitedMembersWithPrivilegeLevels: sinon
|
|
|
|
.stub()
|
|
|
|
.resolves(['members', 'mock'])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.CollaboratorsHandler = {
|
|
|
|
promises: {
|
|
|
|
userIsTokenMember: sinon.stub().resolves(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.CollaboratorsInviteHandler = {
|
|
|
|
promises: {
|
|
|
|
getAllInvites: sinon.stub().resolves([
|
|
|
|
{
|
|
|
|
_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.EditorController = {
|
|
|
|
promises: {
|
|
|
|
addDoc: sinon.stub().resolves(this.doc),
|
2020-03-04 04:37:43 -05:00
|
|
|
addFile: sinon.stub().resolves(this.file),
|
2020-02-27 07:50:29 -05:00
|
|
|
addFolder: sinon.stub().resolves(this.folder),
|
|
|
|
renameEntity: sinon.stub().resolves(),
|
|
|
|
moveEntity: sinon.stub().resolves(),
|
|
|
|
deleteEntity: sinon.stub().resolves()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.ProjectDeleter = {
|
|
|
|
promises: {
|
|
|
|
unmarkAsDeletedByExternalSource: sinon.stub().resolves()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.ProjectGetter = {
|
|
|
|
promises: {
|
|
|
|
getProjectWithoutDocLines: sinon.stub().resolves(this.project)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.ProjectEditorHandler = {
|
|
|
|
buildProjectModelView: sinon.stub().returns(this.projectView)
|
|
|
|
}
|
|
|
|
this.logger = {
|
|
|
|
log: sinon.stub(),
|
|
|
|
error: sinon.stub()
|
|
|
|
}
|
|
|
|
this.Metrics = { inc: sinon.stub() }
|
|
|
|
this.TokenAccessHandler = {
|
|
|
|
getRequestToken: sinon.stub().returns(this.token),
|
|
|
|
protectTokens: sinon.stub()
|
|
|
|
}
|
|
|
|
this.AuthenticationController = {
|
|
|
|
getLoggedInUserId: sinon.stub().returns(this.user._id)
|
|
|
|
}
|
2020-03-04 04:37:43 -05:00
|
|
|
this.ProjectEntityUpdateHandler = {
|
|
|
|
promises: {
|
|
|
|
convertDocToFile: sinon.stub().resolves(this.file)
|
|
|
|
}
|
|
|
|
}
|
2020-02-27 07:50:29 -05:00
|
|
|
this.EditorHttpController = SandboxedModule.require(MODULE_PATH, {
|
2019-07-15 06:33:47 -04:00
|
|
|
globals: {
|
|
|
|
console: console
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
2020-02-27 07:50:29 -05:00
|
|
|
'../Project/ProjectDeleter': this.ProjectDeleter,
|
|
|
|
'../Project/ProjectGetter': this.ProjectGetter,
|
|
|
|
'../Authorization/AuthorizationManager': this.AuthorizationManager,
|
|
|
|
'../Project/ProjectEditorHandler': this.ProjectEditorHandler,
|
|
|
|
'logger-sharelatex': this.logger,
|
|
|
|
'./EditorController': this.EditorController,
|
|
|
|
'metrics-sharelatex': this.Metrics,
|
|
|
|
'../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
|
|
|
|
'../Collaborators/CollaboratorsHandler': this.CollaboratorsHandler,
|
|
|
|
'../Collaborators/CollaboratorsInviteHandler': this
|
|
|
|
.CollaboratorsInviteHandler,
|
|
|
|
'../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
|
|
|
|
'../Authentication/AuthenticationController': this
|
|
|
|
.AuthenticationController,
|
2020-03-04 04:37:43 -05:00
|
|
|
'../../infrastructure/FileWriter': this.FileWriter,
|
|
|
|
'../Project/ProjectEntityUpdateHandler': this
|
|
|
|
.ProjectEntityUpdateHandler,
|
2020-03-10 08:36:53 -04:00
|
|
|
'../Errors/Errors': Errors,
|
|
|
|
'@overleaf/o-error/http': HttpErrors
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('joinProject', function() {
|
|
|
|
beforeEach(function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
this.req.params = { Project_id: this.project._id }
|
|
|
|
this.req.query = { user_id: this.user._id }
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
|
|
|
this.res.json.callsFake(() => done())
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the project and privilege level', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.json).to.have.been.calledWith({
|
|
|
|
project: this.projectView,
|
|
|
|
privilegeLevel: 'owner',
|
|
|
|
isRestrictedUser: false
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not try to unmark the project as deleted', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.ProjectDeleter.promises.unmarkAsDeletedByExternalSource).not
|
|
|
|
.to.have.been.called
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send an inc metric', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.Metrics.inc).to.have.been.calledWith('editor.join-project')
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the project is marked as deleted', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.projectView.deletedByExternalDataSource = true
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.json.callsFake(() => done())
|
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() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(
|
|
|
|
this.ProjectDeleter.promises.unmarkAsDeletedByExternalSource
|
|
|
|
).to.have.been.calledWith(this.project._id)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
describe('with a restricted user', function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
this.AuthorizationManager.isRestrictedUser.returns(true)
|
|
|
|
this.AuthorizationManager.promises.getPrivilegeLevelForProject.resolves(
|
|
|
|
'readOnly'
|
|
|
|
)
|
|
|
|
this.res.json.callsFake(() => done())
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should mark the user as restricted, and hide details of owner', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.json).to.have.been.calledWith({
|
|
|
|
project: this.reducedProjectView,
|
|
|
|
privilegeLevel: 'readOnly',
|
|
|
|
isRestrictedUser: true
|
|
|
|
})
|
2019-10-18 05:32:19 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
describe('when not authorized', function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
this.AuthorizationManager.promises.getPrivilegeLevelForProject.resolves(
|
|
|
|
null
|
|
|
|
)
|
|
|
|
this.res.sendStatus.callsFake(() => done())
|
2019-11-07 05:28:34 -05:00
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should send a 403 response', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.sendStatus).to.have.been.calledWith(403)
|
2019-11-07 05:28:34 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('with an anonymous user', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.query = { user_id: 'anonymous-user' }
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.json.callsFake(() => done())
|
|
|
|
this.AuthorizationManager.isRestrictedUser
|
|
|
|
.withArgs(null, 'readOnly', false)
|
|
|
|
.returns(true)
|
|
|
|
this.AuthorizationManager.promises.getPrivilegeLevelForProject
|
|
|
|
.withArgs(null, this.project._id, this.token)
|
|
|
|
.resolves('readOnly')
|
2019-10-18 05:32:19 -04:00
|
|
|
this.EditorHttpController.joinProject(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-10-18 05:32:19 -04:00
|
|
|
it('should mark the user as restricted', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.json).to.have.been.calledWith({
|
|
|
|
project: this.reducedProjectView,
|
|
|
|
privilegeLevel: 'readOnly',
|
|
|
|
isRestrictedUser: true
|
|
|
|
})
|
2019-10-18 05:32:19 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-07-01 05:16:50 -04:00
|
|
|
describe('when project is not found', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
|
|
|
this.ProjectGetter.promises.getProjectWithoutDocLines.resolves(null)
|
|
|
|
this.next.callsFake(() => done())
|
|
|
|
this.EditorHttpController.joinProject(this.req, this.res, this.next)
|
2019-07-01 05:16:50 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should handle return not found error', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.next).to.have.been.calledWith(
|
|
|
|
sinon.match.instanceOf(Errors.NotFoundError)
|
2019-10-18 05:32:19 -04:00
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('addDoc', function() {
|
|
|
|
beforeEach(function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
this.req.params = { Project_id: this.project._id }
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body = {
|
|
|
|
name: (this.name = 'doc-name'),
|
2020-02-27 07:50:29 -05:00
|
|
|
parent_folder_id: this.parentFolderId
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
|
|
|
this.res.json.callsFake(() => done())
|
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() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.EditorController.promises.addDoc).to.have.been.calledWith(
|
|
|
|
this.project._id,
|
|
|
|
this.parentFolderId,
|
|
|
|
this.name,
|
|
|
|
[],
|
|
|
|
'editor',
|
|
|
|
this.user._id
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send the doc back as JSON', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.json).to.have.been.calledWith(this.doc)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('unsuccesfully', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
it('handle name too short', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body.name = ''
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.sendStatus.callsFake(status => {
|
|
|
|
expect(status).to.equal(400)
|
|
|
|
done()
|
|
|
|
})
|
2019-07-01 09:54:23 -04:00
|
|
|
this.EditorHttpController.addDoc(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
it('handle too many files', function(done) {
|
|
|
|
this.EditorController.promises.addDoc.rejects(
|
2020-02-18 06:37:15 -05:00
|
|
|
new Error('project_has_too_many_files')
|
2019-07-01 09:54:23 -04:00
|
|
|
)
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.json.callsFake(payload => {
|
|
|
|
expect(payload).to.equal('project_has_too_many_files')
|
|
|
|
expect(this.res.status).to.have.been.calledWith(400)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
this.res.status.returns(this.res)
|
|
|
|
this.EditorHttpController.addDoc(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('addFolder', function() {
|
|
|
|
beforeEach(function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
this.folderName = 'folder-name'
|
|
|
|
this.req.params = { Project_id: this.project._id }
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body = {
|
2020-02-27 07:50:29 -05:00
|
|
|
name: this.folderName,
|
|
|
|
parent_folder_id: this.parentFolderId
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
|
|
|
this.res.json.callsFake(() => done())
|
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() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(
|
|
|
|
this.EditorController.promises.addFolder
|
|
|
|
).to.have.been.calledWith(
|
|
|
|
this.project._id,
|
|
|
|
this.parentFolderId,
|
|
|
|
this.folderName,
|
|
|
|
'editor'
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send the folder back as JSON', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.json).to.have.been.calledWith(this.folder)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('unsuccesfully', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
it('handle name too short', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.body.name = ''
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.sendStatus.callsFake(status => {
|
|
|
|
expect(status).to.equal(400)
|
|
|
|
done()
|
|
|
|
})
|
2019-07-01 09:54:23 -04:00
|
|
|
this.EditorHttpController.addFolder(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
it('handle too many files', function(done) {
|
|
|
|
this.EditorController.promises.addFolder.rejects(
|
2020-02-18 06:37:15 -05:00
|
|
|
new Error('project_has_too_many_files')
|
2019-07-01 09:54:23 -04:00
|
|
|
)
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.json.callsFake(payload => {
|
|
|
|
expect(payload).to.equal('project_has_too_many_files')
|
|
|
|
expect(this.res.status).to.have.been.calledWith(400)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
this.res.status.returns(this.res)
|
|
|
|
this.EditorHttpController.addFolder(this.req, this.res)
|
2019-07-01 09:54:23 -04:00
|
|
|
})
|
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
it('handle invalid element name', function(done) {
|
|
|
|
this.EditorController.promises.addFolder.rejects(
|
2019-07-01 09:54:23 -04:00
|
|
|
new Error('invalid element name')
|
|
|
|
)
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.json.callsFake(payload => {
|
|
|
|
expect(payload).to.equal('invalid_file_name')
|
|
|
|
expect(this.res.status).to.have.been.calledWith(400)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
this.res.status.returns(this.res)
|
|
|
|
this.EditorHttpController.addFolder(this.req, this.res)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renameEntity', function() {
|
|
|
|
beforeEach(function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
this.entityId = 'entity-id-123'
|
|
|
|
this.entityType = 'entity-type'
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.params = {
|
2020-02-27 07:50:29 -05:00
|
|
|
Project_id: this.project._id,
|
|
|
|
entity_id: this.entityId,
|
|
|
|
entity_type: this.entityType
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
describe('successfully', function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
this.newName = 'new-name'
|
|
|
|
this.req.body = { name: this.newName }
|
|
|
|
this.res.sendStatus.callsFake(() => done())
|
|
|
|
this.EditorHttpController.renameEntity(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call EditorController.renameEntity', function() {
|
|
|
|
expect(
|
|
|
|
this.EditorController.promises.renameEntity
|
|
|
|
).to.have.been.calledWith(
|
|
|
|
this.project._id,
|
|
|
|
this.entityId,
|
|
|
|
this.entityType,
|
|
|
|
this.newName,
|
|
|
|
this.user._id
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
2020-02-27 07:50:29 -05:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
it('should send back a success response', function() {
|
|
|
|
expect(this.res.sendStatus).to.have.been.calledWith(204)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2020-02-27 07:50:29 -05:00
|
|
|
describe('with long name', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.newName = 'long'.repeat(100)
|
|
|
|
this.req.body = { name: this.newName }
|
|
|
|
this.EditorHttpController.renameEntity(this.req, this.res)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
it('should send back a bad request status code', function() {
|
|
|
|
expect(this.res.sendStatus).to.have.been.calledWith(400)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
describe('with 0 length name', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.newName = ''
|
|
|
|
this.req.body = { name: this.newName }
|
|
|
|
this.EditorHttpController.renameEntity(this.req, this.res)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2020-02-27 07:50:29 -05:00
|
|
|
it('should send back a bad request status code', function() {
|
|
|
|
expect(this.res.sendStatus).to.have.been.calledWith(400)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('moveEntity', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
|
|
|
this.entityId = 'entity-id-123'
|
|
|
|
this.entityType = 'entity-type'
|
|
|
|
this.folderId = 'folder-id-123'
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.params = {
|
2020-02-27 07:50:29 -05:00
|
|
|
Project_id: this.project._id,
|
|
|
|
entity_id: this.entityId,
|
|
|
|
entity_type: this.entityType
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-02-27 07:50:29 -05:00
|
|
|
this.req.body = { folder_id: this.folderId }
|
|
|
|
this.res.sendStatus.callsFake(() => done())
|
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() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.EditorController.promises.moveEntity).to.have.been.calledWith(
|
|
|
|
this.project._id,
|
|
|
|
this.entityId,
|
|
|
|
this.folderId,
|
|
|
|
this.entityType,
|
|
|
|
this.user._id
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send back a success response', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.sendStatus).to.have.been.calledWith(204)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
describe('deleteEntity', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
beforeEach(function(done) {
|
|
|
|
this.entityId = 'entity-id-123'
|
|
|
|
this.entityType = 'entity-type'
|
2019-05-29 05:21:06 -04:00
|
|
|
this.req.params = {
|
2020-02-27 07:50:29 -05:00
|
|
|
Project_id: this.project._id,
|
|
|
|
entity_id: this.entityId,
|
|
|
|
entity_type: this.entityType
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2020-02-27 07:50:29 -05:00
|
|
|
this.res.sendStatus.callsFake(() => done())
|
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() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(
|
|
|
|
this.EditorController.promises.deleteEntity
|
|
|
|
).to.have.been.calledWith(
|
|
|
|
this.project._id,
|
|
|
|
this.entityId,
|
|
|
|
this.entityType,
|
|
|
|
'editor',
|
|
|
|
this.user._id
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should send back a success response', function() {
|
2020-02-27 07:50:29 -05:00
|
|
|
expect(this.res.sendStatus).to.have.been.calledWith(204)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
2020-03-04 04:37:43 -05:00
|
|
|
|
|
|
|
describe('convertDocToFile', function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
this.req.params = {
|
|
|
|
Project_id: this.project._id.toString(),
|
|
|
|
entity_id: this.doc._id.toString()
|
|
|
|
}
|
|
|
|
this.req.body = { userId: this.user._id.toString() }
|
|
|
|
this.res.json.callsFake(() => done())
|
|
|
|
this.EditorHttpController.convertDocToFile(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2020-03-10 08:36:53 -04:00
|
|
|
describe('when successful', function() {
|
|
|
|
it('should convert the doc to a file', function() {
|
|
|
|
expect(
|
|
|
|
this.ProjectEntityUpdateHandler.promises.convertDocToFile
|
|
|
|
).to.have.been.calledWith(
|
|
|
|
this.project._id.toString(),
|
|
|
|
this.doc._id.toString(),
|
|
|
|
this.user._id.toString()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the file id in the response', function() {
|
|
|
|
expect(this.res.json).to.have.been.calledWith({
|
|
|
|
fileId: this.file._id.toString()
|
|
|
|
})
|
|
|
|
})
|
2020-03-04 04:37:43 -05:00
|
|
|
})
|
|
|
|
|
2020-03-10 08:36:53 -04:00
|
|
|
describe('when the doc has ranges', function() {
|
|
|
|
it('should return a 422', function(done) {
|
|
|
|
this.ProjectEntityUpdateHandler.promises.convertDocToFile.rejects(
|
|
|
|
new Errors.DocHasRangesError({})
|
|
|
|
)
|
|
|
|
this.EditorHttpController.convertDocToFile(this.req, this.res, err => {
|
|
|
|
expect(err).to.be.instanceof(HttpErrors.UnprocessableEntityError)
|
|
|
|
done()
|
|
|
|
})
|
2020-03-04 04:37:43 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|