diff --git a/src/http-client.service.spec.ts b/src/http-client.service.spec.ts index 8ab201d..d9e46a9 100644 --- a/src/http-client.service.spec.ts +++ b/src/http-client.service.spec.ts @@ -90,6 +90,23 @@ describe('HTTP client service', () => { describe.each(['get', 'post', 'delete', 'head', 'put', 'patch'])( 'Method invocation: %s', (method: string) => { + it('Should provide client options', () => { + ctx.gotInstance[method] = jest.fn(); + + const service = new HttpClientService( + ctx.gotInstance, + ctx.traceDataService, + ctx.httpServiceConfigProvider, + ); + + service[method]('', { headers: { test: 10 }, retries: 10 }); + + expect(ctx.gotInstance[method]).toBeCalledWith('', { + headers: { test: 10 }, + retries: 10, + }); + }); + it('Should not add headers if shouldTraceServiceInvoke is disabled', () => { ctx.gotInstance[method] = jest.fn(); @@ -126,10 +143,10 @@ describe('HTTP client service', () => { ctx.httpServiceConfigProvider, ); - service[method](''); + service[method]('', { headers: { test: 1 } }); expect(ctx.gotInstance[method]).toBeCalledWith('', { - headers: { 'x-trace-id': 'testId' }, + headers: { 'x-trace-id': 'testId', test: 1 }, }); }); }, diff --git a/src/http-client.service.ts b/src/http-client.service.ts index 56a6151..e2f7346 100644 --- a/src/http-client.service.ts +++ b/src/http-client.service.ts @@ -20,10 +20,7 @@ export class HttpClientService { this.clientConfig = this.httpServiceConfigProvider.getConfig(); } - get( - url: string, - { clientOpts }: { clientOpts: HttpClientOptionsType } = { clientOpts: {} }, - ) { + get(url: string, clientOpts: HttpClientOptionsType = {}) { const { headers } = clientOpts; const traceHeaders = this.getHeaders(); return this.gotInstance.get(url, { @@ -32,10 +29,7 @@ export class HttpClientService { }); } - post( - url: string, - { clientOpts }: { clientOpts: HttpClientOptionsType } = { clientOpts: {} }, - ) { + post(url: string, clientOpts: HttpClientOptionsType = {}) { const { headers } = clientOpts; const traceHeaders = this.getHeaders(); return this.gotInstance.post(url, { @@ -44,10 +38,7 @@ export class HttpClientService { }); } - delete( - url: string, - { clientOpts }: { clientOpts: HttpClientOptionsType } = { clientOpts: {} }, - ) { + delete(url: string, clientOpts: HttpClientOptionsType = {}) { const { headers } = clientOpts; const traceHeaders = this.getHeaders(); return this.gotInstance.delete(url, { @@ -56,10 +47,7 @@ export class HttpClientService { }); } - head( - url: string, - { clientOpts }: { clientOpts: HttpClientOptionsType } = { clientOpts: {} }, - ) { + head(url: string, clientOpts: HttpClientOptionsType = {}) { const { headers } = clientOpts; const traceHeaders = this.getHeaders(); return this.gotInstance.head(url, { @@ -68,10 +56,7 @@ export class HttpClientService { }); } - put( - url: string, - { clientOpts }: { clientOpts: HttpClientOptionsType } = { clientOpts: {} }, - ) { + put(url: string, clientOpts: HttpClientOptionsType = {}) { const { headers } = clientOpts; const traceHeaders = this.getHeaders(); return this.gotInstance.put(url, { @@ -80,10 +65,7 @@ export class HttpClientService { }); } - patch( - url: string, - { clientOpts }: { clientOpts: HttpClientOptionsType } = { clientOpts: {} }, - ) { + patch(url: string, clientOpts: HttpClientOptionsType = {}) { const { headers } = clientOpts; const traceHeaders = this.getHeaders(); return this.gotInstance.patch(url, {