Skip to content

Commit a79992b

Browse files
jbl428imdudu1
andcommitted
test: add test for http client option
Co-authored-by: imdudu1 <[email protected]>
1 parent 1f20805 commit a79992b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/fixtures/stub-http-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ export class StubHttpClient implements HttpClient {
3333
clear(): void {
3434
this.#requestInfo = [];
3535
this.#responses = [];
36+
this.#options = [];
3637
}
3738
}

lib/supports/node-fetch.injector.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { GraphQLExchange } from '../decorators/graphql-exchange.decorator';
2121
import { ResponseBody } from '../decorators/response-body.decorator';
2222
import { StubDiscoveryService } from '../fixtures/stub-discovery.service';
2323
import { StubHttpClient } from '../fixtures/stub-http-client';
24+
import { type HttpClientOptions } from '../types';
2425

2526
describe('NodeFetchInjector', () => {
2627
const metadataScanner = new MetadataScanner();
@@ -216,6 +217,27 @@ describe('NodeFetchInjector', () => {
216217
expect(httpClient.requestInfo[0].method).toBe(method);
217218
});
218219

220+
test('should use http config option from decorator', async () => {
221+
// given
222+
const options: HttpClientOptions = { timeout: 12345 };
223+
@HttpInterface('https://example.com')
224+
class SampleClient {
225+
@GetExchange('/api', options)
226+
async request(): Promise<string> {
227+
return 'request';
228+
}
229+
}
230+
const instance = discoveryService.addProvider(SampleClient);
231+
nodeFetchInjector.onModuleInit();
232+
233+
// when
234+
await instance.request();
235+
236+
// then
237+
expect(httpClient.options).toHaveLength(1);
238+
expect(httpClient.options[0]).toBe(options);
239+
});
240+
219241
test('should include body', async () => {
220242
// given
221243
@HttpInterface()

0 commit comments

Comments
 (0)