Change findAllUsersProjects, produce and object rather than lists
This commit is contained in:
@@ -239,6 +239,13 @@ describe "ProjectController", ->
|
||||
@tokenReadOnly = [
|
||||
{_id:7, lastUpdated:4, owner_ref: "user-5"}
|
||||
]
|
||||
@allProjects = {
|
||||
owned: @projects,
|
||||
readAndWrite: @collabertions,
|
||||
readOnly: @readOnly,
|
||||
tokenReadAndWrite: @tokenReadAndWrite,
|
||||
tokenReadOnly: @tokenReadOnly
|
||||
}
|
||||
|
||||
@users =
|
||||
'user-1':
|
||||
@@ -252,7 +259,7 @@ describe "ProjectController", ->
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, false)
|
||||
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
|
||||
@NotificationsHandler.getUserNotifications = sinon.stub().callsArgWith(1, null, @notifications, {})
|
||||
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @projects, @collabertions, @readOnly, @tokenReadAndWrite, @tokenReadOnly)
|
||||
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @allProjects)
|
||||
|
||||
it "should render the project/list page", (done)->
|
||||
@res.render = (pageName, opts)=>
|
||||
@@ -307,6 +314,13 @@ describe "ProjectController", ->
|
||||
{_id:6, lastUpdated:5, owner_ref: "user-4"} # Also in tokenReadAndWrite
|
||||
{_id:7, lastUpdated:4, owner_ref: "user-5"}
|
||||
]
|
||||
@allProjects = {
|
||||
owned: @projects,
|
||||
readAndWrite: @collabertions,
|
||||
readOnly: @readOnly,
|
||||
tokenReadAndWrite: @tokenReadAndWrite,
|
||||
tokenReadOnly: @tokenReadOnly
|
||||
}
|
||||
|
||||
@users =
|
||||
'user-1':
|
||||
@@ -320,7 +334,7 @@ describe "ProjectController", ->
|
||||
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, false)
|
||||
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
|
||||
@NotificationsHandler.getUserNotifications = sinon.stub().callsArgWith(1, null, @notifications, {})
|
||||
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @projects, @collabertions, @readOnly, @tokenReadAndWrite, @tokenReadOnly)
|
||||
@ProjectGetter.findAllUsersProjects.callsArgWith(2, null, @allProjects)
|
||||
|
||||
it "should render the project/list page", (done)->
|
||||
@res.render = (pageName, opts)=>
|
||||
|
||||
@@ -152,12 +152,21 @@ describe "ProjectGetter", ->
|
||||
@CollaboratorsHandler.getProjectsUserIsMemberOf.withArgs(@user_id, @fields).yields(
|
||||
null,
|
||||
{
|
||||
readAndWrite: ["mock-rw-projects"], readOnly: ["mock-ro-projects"]
|
||||
readAndWrite: ["mock-rw-projects"],
|
||||
readOnly: ["mock-ro-projects"],
|
||||
tokenReadAndWrite: ['mock-token-rw-projects'],
|
||||
tokenReadOnly: ['mock-token-ro-projects']
|
||||
}
|
||||
)
|
||||
@ProjectGetter.findAllUsersProjects @user_id, @fields, @callback
|
||||
|
||||
it "should call the callback with all the projects", ->
|
||||
@callback
|
||||
.calledWith(null, ["mock-owned-projects"], ["mock-rw-projects"], ["mock-ro-projects"])
|
||||
.calledWith(null, {
|
||||
owned: ["mock-owned-projects"],
|
||||
readAndWrite: ["mock-rw-projects"],
|
||||
readOnly: ["mock-ro-projects"]
|
||||
tokenReadAndWrite: ['mock-token-rw-projects'],
|
||||
tokenReadOnly: ['mock-token-ro-projects']
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
@@ -317,7 +317,9 @@ describe 'ProjectLocator', ->
|
||||
it 'should return the project from an array case insenstive', (done)->
|
||||
user_id = "123jojoidns"
|
||||
stubbedProject = {name:"findThis"}
|
||||
projects = [{name:"notThis"}, {name:"wellll"}, stubbedProject, {name:"Noooo"}]
|
||||
projects = {
|
||||
owned: [{name:"notThis"}, {name:"wellll"}, stubbedProject, {name:"Noooo"}]
|
||||
}
|
||||
@ProjectGetter.findAllUsersProjects = sinon.stub().callsArgWith(2, null, projects)
|
||||
@locator.findUsersProjectByName user_id, stubbedProject.name.toLowerCase(), (err, project)->
|
||||
project.should.equal stubbedProject
|
||||
@@ -326,7 +328,16 @@ describe 'ProjectLocator', ->
|
||||
it 'should return the project which is not archived', (done)->
|
||||
user_id = "123jojoidns"
|
||||
stubbedProject = {name:"findThis", _id:12331321}
|
||||
projects = [{name:"notThis"}, {name:"wellll"}, {name:"findThis",archived:true}, stubbedProject, {name:"findThis",archived:true}, {name:"Noooo"}]
|
||||
projects = {
|
||||
owned: [
|
||||
{name:"notThis"},
|
||||
{name:"wellll"},
|
||||
{name:"findThis",archived:true},
|
||||
stubbedProject,
|
||||
{name:"findThis",archived:true},
|
||||
{name:"Noooo"}
|
||||
]
|
||||
}
|
||||
@ProjectGetter.findAllUsersProjects = sinon.stub().callsArgWith(2, null, projects)
|
||||
@locator.findUsersProjectByName user_id, stubbedProject.name.toLowerCase(), (err, project)->
|
||||
project._id.should.equal stubbedProject._id
|
||||
@@ -335,8 +346,11 @@ describe 'ProjectLocator', ->
|
||||
it 'should search collab projects as well', (done)->
|
||||
user_id = "123jojoidns"
|
||||
stubbedProject = {name:"findThis"}
|
||||
projects = [{name:"notThis"}, {name:"wellll"}, {name:"Noooo"}]
|
||||
@ProjectGetter.findAllUsersProjects = sinon.stub().callsArgWith(2, null, projects, [stubbedProject])
|
||||
projects = {
|
||||
owned: [{name:"notThis"}, {name:"wellll"}, {name:"Noooo"}]
|
||||
readAndWrite: [stubbedProject]
|
||||
}
|
||||
@ProjectGetter.findAllUsersProjects = sinon.stub().callsArgWith(2, null, projects)
|
||||
@locator.findUsersProjectByName user_id, stubbedProject.name.toLowerCase(), (err, project)->
|
||||
project.should.equal stubbedProject
|
||||
done()
|
||||
|
||||
Reference in New Issue
Block a user