@@ -38,7 +38,11 @@ describe('services/gateway', () => {
3838 * Create express response
3939 */
4040 const createResponse = ( ) =>
41- ( { json : sinon . stub ( ) } as unknown as Response & { json : SinonStub } ) ;
41+ ( {
42+ json : sinon . stub ( ) ,
43+ cookie : sinon . stub ( ) ,
44+ clearCookie : sinon . stub ( ) ,
45+ } as unknown as Response & { json : SinonStub ; cookie : SinonStub ; clearCookie : SinonStub } ) ;
4246
4347 const msName = 'ms1' ;
4448 const msName2 = 'ms2' ;
@@ -301,6 +305,7 @@ describe('services/gateway', () => {
301305 expect ( response . getResult ( ) ) . to . deep . equal ( { endpointTriggerMiddleware, middleware : 'after' } ) ;
302306 expect ( data . method ) . to . equal ( endpointTriggerMiddleware ) ;
303307 expect ( data . params . middleware ) . to . equal ( 'before' ) ;
308+ expect ( data . params . payload . headers . type ) . to . equal ( 'async' ) ; // check pass client headers through payload
304309 expect ( headers . type ) . to . equal ( 'async' ) ;
305310 } ) ;
306311
@@ -386,4 +391,34 @@ describe('services/gateway', () => {
386391 expect ( response ) . to . undefined ;
387392 expect ( stubbed ) . to . calledOnce ;
388393 } ) ;
394+
395+ it ( 'should correctly manipulation with cookie' , async ( ) => {
396+ const req = createRequest ( { method : 'cookies.test-cookies' } ) ;
397+ const res = createResponse ( ) ;
398+
399+ const responseAxios = new MicroserviceResponse ( {
400+ result : {
401+ hello : 'world' ,
402+ payload : {
403+ cookies : [
404+ { action : 'add' , name : 'cookie1' , value : 'test1' , options : { httpOnly : true } } ,
405+ { action : 'remove' , name : 'cookie2' } ,
406+ ] ,
407+ } ,
408+ } ,
409+ } ) ;
410+ const stubbed = sinon . stub ( axios , 'request' ) . resolves ( { data : responseAxios . toJSON ( ) } ) ;
411+
412+ await handleClientRequest ( req , res ) ;
413+
414+ stubbed . restore ( ) ;
415+
416+ const addCookie = res . cookie . firstCall . args ;
417+ const clearCookie = res . clearCookie . firstCall . args ;
418+ const result = res . json . firstCall . firstArg ;
419+
420+ expect ( addCookie ) . to . deep . equal ( [ 'cookie1' , 'test1' , { httpOnly : true } ] ) ;
421+ expect ( clearCookie ) . to . deep . equal ( [ 'cookie2' ] ) ;
422+ expect ( result . payload ) . to . undefined ;
423+ } ) ;
389424} ) ;
0 commit comments