Remove ProjectGetter.populateProjectWithUsers
This commit is contained in:
@@ -16,6 +16,7 @@ describe "EditorHttpController", ->
|
||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
||||
"./EditorController": @EditorController = {}
|
||||
'../../infrastructure/Metrics': @Metrics = {inc: sinon.stub()}
|
||||
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler = {}
|
||||
|
||||
@project_id = "mock-project-id"
|
||||
@doc_id = "mock-doc-id"
|
||||
@@ -85,13 +86,14 @@ describe "EditorHttpController", ->
|
||||
@user =
|
||||
_id: @user_id = "user-id"
|
||||
projects: {}
|
||||
@members = ["members", "mock"]
|
||||
@projectModelView =
|
||||
_id: @project_id
|
||||
owner:{_id:"something"}
|
||||
view: true
|
||||
@ProjectEditorHandler.buildProjectModelView = sinon.stub().returns(@projectModelView)
|
||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().callsArgWith(1, null, @project)
|
||||
@ProjectGetter.populateProjectWithUsers = sinon.stub().callsArgWith(1, null, @project)
|
||||
@CollaboratorsHandler.getMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, null, @members)
|
||||
@UserGetter.getUser = sinon.stub().callsArgWith(2, null, @user)
|
||||
|
||||
describe "when authorized", ->
|
||||
@@ -105,8 +107,8 @@ describe "EditorHttpController", ->
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should populate the user references in the project", ->
|
||||
@ProjectGetter.populateProjectWithUsers
|
||||
it "should get the list of users in the project", ->
|
||||
@CollaboratorsHandler.getMembersWithPrivilegeLevels
|
||||
.calledWith(@project)
|
||||
.should.equal true
|
||||
|
||||
|
||||
@@ -38,33 +38,41 @@ describe "ProjectEditorHandler", ->
|
||||
folders : []
|
||||
}]
|
||||
}]
|
||||
owner_ref :
|
||||
_id: "owner-id"
|
||||
first_name : "Owner"
|
||||
last_name : "ShareLaTeX"
|
||||
email : "owner@sharelatex.com"
|
||||
readOnly_refs: [{
|
||||
_id: "read-only-id"
|
||||
first_name : "Read"
|
||||
last_name : "Only"
|
||||
email : "read-only@sharelatex.com"
|
||||
}]
|
||||
collaberator_refs: [{
|
||||
_id: "read-write-id"
|
||||
first_name : "Read"
|
||||
last_name : "Write"
|
||||
email : "read-write@sharelatex.com"
|
||||
}]
|
||||
deletedDocs: [{
|
||||
_id: "deleted-doc-id"
|
||||
name: "main.tex"
|
||||
}]
|
||||
@members = [{
|
||||
user: @owner = {
|
||||
_id: "owner-id"
|
||||
first_name : "Owner"
|
||||
last_name : "ShareLaTeX"
|
||||
email : "owner@sharelatex.com"
|
||||
},
|
||||
privilegeLevel: "admin"
|
||||
},{
|
||||
user: {
|
||||
_id: "read-only-id"
|
||||
first_name : "Read"
|
||||
last_name : "Only"
|
||||
email : "read-only@sharelatex.com"
|
||||
},
|
||||
privilegeLevel: "readOnly"
|
||||
},{
|
||||
user: {
|
||||
_id: "read-write-id"
|
||||
first_name : "Read"
|
||||
last_name : "Write"
|
||||
email : "read-write@sharelatex.com"
|
||||
},
|
||||
privilegeLevel: "readAndWrite"
|
||||
}]
|
||||
@handler = SandboxedModule.require modulePath
|
||||
|
||||
describe "buildProjectModelView", ->
|
||||
describe "with owner and members included", ->
|
||||
beforeEach ->
|
||||
@result = @handler.buildProjectModelView @project
|
||||
@result = @handler.buildProjectModelView @project, @members
|
||||
|
||||
it "should include the id", ->
|
||||
should.exist @result._id
|
||||
@@ -140,41 +148,30 @@ describe "ProjectEditorHandler", ->
|
||||
|
||||
it "should set the deletedByExternalDataSource flag to false when it is not there", ->
|
||||
delete @project.deletedByExternalDataSource
|
||||
result = @handler.buildProjectModelView @project
|
||||
result = @handler.buildProjectModelView @project, @members
|
||||
result.deletedByExternalDataSource.should.equal false
|
||||
|
||||
it "should set the deletedByExternalDataSource flag to false when it is false", ->
|
||||
result = @handler.buildProjectModelView @project
|
||||
result = @handler.buildProjectModelView @project, @members
|
||||
result.deletedByExternalDataSource.should.equal false
|
||||
|
||||
it "should set the deletedByExternalDataSource flag to true when it is true", ->
|
||||
@project.deletedByExternalDataSource = true
|
||||
result = @handler.buildProjectModelView @project
|
||||
result = @handler.buildProjectModelView @project, @members
|
||||
result.deletedByExternalDataSource.should.equal true
|
||||
|
||||
describe "features", ->
|
||||
beforeEach ->
|
||||
@project.owner_ref.features =
|
||||
@owner.features =
|
||||
versioning: true
|
||||
collaborators: 3
|
||||
compileGroup:"priority"
|
||||
compileTimeout: 96
|
||||
@result = @handler.buildProjectModelView @project
|
||||
@result = @handler.buildProjectModelView @project, @members
|
||||
|
||||
it "should copy the owner features to the project", ->
|
||||
@result.features.versioning.should.equal @project.owner_ref.features.versioning
|
||||
@result.features.collaborators.should.equal @project.owner_ref.features.collaborators
|
||||
@result.features.compileGroup.should.equal @project.owner_ref.features.compileGroup
|
||||
@result.features.compileTimeout.should.equal @project.owner_ref.features.compileTimeout
|
||||
@result.features.versioning.should.equal @owner.features.versioning
|
||||
@result.features.collaborators.should.equal @owner.features.collaborators
|
||||
@result.features.compileGroup.should.equal @owner.features.compileGroup
|
||||
@result.features.compileTimeout.should.equal @owner.features.compileTimeout
|
||||
|
||||
|
||||
describe "without owners and members", ->
|
||||
beforeEach ->
|
||||
@result = @handler.buildProjectModelView @project, includeUsers: false
|
||||
|
||||
it "should not include the owner", ->
|
||||
should.not.exist @result.owner
|
||||
|
||||
it "should not include the members", ->
|
||||
should.not.exist @result.members
|
||||
|
||||
|
||||
@@ -79,41 +79,6 @@ describe "ProjectGetter", ->
|
||||
it "should call the callback with the project", ->
|
||||
@callback.calledWith(null, @project).should.equal true
|
||||
|
||||
|
||||
describe "populateProjectWithUsers", ->
|
||||
beforeEach ->
|
||||
@users = []
|
||||
@user_lookup = {}
|
||||
for i in [0..4]
|
||||
@users[i] = _id: ObjectId.createPk()
|
||||
@user_lookup[@users[i]._id.toString()] = @users[i]
|
||||
@project =
|
||||
_id: ObjectId.createPk()
|
||||
owner_ref: @users[0]._id
|
||||
readOnly_refs: [@users[1]._id, @users[2]._id]
|
||||
collaberator_refs: [@users[3]._id, @users[4]._id]
|
||||
@db.users.find = (query, callback) =>
|
||||
callback null, [@user_lookup[query._id.toString()]]
|
||||
sinon.spy @db.users, "find"
|
||||
@ProjectGetter.populateProjectWithUsers @project, (err, project)=>
|
||||
@callback err, project
|
||||
|
||||
it "should look up each user", ->
|
||||
for user in @users
|
||||
@db.users.find.calledWith(_id: user._id).should.equal true
|
||||
|
||||
it "should set the owner_ref to the owner", ->
|
||||
@project.owner_ref.should.equal @users[0]
|
||||
|
||||
it "should set the readOnly_refs to the read only users", ->
|
||||
expect(@project.readOnly_refs).to.deep.equal [@users[1], @users[2]]
|
||||
|
||||
it "should set the collaberator_refs to the collaborators", ->
|
||||
expect(@project.collaberator_refs).to.deep.equal [@users[3], @users[4]]
|
||||
|
||||
it "should call the callback", ->
|
||||
assert.deepEqual @callback.args[0][1], @project
|
||||
|
||||
describe "findAllUsersProjects", ->
|
||||
beforeEach ->
|
||||
@fields = {"mock": "fields"}
|
||||
|
||||
Reference in New Issue
Block a user