@@ -9,7 +9,14 @@ import util from '../../util';
9
9
import server from '../../app' ;
10
10
import testUtil from '../../tests/util' ;
11
11
import 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' ;
13
20
14
21
const should = chai . should ( ) ;
15
22
@@ -201,6 +208,69 @@ describe('Project Members create', () => {
201
208
} ) ;
202
209
} ) ;
203
210
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 . TOPCODER_ADMIN ,
223
+ } ] ,
224
+ } ,
225
+ } ,
226
+ } ) ,
227
+ } ) ;
228
+ sandbox . stub ( util , 'getHttpClient' , ( ) => mockHttpClient ) ;
229
+ request ( server )
230
+ . post ( `/v5/projects/${ project1 . id } /members/` )
231
+ . set ( {
232
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
233
+ } )
234
+ . expect ( 'Content-Type' , / j s o n / )
235
+ . expect ( 201 )
236
+ . end ( ( err , res ) => {
237
+ if ( err ) {
238
+ done ( err ) ;
239
+ } else {
240
+ const resJson = res . body ;
241
+ should . exist ( resJson ) ;
242
+ resJson . role . should . equal ( 'manager' ) ;
243
+ resJson . isPrimary . should . be . truthy ;
244
+ resJson . projectId . should . equal ( project1 . id ) ;
245
+ resJson . userId . should . equal ( 40051333 ) ;
246
+ server . services . pubsub . publish . calledWith ( 'project.member.added' ) . should . be . true ;
247
+ done ( ) ;
248
+ }
249
+ } ) ;
250
+ } ) ;
251
+
252
+ it ( 'should return 401 if register admin as role other than manager (copilot) ' , ( done ) => {
253
+ request ( server )
254
+ . post ( `/v5/projects/${ project1 . id } /members/` )
255
+ . set ( {
256
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
257
+ } )
258
+ . send ( { role : PROJECT_MEMBER_ROLE . COPILOT } )
259
+ . expect ( 'Content-Type' , / j s o n / )
260
+ . expect ( 401 , done ) ;
261
+ } ) ;
262
+
263
+ it ( 'should return 401 if register admin as role other than manager (project manager) ' , ( done ) => {
264
+ request ( server )
265
+ . post ( `/v5/projects/${ project1 . id } /members/` )
266
+ . set ( {
267
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
268
+ } )
269
+ . send ( { role : PROJECT_MEMBER_ROLE . PROJECT_MANAGER } )
270
+ . expect ( 'Content-Type' , / j s o n / )
271
+ . expect ( 401 , done ) ;
272
+ } ) ;
273
+
204
274
describe ( 'Bus api' , ( ) => {
205
275
let createEventSpy ;
206
276
0 commit comments