Skip to content

Commit

Permalink
test: add test for http client option
Browse files Browse the repository at this point in the history
Co-authored-by: imdudu1 <[email protected]>
  • Loading branch information
jbl428 and imdudu1 committed May 5, 2023
1 parent 1f20805 commit a79992b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fixtures/stub-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export class StubHttpClient implements HttpClient {
clear(): void {
this.#requestInfo = [];
this.#responses = [];
this.#options = [];
}
}
22 changes: 22 additions & 0 deletions lib/supports/node-fetch.injector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { GraphQLExchange } from '../decorators/graphql-exchange.decorator';
import { ResponseBody } from '../decorators/response-body.decorator';
import { StubDiscoveryService } from '../fixtures/stub-discovery.service';
import { StubHttpClient } from '../fixtures/stub-http-client';
import { type HttpClientOptions } from '../types';

describe('NodeFetchInjector', () => {
const metadataScanner = new MetadataScanner();
Expand Down Expand Up @@ -216,6 +217,27 @@ describe('NodeFetchInjector', () => {
expect(httpClient.requestInfo[0].method).toBe(method);
});

test('should use http config option from decorator', async () => {
// given
const options: HttpClientOptions = { timeout: 12345 };
@HttpInterface('https://example.com')
class SampleClient {
@GetExchange('/api', options)
async request(): Promise<string> {
return 'request';
}
}
const instance = discoveryService.addProvider(SampleClient);
nodeFetchInjector.onModuleInit();

// when
await instance.request();

// then
expect(httpClient.options).toHaveLength(1);
expect(httpClient.options[0]).toBe(options);
});

test('should include body', async () => {
// given
@HttpInterface()
Expand Down

0 comments on commit a79992b

Please sign in to comment.