@@ -62,29 +62,46 @@ describe('Project Members create', () => {
62
62
63
63
it ( 'should return 201 when invited then accepted and then 404 if user is already as a member' , ( done ) => {
64
64
const mockHttpClient = _ . merge ( testUtil . mockHttpClient , {
65
- get : ( ) => Promise . resolve ( {
66
- status : 200 ,
67
- data : {
68
- id : 'requesterId' ,
69
- version : 'v3' ,
70
- result : {
71
- success : true ,
72
- status : 200 ,
73
- content : [ {
74
- roleName : USER_ROLE . COPILOT ,
75
- } ] ,
65
+ get : ( url ) => {
66
+ const testCopilot = {
67
+ userId : 40051332 ,
68
+ handle : 'test_copilot1' ,
69
+ firstName : 'Firstname' ,
70
+ lastName : 'Lastname' ,
71
+ email : 'test_copilot1@email.com' ,
72
+ } ;
73
+ const testRoleName = {
74
+ roleName : USER_ROLE . COPILOT_MANAGER ,
75
+ } ;
76
+ const ret = {
77
+ status : 200 ,
78
+ data : {
79
+ id : 'requesterId' ,
80
+ version : 'v3' ,
81
+ result : {
82
+ success : true ,
83
+ status : 200 ,
84
+ content : [ ] ,
85
+ } ,
76
86
} ,
77
- } ,
78
- } ) ,
87
+ } ;
88
+
89
+ if ( url . indexOf ( '/_search' ) >= 0 ) {
90
+ ret . data . result . content . push ( testCopilot ) ;
91
+ } else {
92
+ ret . data . result . content . push ( testRoleName ) ;
93
+ }
94
+ return Promise . resolve ( ret ) ;
95
+ } ,
79
96
} ) ;
80
97
sandbox . stub ( util , 'getHttpClient' , ( ) => mockHttpClient ) ;
81
98
request ( server )
82
- . post ( `/v5/projects/${ project1 . id } /members/invite ` )
99
+ . post ( `/v5/projects/${ project1 . id } /invites ` )
83
100
. set ( {
84
101
Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
85
102
} )
86
103
. send ( {
87
- userIds : [ 40051332 ] ,
104
+ handles : [ 'test_copilot1' ] ,
88
105
role : 'copilot' ,
89
106
} )
90
107
. expect ( 'Content-Type' , / j s o n / )
@@ -98,14 +115,14 @@ describe('Project Members create', () => {
98
115
resJson . role . should . equal ( 'copilot' ) ;
99
116
resJson . projectId . should . equal ( project1 . id ) ;
100
117
resJson . userId . should . equal ( 40051332 ) ;
118
+ should . exist ( resJson . id )
101
119
server . services . pubsub . publish . calledWith ( 'project.member.invite.created' ) . should . be . true ;
102
120
request ( server )
103
- . put ( `/v5/projects/${ project1 . id } /members/invite ` )
121
+ . patch ( `/v5/projects/${ project1 . id } /invites/ ${ resJson . id } ` )
104
122
. set ( {
105
123
Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
106
124
} )
107
125
. send ( {
108
- userId : 40051332 ,
109
126
status : 'accepted' ,
110
127
} )
111
128
. expect ( 'Content-Type' , / j s o n / )
@@ -123,12 +140,11 @@ describe('Project Members create', () => {
123
140
server . services . pubsub . publish . calledWith ( 'project.member.added' ) . should . be . true ;
124
141
125
142
request ( server )
126
- . put ( `/v5/projects/${ project1 . id } /members/invite ` )
143
+ . patch ( `/v5/projects/${ project1 . id } /invites/ ${ resJson . id } ` )
127
144
. set ( {
128
145
Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
129
146
} )
130
147
. send ( {
131
- userId : 40051332 ,
132
148
status : 'accepted' ,
133
149
} )
134
150
. expect ( 'Content-Type' , / j s o n / )
@@ -138,7 +154,7 @@ describe('Project Members create', () => {
138
154
done ( err3 ) ;
139
155
} else {
140
156
const errorMessage = _ . get ( res3 . body , 'message' , '' ) ;
141
- 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 / ) ;
157
+ 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 / ) ;
142
158
done ( ) ;
143
159
}
144
160
} ) ;
@@ -279,27 +295,63 @@ describe('Project Members create', () => {
279
295
} ) ;
280
296
281
297
it ( 'should send correct BUS API messages when copilot added' , ( done ) => {
298
+ const mockHttpClient = _ . merge ( testUtil . mockHttpClient , {
299
+ get : ( url ) => {
300
+ const testCopilot = {
301
+ userId : 40051332 ,
302
+ handle : 'test_copilot1' ,
303
+ firstName : 'Firstname' ,
304
+ lastName : 'Lastname' ,
305
+ email : 'test_copilot1@email.com' ,
306
+ } ;
307
+ const testRoleName = {
308
+ roleName : USER_ROLE . COPILOT_MANAGER ,
309
+ } ;
310
+ const ret = {
311
+ status : 200 ,
312
+ data : {
313
+ id : 'requesterId' ,
314
+ version : 'v3' ,
315
+ result : {
316
+ success : true ,
317
+ status : 200 ,
318
+ content : [ ] ,
319
+ } ,
320
+ } ,
321
+ } ;
322
+
323
+ if ( url . indexOf ( '/_search' ) >= 0 ) {
324
+ ret . data . result . content . push ( testCopilot ) ;
325
+ } else {
326
+ ret . data . result . content . push ( testRoleName ) ;
327
+ }
328
+ return Promise . resolve ( ret ) ;
329
+ } ,
330
+ } ) ;
331
+ sandbox . stub ( util , 'getHttpClient' , ( ) => mockHttpClient ) ;
282
332
request ( server )
283
- . post ( `/v5/projects/${ project1 . id } /members/invite ` )
333
+ . post ( `/v5/projects/${ project1 . id } /invites ` )
284
334
. set ( {
285
335
Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
286
336
} )
287
337
. send ( {
288
- userIds : [ 40051332 ] ,
338
+ handles : [ 'test_copilot1' ] ,
289
339
role : 'copilot' ,
290
340
} )
291
341
. expect ( 201 )
292
- . end ( ( err ) => {
342
+ . end ( ( err , inviteRes ) => {
293
343
if ( err ) {
294
344
done ( err ) ;
295
345
} else {
346
+ const inviteResJson = inviteRes . body . success [ 0 ] ;
347
+ should . exist ( inviteResJson )
348
+ should . exist ( inviteResJson . id )
296
349
request ( server )
297
- . put ( `/v5/projects/${ project1 . id } /members/invite ` )
350
+ . patch ( `/v5/projects/${ project1 . id } /invites/ ${ inviteResJson . id } ` )
298
351
. set ( {
299
352
Authorization : `Bearer ${ testUtil . jwts . connectAdmin } ` ,
300
353
} )
301
354
. send ( {
302
- userId : 40051332 ,
303
355
status : 'accepted' ,
304
356
} )
305
357
. expect ( 'Content-Type' , / j s o n / )
0 commit comments