@@ -12,6 +12,7 @@ import {
12
12
PutExchange ,
13
13
RequestBody ,
14
14
RequestForm ,
15
+ RequestHeader ,
15
16
RequestParam ,
16
17
} from './decorators' ;
17
18
import { StubDiscoveryService } from './fixtures/stub-discovery.service' ;
@@ -289,4 +290,48 @@ describe('NodeFetchInjector', () => {
289
290
'application/x-www-form-urlencoded' ,
290
291
) ;
291
292
} ) ;
293
+
294
+ test ( 'should include header provided with key' , async ( ) => {
295
+ // given
296
+ @HttpInterface ( )
297
+ class SampleClient {
298
+ @GetExchange ( 'https://example.com/api' )
299
+ async request ( @RequestHeader ( 'Cookie' ) foo : string ) : Promise < string > {
300
+ return 'request' ;
301
+ }
302
+ }
303
+ const instance = discoveryService . addProvider ( SampleClient ) ;
304
+ httpClient . addResponse ( { status : 'ok' } ) ;
305
+ nodeFetchInjector . onModuleInit ( ) ;
306
+
307
+ // when
308
+ await instance . request ( 'value' ) ;
309
+
310
+ // then
311
+ expect ( httpClient . requestInfo ) . toHaveLength ( 1 ) ;
312
+ expect ( httpClient . requestInfo [ 0 ] . headers . get ( 'Cookie' ) ) . toBe ( 'value' ) ;
313
+ } ) ;
314
+
315
+ test ( 'should include header provided without key' , async ( ) => {
316
+ // given
317
+ @HttpInterface ( )
318
+ class SampleClient {
319
+ @GetExchange ( 'https://example.com/api' )
320
+ async request (
321
+ @RequestHeader ( ) header : { Cookie : string } ,
322
+ ) : Promise < string > {
323
+ return 'request' ;
324
+ }
325
+ }
326
+ const instance = discoveryService . addProvider ( SampleClient ) ;
327
+ httpClient . addResponse ( { status : 'ok' } ) ;
328
+ nodeFetchInjector . onModuleInit ( ) ;
329
+
330
+ // when
331
+ await instance . request ( { Cookie : 'value' } ) ;
332
+
333
+ // then
334
+ expect ( httpClient . requestInfo ) . toHaveLength ( 1 ) ;
335
+ expect ( httpClient . requestInfo [ 0 ] . headers . get ( 'Cookie' ) ) . toBe ( 'value' ) ;
336
+ } ) ;
292
337
} ) ;
0 commit comments