Skip to content

Commit 587d3dc

Browse files
jbl428imdudu1
andcommitted
test: add header test cases
Co-authored-by: imdudu1 <[email protected]>
1 parent 612dbaa commit 587d3dc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lib/node-fetch.injector.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
PutExchange,
1313
RequestBody,
1414
RequestForm,
15+
RequestHeader,
1516
RequestParam,
1617
} from './decorators';
1718
import { StubDiscoveryService } from './fixtures/stub-discovery.service';
@@ -289,4 +290,48 @@ describe('NodeFetchInjector', () => {
289290
'application/x-www-form-urlencoded',
290291
);
291292
});
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+
});
292337
});

0 commit comments

Comments
 (0)