@@ -9,7 +9,14 @@ import util from '../../util';
99import server from '../../app' ;
1010import testUtil from '../../tests/util' ;
1111import busApi from '../../services/busApi' ;
12- import { USER_ROLE , BUS_API_EVENT , RESOURCES , CONNECT_NOTIFICATION_EVENT , INVITE_STATUS } from '../../constants' ;
12+ import {
13+ USER_ROLE ,
14+ BUS_API_EVENT ,
15+ RESOURCES ,
16+ CONNECT_NOTIFICATION_EVENT ,
17+ INVITE_STATUS ,
18+ PROJECT_MEMBER_ROLE ,
19+ } from '../../constants' ;
1320
1421const should = chai . should ( ) ;
1522
@@ -201,6 +208,81 @@ describe('Project Members create', () => {
201208 } ) ;
202209 } ) ;
203210
211+ it ( 'should return 201 and register admin as manager' , ( done ) => {
212+ const mockHttpClient = _ . merge ( testUtil . mockHttpClient , {
213+ get : ( ) => Promise . resolve ( {
214+ status : 200 ,
215+ data : {
216+ id : 'requesterId' ,
217+ version : 'v3' ,
218+ result : {
219+ success : true ,
220+ status : 200 ,
221+ content : [ {
222+ roleName : USER_ROLE . MANAGER ,
223+ } ] ,
224+ } ,
225+ } ,
226+ } ) ,
227+ post : ( ) => Promise . resolve ( {
228+ status : 200 ,
229+ data : {
230+ id : 'requesterId' ,
231+ version : 'v3' ,
232+ result : {
233+ success : true ,
234+ status : 200 ,
235+ content : { } ,
236+ } ,
237+ } ,
238+ } ) ,
239+ } ) ;
240+ sandbox . stub ( util , 'getHttpClient' , ( ) => mockHttpClient ) ;
241+ request ( server )
242+ . post ( `/v5/projects/${ project1 . id } /members/` )
243+ . set ( {
244+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
245+ } )
246+ . expect ( 'Content-Type' , / j s o n / )
247+ . expect ( 201 )
248+ . end ( ( err , res ) => {
249+ if ( err ) {
250+ done ( err ) ;
251+ } else {
252+ const resJson = res . body ;
253+ should . exist ( resJson ) ;
254+ resJson . role . should . equal ( 'manager' ) ;
255+ resJson . isPrimary . should . be . truthy ;
256+ resJson . projectId . should . equal ( project1 . id ) ;
257+ resJson . userId . should . equal ( 40051333 ) ;
258+ server . services . pubsub . publish . calledWith ( 'project.member.added' ) . should . be . true ;
259+ done ( ) ;
260+ }
261+ } ) ;
262+ } ) ;
263+
264+ it ( 'should return 401 if register admin as role other than manager (copilot) ' , ( done ) => {
265+ request ( server )
266+ . post ( `/v5/projects/${ project1 . id } /members/` )
267+ . set ( {
268+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
269+ } )
270+ . send ( { role : PROJECT_MEMBER_ROLE . COPILOT } )
271+ . expect ( 'Content-Type' , / j s o n / )
272+ . expect ( 401 , done ) ;
273+ } ) ;
274+
275+ it ( 'should return 401 if register admin as role other than manager (project manager) ' , ( done ) => {
276+ request ( server )
277+ . post ( `/v5/projects/${ project1 . id } /members/` )
278+ . set ( {
279+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
280+ } )
281+ . send ( { role : PROJECT_MEMBER_ROLE . PROJECT_MANAGER } )
282+ . expect ( 'Content-Type' , / j s o n / )
283+ . expect ( 401 , done ) ;
284+ } ) ;
285+
204286 describe ( 'Bus api' , ( ) => {
205287 let createEventSpy ;
206288
0 commit comments