|
|
@@ -22,6 +22,93 @@ describe "CollaboratorsHandler", ->
|
|
|
@adding_user_id = "adding-user-id"
|
|
|
@email = "joe@sharelatex.com"
|
|
|
@callback = sinon.stub()
|
|
|
+
|
|
|
+ describe "getMemberIdsWithPrivilegeLevels", ->
|
|
|
+ beforeEach ->
|
|
|
+ @Project.findOne = sinon.stub()
|
|
|
+ @Project.findOne.withArgs({_id: @project_id}, {collaberator_refs: 1, readOnly_refs: 1}).yields(null, @project = {
|
|
|
+ readOnly_refs: [ "read-only-ref-1", "read-only-ref-2" ]
|
|
|
+ collaberator_refs: [ "read-write-ref-1", "read-write-ref-2" ]
|
|
|
+ })
|
|
|
+ @CollaboratorHandler.getMemberIdsWithPrivilegeLevels @project_id, @callback
|
|
|
+
|
|
|
+ it "should return an array of member ids with their privilege levels", ->
|
|
|
+ @callback
|
|
|
+ .calledWith(null, [
|
|
|
+ { id: "read-only-ref-1", privilegeLevel: "readOnly" }
|
|
|
+ { id: "read-only-ref-2", privilegeLevel: "readOnly" }
|
|
|
+ { id: "read-write-ref-1", privilegeLevel: "readAndWrite" }
|
|
|
+ { id: "read-write-ref-2", privilegeLevel: "readAndWrite" }
|
|
|
+ ])
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "getMembersWithPrivilegeLevels", ->
|
|
|
+ beforeEach ->
|
|
|
+ @CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()
|
|
|
+ @CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
|
|
|
+ { id: "read-only-ref-1", privilegeLevel: "readOnly" }
|
|
|
+ { id: "read-only-ref-2", privilegeLevel: "readOnly" }
|
|
|
+ { id: "read-write-ref-1", privilegeLevel: "readAndWrite" }
|
|
|
+ { id: "read-write-ref-2", privilegeLevel: "readAndWrite" }
|
|
|
+ ])
|
|
|
+ @UserGetter.getUser = sinon.stub()
|
|
|
+ @UserGetter.getUser.withArgs("read-only-ref-1").yields(null, { _id: "read-only-ref-1" })
|
|
|
+ @UserGetter.getUser.withArgs("read-only-ref-2").yields(null, { _id: "read-only-ref-2" })
|
|
|
+ @UserGetter.getUser.withArgs("read-write-ref-1").yields(null, { _id: "read-write-ref-1" })
|
|
|
+ @UserGetter.getUser.withArgs("read-write-ref-2").yields(null, { _id: "read-write-ref-2" })
|
|
|
+ @CollaboratorHandler.getMembersWithPrivilegeLevels @project_id, @callback
|
|
|
+
|
|
|
+ it "should return an array of members with their privilege levels", ->
|
|
|
+ @callback
|
|
|
+ .calledWith(undefined, [
|
|
|
+ { user: { _id: "read-only-ref-1" }, privilegeLevel: "readOnly" }
|
|
|
+ { user: { _id: "read-only-ref-2" }, privilegeLevel: "readOnly" }
|
|
|
+ { user: { _id: "read-write-ref-1" }, privilegeLevel: "readAndWrite" }
|
|
|
+ { user: { _id: "read-write-ref-2" }, privilegeLevel: "readAndWrite" }
|
|
|
+ ])
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "isUserMemberOfProject", ->
|
|
|
+ beforeEach ->
|
|
|
+ @CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()
|
|
|
+
|
|
|
+ describe "when user is a member of the project", ->
|
|
|
+ beforeEach ->
|
|
|
+ @CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
|
|
|
+ { id: "not-the-user", privilegeLevel: "readOnly" }
|
|
|
+ { id: @user_id, privilegeLevel: "readAndWrite" }
|
|
|
+ ])
|
|
|
+ @CollaboratorHandler.isUserMemberOfProject @user_id, @project_id, @callback
|
|
|
+
|
|
|
+ it "should return true and the privilegeLevel", ->
|
|
|
+ @callback
|
|
|
+ .calledWith(null, true, "readAndWrite")
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "when user is not a member of the project", ->
|
|
|
+ beforeEach ->
|
|
|
+ @CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
|
|
|
+ { id: "not-the-user", privilegeLevel: "readOnly" }
|
|
|
+ ])
|
|
|
+ @CollaboratorHandler.isUserMemberOfProject @user_id, @project_id, @callback
|
|
|
+
|
|
|
+ it "should return false", ->
|
|
|
+ @callback
|
|
|
+ .calledWith(null, false, null)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "getProjectsUserIsMemberOf", ->
|
|
|
+ beforeEach ->
|
|
|
+ @fields = "mock fields"
|
|
|
+ @Project.find = sinon.stub()
|
|
|
+ @Project.find.withArgs({collaberator_refs:@user_id}, @fields).yields(null, ["mock-read-write-project-1", "mock-read-write-project-2"])
|
|
|
+ @Project.find.withArgs({readOnly_refs:@user_id}, @fields).yields(null, ["mock-read-only-project-1", "mock-read-only-project-2"])
|
|
|
+ @CollaboratorHandler.getProjectsUserIsMemberOf @user_id, @fields, @callback
|
|
|
+
|
|
|
+ it "should call the callback with the projects", ->
|
|
|
+ @callback
|
|
|
+ .calledWith(null, ["mock-read-write-project-1", "mock-read-write-project-2"], ["mock-read-only-project-1", "mock-read-only-project-2"])
|
|
|
+ .should.equal true
|
|
|
|
|
|
describe "removeUserFromProject", ->
|
|
|
beforeEach ->
|