|
|
@@ -11,11 +11,16 @@ describe "CollaboratorsHandler", ->
|
|
|
@CollaboratorHandler = SandboxedModule.require modulePath, requires:
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), err: sinon.stub() }
|
|
|
'../User/UserCreator': @UserCreator = {}
|
|
|
+ '../User/UserGetter': @UserGetter = {}
|
|
|
+ "../Contacts/ContactManager": @ContactManager = {}
|
|
|
"../../models/Project": Project: @Project = {}
|
|
|
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
|
|
+ "./CollaboratorsEmailHandler": @CollaboratorsEmailHandler = {}
|
|
|
|
|
|
@project_id = "mock-project-id"
|
|
|
@user_id = "mock-user-id"
|
|
|
+ @adding_user_id = "adding-user-id"
|
|
|
+ @email = "joe@sharelatex.com"
|
|
|
@callback = sinon.stub()
|
|
|
|
|
|
describe "removeUserFromProject", ->
|
|
|
@@ -36,10 +41,14 @@ describe "CollaboratorsHandler", ->
|
|
|
beforeEach ->
|
|
|
@Project.update = sinon.stub().callsArg(2)
|
|
|
@ProjectEntityHandler.flushProjectToThirdPartyDataStore = sinon.stub().callsArg(1)
|
|
|
+ @CollaboratorHandler.addEmailToProject = sinon.stub().callsArgWith(4, null, @user_id)
|
|
|
+ @UserGetter.getUser = sinon.stub().callsArgWith(2, null, @user = { _id: @user_id, email: @email })
|
|
|
+ @CollaboratorsEmailHandler.notifyUserOfProjectShare = sinon.stub()
|
|
|
+ @ContactManager.addContact = sinon.stub()
|
|
|
|
|
|
describe "as readOnly", ->
|
|
|
beforeEach ->
|
|
|
- @CollaboratorHandler.addUserToProject @project_id, @user_id, "readOnly", @callback
|
|
|
+ @CollaboratorHandler.addUserIdToProject @project_id, @adding_user_id, @user_id, "readOnly", @callback
|
|
|
|
|
|
it "should add the user to the readOnly_refs", ->
|
|
|
@Project.update
|
|
|
@@ -54,10 +63,20 @@ describe "CollaboratorsHandler", ->
|
|
|
@ProjectEntityHandler.flushProjectToThirdPartyDataStore
|
|
|
.calledWith(@project_id)
|
|
|
.should.equal true
|
|
|
+
|
|
|
+ it "should send an email to the shared-with user", ->
|
|
|
+ @CollaboratorsEmailHandler.notifyUserOfProjectShare
|
|
|
+ .calledWith(@project_id, @email)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should add the user as a contact for the adding user", ->
|
|
|
+ @ContactManager.addContact
|
|
|
+ .calledWith(@adding_user_id, @user_id)
|
|
|
+ .should.equal true
|
|
|
|
|
|
describe "as readAndWrite", ->
|
|
|
beforeEach ->
|
|
|
- @CollaboratorHandler.addUserToProject @project_id, @user_id, "readAndWrite", @callback
|
|
|
+ @CollaboratorHandler.addUserIdToProject @project_id, @adding_user_id, @user_id, "readAndWrite", @callback
|
|
|
|
|
|
it "should add the user to the collaberator_refs", ->
|
|
|
@Project.update
|
|
|
@@ -75,7 +94,7 @@ describe "CollaboratorsHandler", ->
|
|
|
|
|
|
describe "with invalid privilegeLevel", ->
|
|
|
beforeEach ->
|
|
|
- @CollaboratorHandler.addUserToProject @project_id, @user_id, "notValid", @callback
|
|
|
+ @CollaboratorHandler.addUserIdToProject @project_id, @adding_user_id, @user_id, "notValid", @callback
|
|
|
|
|
|
it "should call the callback with an error", ->
|
|
|
@callback.calledWith(new Error()).should.equal true
|
|
|
@@ -83,11 +102,11 @@ describe "CollaboratorsHandler", ->
|
|
|
describe "addEmailToProject", ->
|
|
|
beforeEach ->
|
|
|
@UserCreator.getUserOrCreateHoldingAccount = sinon.stub().callsArgWith(1, null, @user = {_id: @user_id})
|
|
|
- @CollaboratorHandler.addUserToProject = sinon.stub().callsArg(3)
|
|
|
+ @CollaboratorHandler.addUserIdToProject = sinon.stub().callsArg(4)
|
|
|
|
|
|
describe "with a valid email", ->
|
|
|
beforeEach ->
|
|
|
- @CollaboratorHandler.addEmailToProject @project_id, (@email = "Joe@example.com"), (@privilegeLevel = "readAndWrite"), @callback
|
|
|
+ @CollaboratorHandler.addEmailToProject @project_id, @adding_user_id, (@email = "Joe@example.com"), (@privilegeLevel = "readAndWrite"), @callback
|
|
|
|
|
|
it "should get the user with the lowercased email", ->
|
|
|
@UserCreator.getUserOrCreateHoldingAccount
|
|
|
@@ -95,8 +114,8 @@ describe "CollaboratorsHandler", ->
|
|
|
.should.equal true
|
|
|
|
|
|
it "should add the user to the project by id", ->
|
|
|
- @CollaboratorHandler.addUserToProject
|
|
|
- .calledWith(@project_id, @user_id, @privilegeLevel)
|
|
|
+ @CollaboratorHandler.addUserIdToProject
|
|
|
+ .calledWith(@project_id, @adding_user_id, @user_id, @privilegeLevel)
|
|
|
.should.equal true
|
|
|
|
|
|
it "should return the callback with the user_id", ->
|
|
|
@@ -104,13 +123,13 @@ describe "CollaboratorsHandler", ->
|
|
|
|
|
|
describe "with an invalid email", ->
|
|
|
beforeEach ->
|
|
|
- @CollaboratorHandler.addEmailToProject @project_id, "not-and-email", (@privilegeLevel = "readAndWrite"), @callback
|
|
|
+ @CollaboratorHandler.addEmailToProject @project_id, @adding_user_id, "not-and-email", (@privilegeLevel = "readAndWrite"), @callback
|
|
|
|
|
|
it "should call the callback with an error", ->
|
|
|
@callback.calledWith(new Error()).should.equal true
|
|
|
|
|
|
it "should not add any users to the proejct", ->
|
|
|
- @CollaboratorHandler.addUserToProject.called.should.equal false
|
|
|
+ @CollaboratorHandler.addUserIdToProject.called.should.equal false
|
|
|
|
|
|
|
|
|
|