|
@@ -26,32 +26,49 @@ describe "CollaboratorsController", ->
|
|
|
|
|
|
|
|
describe "getCollaborators", ->
|
|
describe "getCollaborators", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @project =
|
|
|
|
|
- _id: @project_id = "project-id-123"
|
|
|
|
|
- @collaborators = ["array of collaborators"]
|
|
|
|
|
- @req.params = Project_id: @project_id
|
|
|
|
|
- @ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, @project)
|
|
|
|
|
- @ProjectGetter.populateProjectWithUsers = sinon.stub().callsArgWith(1, null, @project)
|
|
|
|
|
- @CollaboratorsController._formatCollaborators = sinon.stub().callsArgWith(1, null, @collaborators)
|
|
|
|
|
|
|
+ @req.params =
|
|
|
|
|
+ Project_id: @project_id
|
|
|
|
|
+ @members = [
|
|
|
|
|
+ {
|
|
|
|
|
+ user: { _id: "admin-id", email: "admin@example.com", first_name: "Joe", last_name: "Admin", foo: "bar" }
|
|
|
|
|
+ privilegeLevel: "admin"
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ user: { _id: "rw-id", email: "rw@example.com", first_name: "Jane", last_name: "Write", foo: "bar" }
|
|
|
|
|
+ privilegeLevel: "readAndWrite"
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ user: { _id: "ro-id", email: "ro@example.com", first_name: "Joe", last_name: "Read", foo: "bar" }
|
|
|
|
|
+ privilegeLevel: "readOnly"
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ @CollaboratorsHandler.getMembersWithPrivilegeLevels = sinon.stub()
|
|
|
|
|
+ @CollaboratorsHandler.getMembersWithPrivilegeLevels
|
|
|
|
|
+ .withArgs(@project_id)
|
|
|
|
|
+ .yields(null, @members)
|
|
|
|
|
+ @res.json = sinon.stub()
|
|
|
@CollaboratorsController.getCollaborators(@req, @res)
|
|
@CollaboratorsController.getCollaborators(@req, @res)
|
|
|
|
|
|
|
|
- it "should get the project", ->
|
|
|
|
|
- @ProjectGetter.getProject
|
|
|
|
|
- .calledWith(@project_id, { owner_ref: true, collaberator_refs: true, readOnly_refs: true })
|
|
|
|
|
- .should.equal true
|
|
|
|
|
-
|
|
|
|
|
- it "should populate the users in the project", ->
|
|
|
|
|
- @ProjectGetter.populateProjectWithUsers
|
|
|
|
|
- .calledWith(@project)
|
|
|
|
|
- .should.equal true
|
|
|
|
|
-
|
|
|
|
|
- it "should format the collaborators", ->
|
|
|
|
|
- @CollaboratorsController._formatCollaborators
|
|
|
|
|
- .calledWith(@project)
|
|
|
|
|
- .should.equal true
|
|
|
|
|
-
|
|
|
|
|
it "should return the formatted collaborators", ->
|
|
it "should return the formatted collaborators", ->
|
|
|
- @res.body.should.equal JSON.stringify(@collaborators)
|
|
|
|
|
|
|
+ @res.json
|
|
|
|
|
+ .calledWith([
|
|
|
|
|
+ {
|
|
|
|
|
+ id: "admin-id", email: "admin@example.com", first_name: "Joe", last_name: "Admin"
|
|
|
|
|
+ permissions: ["read", "write", "admin"]
|
|
|
|
|
+ owner: true
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ id: "rw-id", email: "rw@example.com", first_name: "Jane", last_name: "Write"
|
|
|
|
|
+ permissions: ["read", "write"]
|
|
|
|
|
+ owner: false
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ id: "ro-id", email: "ro@example.com", first_name: "Joe", last_name: "Read"
|
|
|
|
|
+ permissions: ["read"]
|
|
|
|
|
+ owner: false
|
|
|
|
|
+ }
|
|
|
|
|
+ ])
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
|
|
|
describe "addUserToProject", ->
|
|
describe "addUserToProject", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
@@ -179,85 +196,3 @@ describe "CollaboratorsController", ->
|
|
|
it "should return a success code", ->
|
|
it "should return a success code", ->
|
|
|
@res.sendStatus.calledWith(204).should.equal true
|
|
@res.sendStatus.calledWith(204).should.equal true
|
|
|
|
|
|
|
|
- describe "_formatCollaborators", ->
|
|
|
|
|
- beforeEach ->
|
|
|
|
|
- @owner =
|
|
|
|
|
- _id: ObjectId()
|
|
|
|
|
- first_name: "Lenny"
|
|
|
|
|
- last_name: "Lion"
|
|
|
|
|
- email: "test@sharelatex.com"
|
|
|
|
|
- hashed_password: "password" # should not be included
|
|
|
|
|
-
|
|
|
|
|
- describe "formatting the owner", ->
|
|
|
|
|
- beforeEach ->
|
|
|
|
|
- @project =
|
|
|
|
|
- owner_ref: @owner
|
|
|
|
|
- collaberator_refs: []
|
|
|
|
|
- @CollaboratorsController._formatCollaborators(@project, @callback)
|
|
|
|
|
-
|
|
|
|
|
- it "should return the owner with read, write and admin permissions", ->
|
|
|
|
|
- @formattedOwner = @callback.args[0][1][0]
|
|
|
|
|
- expect(@formattedOwner).to.deep.equal {
|
|
|
|
|
- id: @owner._id.toString()
|
|
|
|
|
- first_name: @owner.first_name
|
|
|
|
|
- last_name: @owner.last_name
|
|
|
|
|
- email: @owner.email
|
|
|
|
|
- permissions: ["read", "write", "admin"]
|
|
|
|
|
- owner: true
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- describe "formatting a collaborator with write access", ->
|
|
|
|
|
- beforeEach ->
|
|
|
|
|
- @collaborator =
|
|
|
|
|
- _id: ObjectId()
|
|
|
|
|
- first_name: "Douglas"
|
|
|
|
|
- last_name: "Adams"
|
|
|
|
|
- email: "doug@sharelatex.com"
|
|
|
|
|
- hashed_password: "password" # should not be included
|
|
|
|
|
-
|
|
|
|
|
- @project =
|
|
|
|
|
- owner_ref: @owner
|
|
|
|
|
- collaberator_refs: [ @collaborator ]
|
|
|
|
|
- @CollaboratorsController._formatCollaborators(@project, @callback)
|
|
|
|
|
-
|
|
|
|
|
- it "should return the collaborator with read and write permissions", ->
|
|
|
|
|
- @formattedCollaborator = @callback.args[0][1][1]
|
|
|
|
|
- expect(@formattedCollaborator).to.deep.equal {
|
|
|
|
|
- id: @collaborator._id.toString()
|
|
|
|
|
- first_name: @collaborator.first_name
|
|
|
|
|
- last_name: @collaborator.last_name
|
|
|
|
|
- email: @collaborator.email
|
|
|
|
|
- permissions: ["read", "write"]
|
|
|
|
|
- owner: false
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- describe "formatting a collaborator with read only access", ->
|
|
|
|
|
- beforeEach ->
|
|
|
|
|
- @collaborator =
|
|
|
|
|
- _id: ObjectId()
|
|
|
|
|
- first_name: "Douglas"
|
|
|
|
|
- last_name: "Adams"
|
|
|
|
|
- email: "doug@sharelatex.com"
|
|
|
|
|
- hashed_password: "password" # should not be included
|
|
|
|
|
-
|
|
|
|
|
- @project =
|
|
|
|
|
- owner_ref: @owner
|
|
|
|
|
- collaberator_refs: []
|
|
|
|
|
- readOnly_refs: [ @collaborator ]
|
|
|
|
|
- @CollaboratorsController._formatCollaborators(@project, @callback)
|
|
|
|
|
-
|
|
|
|
|
- it "should return the collaborator with read permissions", ->
|
|
|
|
|
- @formattedCollaborator = @callback.args[0][1][1]
|
|
|
|
|
- expect(@formattedCollaborator).to.deep.equal {
|
|
|
|
|
- id: @collaborator._id.toString()
|
|
|
|
|
- first_name: @collaborator.first_name
|
|
|
|
|
- last_name: @collaborator.last_name
|
|
|
|
|
- email: @collaborator.email
|
|
|
|
|
- permissions: ["read"]
|
|
|
|
|
- owner: false
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|