@@ -17,11 +17,11 @@ test.before(async () => {
1717
1818 // stub hydra introspect
1919 let introspectStub = sinon . stub ( hydra , 'introspect' )
20- introspectStub . withArgs ( 'validToken ' ) . returns ( {
20+ introspectStub . withArgs ( 'user100 ' ) . returns ( {
2121 active : true ,
2222 sub : '100'
2323 } )
24- introspectStub . withArgs ( 'differentUser ' ) . returns ( {
24+ introspectStub . withArgs ( 'user101 ' ) . returns ( {
2525 active : true ,
2626 sub : '101'
2727 } )
@@ -39,11 +39,11 @@ test.after.always(async () => {
3939test ( 'a team moderator can update a team' , async t => {
4040 let res = await agent . post ( '/api/teams' )
4141 . send ( { name : 'road team 1' } )
42- . set ( 'Authorization' , `Bearer validToken ` )
42+ . set ( 'Authorization' , `Bearer user100 ` )
4343 . expect ( 200 )
4444
4545 let res2 = await agent . put ( `/api/teams/${ res . body . id } ` )
46- . set ( 'Authorization' , `Bearer validToken ` )
46+ . set ( 'Authorization' , `Bearer user100 ` )
4747 . send ( { name : 'building team 1' } )
4848
4949 t . is ( res2 . status , 200 )
@@ -52,12 +52,65 @@ test('a team moderator can update a team', async t => {
5252test ( 'a non-team moderator cannot update a team' , async t => {
5353 let res = await agent . post ( '/api/teams' )
5454 . send ( { name : 'road team 2' } )
55- . set ( 'Authorization' , `Bearer validToken ` )
55+ . set ( 'Authorization' , `Bearer user100 ` )
5656 . expect ( 200 )
5757
5858 let res2 = await agent . put ( `/api/teams/${ res . body . id } ` )
59- . set ( 'Authorization' , `Bearer differentUser ` )
59+ . set ( 'Authorization' , `Bearer user101 ` )
6060 . send ( { name : 'building team 2' } )
6161
6262 t . is ( res2 . status , 401 )
6363} )
64+
65+ test ( 'an org team can be updated by the the org manager' , async t => {
66+ // Let's create an organization, user100 is the owner
67+ const res = await agent . post ( '/api/organizations' )
68+ . send ( { name : 'org manager can update team' } )
69+ . set ( 'Authorization' , `Bearer user100` )
70+ . expect ( 200 )
71+
72+ // Let's set user101 to be a manager of this organization and create a
73+ // team in the organization
74+ await agent . put ( `/api/organizations/${ res . body . id } /addManager/101` )
75+ . set ( 'Authorization' , `Bearer user100` )
76+ . expect ( 200 )
77+
78+ const res2 = await agent . post ( `/api/organizations/${ res . body . id } /teams` )
79+ . send ( { name : 'org team can be updated by manager - team' } )
80+ . set ( 'Authorization' , `Bearer user101` )
81+ . expect ( 200 )
82+
83+ // Use the manager to update the team
84+ const res3 = await agent . put ( `/api/teams/${ res2 . body . id } ` )
85+ . send ( { name : 'org team can be updated by manager - team2' } )
86+ . set ( 'Authorization' , `Bearer user101` )
87+
88+ t . is ( res3 . status , 200 )
89+ } )
90+
91+ test ( 'an org team can be updated by the owner of the org' , async t => {
92+ // Let's create an organization, user100 is the owner
93+ const res = await agent . post ( '/api/organizations' )
94+ . send ( { name : 'org owner can update team' } )
95+ . set ( 'Authorization' , `Bearer user100` )
96+ . expect ( 200 )
97+
98+ // Let's set user101 to be a manager of this organization and create a
99+ // team in the organization
100+ await agent . put ( `/api/organizations/${ res . body . id } /addManager/101` )
101+ . set ( 'Authorization' , `Bearer user100` )
102+ . expect ( 200 )
103+
104+ const res2 = await agent . post ( `/api/organizations/${ res . body . id } /teams` )
105+ . send ( { name : 'org team can be updated by owner - team' } )
106+ . set ( 'Authorization' , `Bearer user101` )
107+ . expect ( 200 )
108+
109+ // user101 is the moderator and manager, but user100 should be able
110+ // to edit this team
111+ const res3 = await agent . put ( `/api/teams/${ res2 . body . id } ` )
112+ . send ( { name : 'org team can be updated by owner - team2' } )
113+ . set ( 'Authorization' , `Bearer user100` )
114+
115+ t . is ( res3 . status , 200 )
116+ } )
0 commit comments