@@ -69,29 +69,46 @@ describe('Project Members create', () => {
69
69
70
70
it ( 'should return 201 when invited then accepted and then 404 if user is already as a member' , ( done ) => {
71
71
const mockHttpClient = _ . merge ( testUtil . mockHttpClient , {
72
- get : ( ) => Promise . resolve ( {
73
- status : 200 ,
74
- data : {
75
- id : 'requesterId' ,
76
- version : 'v3' ,
77
- result : {
78
- success : true ,
79
- status : 200 ,
80
- content : [ {
81
- roleName : USER_ROLE . COPILOT ,
82
- } ] ,
72
+ get : ( url ) => {
73
+ const testCopilot = {
74
+ userId : 40051332 ,
75
+ handle : 'test_copilot1' ,
76
+ firstName : 'Firstname' ,
77
+ lastName : 'Lastname' ,
78
+ email : 'test_copilot1@email.com' ,
79
+ } ;
80
+ const testRoleName = {
81
+ roleName : USER_ROLE . COPILOT_MANAGER ,
82
+ } ;
83
+ const ret = {
84
+ status : 200 ,
85
+ data : {
86
+ id : 'requesterId' ,
87
+ version : 'v3' ,
88
+ result : {
89
+ success : true ,
90
+ status : 200 ,
91
+ content : [ ] ,
92
+ } ,
83
93
} ,
84
- } ,
85
- } ) ,
94
+ } ;
95
+
96
+ if ( url . indexOf ( '/_search' ) >= 0 ) {
97
+ ret . data . result . content . push ( testCopilot ) ;
98
+ } else {
99
+ ret . data . result . content . push ( testRoleName ) ;
100
+ }
101
+ return Promise . resolve ( ret ) ;
102
+ } ,
86
103
} ) ;
87
104
sandbox . stub ( util , 'getHttpClient' , ( ) => mockHttpClient ) ;
88
105
request ( server )
89
- . post ( `/v5/projects/${ project1 . id } /members/invite ` )
106
+ . post ( `/v5/projects/${ project1 . id } /invites ` )
90
107
. set ( {
91
108
Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
92
109
} )
93
110
. send ( {
94
- userIds : [ 40051332 ] ,
111
+ handles : [ 'test_copilot1' ] ,
95
112
role : 'copilot' ,
96
113
} )
97
114
. expect ( 'Content-Type' , / j s o n / )
@@ -105,14 +122,14 @@ describe('Project Members create', () => {
105
122
resJson . role . should . equal ( 'copilot' ) ;
106
123
resJson . projectId . should . equal ( project1 . id ) ;
107
124
resJson . userId . should . equal ( 40051332 ) ;
125
+ should . exist ( resJson . id )
108
126
server . services . pubsub . publish . calledWith ( 'project.member.invite.created' ) . should . be . true ;
109
127
request ( server )
110
- . put ( `/v5/projects/${ project1 . id } /members/invite ` )
128
+ . patch ( `/v5/projects/${ project1 . id } /invites/ ${ resJson . id } ` )
111
129
. set ( {
112
130
Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
113
131
} )
114
132
. send ( {
115
- userId : 40051332 ,
116
133
status : 'accepted' ,
117
134
} )
118
135
. expect ( 'Content-Type' , / j s o n / )
@@ -130,12 +147,11 @@ describe('Project Members create', () => {
130
147
server . services . pubsub . publish . calledWith ( 'project.member.added' ) . should . be . true ;
131
148
132
149
request ( server )
133
- . put ( `/v5/projects/${ project1 . id } /members/invite ` )
150
+ . patch ( `/v5/projects/${ project1 . id } /invites/ ${ resJson . id } ` )
134
151
. set ( {
135
152
Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
136
153
} )
137
154
. send ( {
138
- userId : 40051332 ,
139
155
status : 'accepted' ,
140
156
} )
141
157
. expect ( 'Content-Type' , / j s o n / )
@@ -145,7 +161,7 @@ describe('Project Members create', () => {
145
161
done ( err3 ) ;
146
162
} else {
147
163
const errorMessage = _ . get ( res3 . body , 'message' , '' ) ;
148
- sinon . assert . match ( errorMessage , / .* i n v i t e n o t f o u n d f o r p r o j e c t i d 1 , e m a i l u n d e f i n e d a n d u s e r I d / ) ;
164
+ sinon . assert . match ( errorMessage , / .* i n v i t e n o t f o u n d f o r p r o j e c t i d 1 , i n v i t e I d / ) ;
149
165
done ( ) ;
150
166
}
151
167
} ) ;
@@ -349,27 +365,63 @@ describe('Project Members create', () => {
349
365
} ) ;
350
366
351
367
it ( 'should send correct BUS API messages when copilot added' , ( done ) => {
368
+ const mockHttpClient = _ . merge ( testUtil . mockHttpClient , {
369
+ get : ( url ) => {
370
+ const testCopilot = {
371
+ userId : 40051332 ,
372
+ handle : 'test_copilot1' ,
373
+ firstName : 'Firstname' ,
374
+ lastName : 'Lastname' ,
375
+ email : 'test_copilot1@email.com' ,
376
+ } ;
377
+ const testRoleName = {
378
+ roleName : USER_ROLE . COPILOT_MANAGER ,
379
+ } ;
380
+ const ret = {
381
+ status : 200 ,
382
+ data : {
383
+ id : 'requesterId' ,
384
+ version : 'v3' ,
385
+ result : {
386
+ success : true ,
387
+ status : 200 ,
388
+ content : [ ] ,
389
+ } ,
390
+ } ,
391
+ } ;
392
+
393
+ if ( url . indexOf ( '/_search' ) >= 0 ) {
394
+ ret . data . result . content . push ( testCopilot ) ;
395
+ } else {
396
+ ret . data . result . content . push ( testRoleName ) ;
397
+ }
398
+ return Promise . resolve ( ret ) ;
399
+ } ,
400
+ } ) ;
401
+ sandbox . stub ( util , 'getHttpClient' , ( ) => mockHttpClient ) ;
352
402
request ( server )
353
- . post ( `/v5/projects/${ project1 . id } /members/invite ` )
403
+ . post ( `/v5/projects/${ project1 . id } /invites ` )
354
404
. set ( {
355
405
Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
356
406
} )
357
407
. send ( {
358
- userIds : [ 40051332 ] ,
408
+ handles : [ 'test_copilot1' ] ,
359
409
role : 'copilot' ,
360
410
} )
361
411
. expect ( 201 )
362
- . end ( ( err ) => {
412
+ . end ( ( err , inviteRes ) => {
363
413
if ( err ) {
364
414
done ( err ) ;
365
415
} else {
416
+ const inviteResJson = inviteRes . body . success [ 0 ] ;
417
+ should . exist ( inviteResJson )
418
+ should . exist ( inviteResJson . id )
366
419
request ( server )
367
- . put ( `/v5/projects/${ project1 . id } /members/invite ` )
420
+ . patch ( `/v5/projects/${ project1 . id } /invites/ ${ inviteResJson . id } ` )
368
421
. set ( {
369
422
Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
370
423
} )
371
424
. send ( {
372
- userId : 40051332 ,
373
425
status : 'accepted' ,
374
426
} )
375
427
. expect ( 'Content-Type' , / j s o n / )
0 commit comments