created CollaboratorsHandler
This commit is contained in:
+5
-3
@@ -11,9 +11,11 @@ ObjectId = require("mongojs").ObjectId
|
||||
|
||||
describe "CollaboratorsController", ->
|
||||
beforeEach ->
|
||||
@CollaboratorsHandler =
|
||||
removeUserFromProject:sinon.stub()
|
||||
@CollaboratorsController = SandboxedModule.require modulePath, requires:
|
||||
"../Project/ProjectGetter": @ProjectGetter = {}
|
||||
"../../handlers/ProjectHandler": @ProjectHandler = class ProjectHandler
|
||||
"./CollaboratorsHandler": @CollaboratorsHandler
|
||||
@res = new MockResponse()
|
||||
@req = new MockRequest()
|
||||
|
||||
@@ -54,12 +56,12 @@ describe "CollaboratorsController", ->
|
||||
user: _id: @user_id = "user-id-123"
|
||||
destroy:->
|
||||
@req.params = project_id: @project_id
|
||||
@ProjectHandler::removeUserFromProject = sinon.stub().callsArg(2)
|
||||
@CollaboratorsHandler.removeUserFromProject = sinon.stub().callsArg(2)
|
||||
|
||||
@CollaboratorsController.removeSelfFromProject(@req, @res)
|
||||
|
||||
it "should remove the logged in user from the project", ->
|
||||
@ProjectHandler::removeUserFromProject.calledWith(@project_id, @user_id)
|
||||
@CollaboratorsHandler.removeUserFromProject.calledWith(@project_id, @user_id)
|
||||
|
||||
it "should redirect to the project page", ->
|
||||
@res.redirectedTo.should.equal "/project"
|
||||
|
||||
@@ -14,26 +14,48 @@ describe "CollaboratorsHandler", ->
|
||||
email:"bob@bob.com"
|
||||
@UserModel =
|
||||
findById:sinon.stub().callsArgWith(1, null, @user)
|
||||
update: sinon.stub()
|
||||
|
||||
@settings = {}
|
||||
@ProjectModel =
|
||||
update: sinon.stub().callsArgWith(1)
|
||||
@CollaboratorHandler = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex": log:->
|
||||
'../models/User': User:@UserModel
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
'../../models/User': User:@UserModel
|
||||
"../../models/Project": Project:@ProjectModel
|
||||
|
||||
@project_id = "123l2j13lkj"
|
||||
@user_id = "132kj1lk2j"
|
||||
|
||||
describe "changeUsersPrivlageLevel", ->
|
||||
describe "changeUsersPrivilegeLevel", ->
|
||||
|
||||
|
||||
it "should call removeUserFromProject then addUserToProject", (done)->
|
||||
@CollaboratorHandler.removeUserFromProject = sinon.stub().callsArgWith(2)
|
||||
@CollaboratorHandler.addUserToProject = sinon.stub().callsArgWith(3)
|
||||
newPrivalageLevel = "readAndWrite"
|
||||
@CollaboratorHandler.changeUsersPrivlageLevel @project_id, @user_id, newPrivalageLevel, =>
|
||||
@CollaboratorHandler.changeUsersPrivilegeLevel @project_id, @user_id, newPrivalageLevel, =>
|
||||
@CollaboratorHandler.removeUserFromProject.calledWith(@project_id, @user_id).should.equal true
|
||||
@CollaboratorHandler.addUserToProject.calledWith(@project_id, @user_id, newPrivalageLevel)
|
||||
done()
|
||||
|
||||
|
||||
describe "removeUserFromProject", ->
|
||||
|
||||
beforeEach ->
|
||||
@ProjectModel.update.callsArgWith(2)
|
||||
|
||||
it "should remove the user from mongo", (done)->
|
||||
|
||||
@CollaboratorHandler.removeUserFromProject @project_id, @user_id, =>
|
||||
update = @ProjectModel.update.args[0][1]
|
||||
assert.deepEqual update, "$pull":{collaberator_refs:@user_id, readOnly_refs:@user_id}
|
||||
done()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ describe "EditorController", ->
|
||||
@ProjectOptionsHandler =
|
||||
setCompiler : sinon.spy()
|
||||
setSpellCheckLanguage: sinon.spy()
|
||||
@ProjectEntityHandler = {}
|
||||
@ProjectEntityHandler =
|
||||
flushProjectToThirdPartyDataStore:sinon.stub()
|
||||
@ProjectEditorHandler =
|
||||
buildProjectModelView : sinon.stub().returns(@projectModelView)
|
||||
@ProjectHandler = class ProjectHandler
|
||||
@Project =
|
||||
findPopulatedById: sinon.stub().callsArgWith(1, null, @project)
|
||||
@LimitationsManager = {}
|
||||
@@ -51,17 +51,24 @@ describe "EditorController", ->
|
||||
@TpdsPollingBackgroundTasks = {}
|
||||
@ProjectDetailsHandler =
|
||||
setProjectDescription:sinon.stub()
|
||||
@CollaboratorsHandler =
|
||||
removeUserFromProject: sinon.stub().callsArgWith(2)
|
||||
addUserToProject: sinon.stub().callsArgWith(3)
|
||||
@ProjectDeleter =
|
||||
deleteProject: sinon.stub()
|
||||
|
||||
@EditorController = SandboxedModule.require modulePath, requires:
|
||||
"../../infrastructure/Server" : io : @io
|
||||
'../Project/ProjectEditorHandler' : @ProjectEditorHandler
|
||||
'../Project/ProjectEntityHandler' : @ProjectEntityHandler
|
||||
'../Project/ProjectOptionsHandler' : @ProjectOptionsHandler
|
||||
'../Project/ProjectDetailsHandler': @ProjectDetailsHandler
|
||||
'../Project/ProjectDeleter' : @ProjectDeleter
|
||||
'../Project/ProjectGetter' : @ProjectGetter = {}
|
||||
'../Collaborators/CollaboratorsHandler': @CollaboratorsHandler
|
||||
'../DocumentUpdater/DocumentUpdaterHandler' : @DocumentUpdaterHandler
|
||||
'../Subscription/LimitationsManager' : @LimitationsManager
|
||||
'../Security/AuthorizationManager' : @AuthorizationManager
|
||||
'../../handlers/ProjectHandler' : @ProjectHandler
|
||||
"../Versioning/AutomaticSnapshotManager" : @AutomaticSnapshotManager
|
||||
"../Versioning/VersioningApiHandler" : @VersioningApiHandler
|
||||
'../../models/Project' : Project: @Project
|
||||
@@ -293,25 +300,29 @@ describe "EditorController", ->
|
||||
@email = "Jane.Doe@example.com"
|
||||
@priveleges = "readOnly"
|
||||
@addedUser = { _id: "added-user" }
|
||||
@ProjectHandler::addUserToProject = sinon.stub().callsArgWith(3, @addedUser)
|
||||
@CollaboratorsHandler.addUserToProject = sinon.stub().callsArgWith(3, null, @addedUser)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "when the project can accept more collaborators", ->
|
||||
beforeEach ->
|
||||
@LimitationsManager.isCollaboratorLimitReached = sinon.stub().callsArgWith(1, null, false)
|
||||
@EditorController.addUserToProject(@project_id, @email, @priveleges, @callback)
|
||||
|
||||
it "should add the user to the project", ->
|
||||
@ProjectHandler::addUserToProject
|
||||
.calledWith(@project_id, @email.toLowerCase(), @priveleges)
|
||||
.should.equal true
|
||||
it "should add the user to the project", (done)->
|
||||
@EditorController.addUserToProject @project_id, @email, @priveleges, =>
|
||||
@CollaboratorsHandler.addUserToProject.calledWith(@project_id, @email.toLowerCase(), @priveleges).should.equal true
|
||||
done()
|
||||
|
||||
it "should emit a userAddedToProject event", ->
|
||||
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "userAddedToProject", @addedUser).should.equal true
|
||||
it "should emit a userAddedToProject event", (done)->
|
||||
@EditorController.addUserToProject @project_id, @email, @priveleges, =>
|
||||
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "userAddedToProject", @addedUser).should.equal true
|
||||
done()
|
||||
|
||||
it "should return true to the callback", (done)->
|
||||
@EditorController.addUserToProject @project_id, @email, @priveleges, (err, result)=>
|
||||
result.should.equal true
|
||||
done()
|
||||
|
||||
it "should return true to the callback", ->
|
||||
@callback.calledWith(null, true).should.equal true
|
||||
|
||||
describe "when the project cannot accept more collaborators", ->
|
||||
beforeEach ->
|
||||
@@ -319,7 +330,7 @@ describe "EditorController", ->
|
||||
@EditorController.addUserToProject(@project_id, @email, @priveleges, @callback)
|
||||
|
||||
it "should not add the user to the project", ->
|
||||
@ProjectHandler::addUserToProject.called.should.equal false
|
||||
@CollaboratorsHandler.addUserToProject.called.should.equal false
|
||||
|
||||
it "should not emit a userAddedToProject event", ->
|
||||
@EditorRealTimeController.emitToRoom.called.should.equal false
|
||||
@@ -331,13 +342,13 @@ describe "EditorController", ->
|
||||
describe "removeUserFromProject", ->
|
||||
beforeEach ->
|
||||
@removed_user_id = "removed-user-id"
|
||||
@ProjectHandler::removeUserFromProject = sinon.stub().callsArgWith(2)
|
||||
@CollaboratorsHandler.removeUserFromProject = sinon.stub().callsArgWith(2)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
|
||||
@EditorController.removeUserFromProject(@project_id, @removed_user_id)
|
||||
|
||||
it "remove the user from the project", ->
|
||||
@ProjectHandler::removeUserFromProject
|
||||
@CollaboratorsHandler.removeUserFromProject
|
||||
.calledWith(@project_id, @removed_user_id)
|
||||
.should.equal true
|
||||
|
||||
@@ -613,12 +624,12 @@ describe "EditorController", ->
|
||||
|
||||
beforeEach ->
|
||||
@err = "errro"
|
||||
@ProjectHandler::deleteProject = sinon.stub().callsArgWith(1, @err)
|
||||
@ProjectDeleter.deleteProject = sinon.stub().callsArgWith(1, @err)
|
||||
|
||||
it "should call the project handler", (done)->
|
||||
@EditorController.deleteProject @project_id, (err)=>
|
||||
err.should.equal @err
|
||||
@ProjectHandler::deleteProject.calledWith(@project_id).should.equal true
|
||||
@ProjectDeleter.deleteProject.calledWith(@project_id).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
@@ -673,7 +684,7 @@ describe "EditorController", ->
|
||||
@ProjectDetailsHandler.renameProject = sinon.stub().callsArgWith(2, @err)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
|
||||
it "should call the ProjectHandler", (done)->
|
||||
it "should call the EditorController", (done)->
|
||||
@EditorController.renameProject @project_id, @newName, =>
|
||||
@ProjectDetailsHandler.renameProject.calledWith(@project_id, @newName).should.equal true
|
||||
done()
|
||||
@@ -693,7 +704,7 @@ describe "EditorController", ->
|
||||
@ProjectDetailsHandler.setPublicAccessLevel = sinon.stub().callsArgWith(2, @err)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
|
||||
it "should call the ProjectHandler", (done)->
|
||||
it "should call the EditorController", (done)->
|
||||
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
||||
@ProjectDetailsHandler.setPublicAccessLevel.calledWith(@project_id, @newAccessLevel).should.equal true
|
||||
done()
|
||||
|
||||
Reference in New Issue
Block a user