Skip to content

Commit 6923355

Browse files
committed
Allow client to receive optional got configuration object as second
argument
1 parent 57bd289 commit 6923355

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
TIMEOUT,
88
STRICT_AUTHORISATION,
99
} from "@ideal-postcodes/core-interface";
10-
import { Agent } from "./agent";
10+
import { Agent, GotConfig } from "./agent";
1111

1212
const userAgent = `IdealPostcodes ideal-postcodes/core-node`;
1313

@@ -16,8 +16,8 @@ interface Config extends Partial<CoreConfig> {
1616
}
1717

1818
export class Client extends CoreInterface {
19-
constructor(config: Config) {
20-
const agent = new Agent();
19+
constructor(config: Config, gotConfig: GotConfig = {}) {
20+
const agent = new Agent(gotConfig);
2121
const header = { "User-Agent": userAgent };
2222
const tls = config.tls === undefined ? TLS : config.tls;
2323
const baseUrl = config.baseUrl === undefined ? API_URL : config.baseUrl;

test/client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe("Client", () => {
2525
assert.equal(client.strictAuthorisation, STRICT_AUTHORISATION);
2626
assert.equal(client.timeout, TIMEOUT);
2727
});
28+
2829
it("allows default config values to be overwritten", () => {
2930
const options = {
3031
tls: false,
@@ -44,9 +45,17 @@ describe("Client", () => {
4445
options.strictAuthorisation
4546
);
4647
assert.equal(customClient.timeout, options.timeout);
48+
assert.deepEqual((customClient.agent as any).gotConfig, {});
4749
});
50+
4851
it("assigns user agent header", () => {
4952
assert.match(client.header["User-Agent"], /Core-Node/i);
5053
});
54+
55+
it("assigns got config", () => {
56+
const retry = 2;
57+
const customClient = new Client({ api_key }, { retry });
58+
assert.deepEqual((customClient.agent as any).gotConfig, { retry });
59+
});
5160
});
5261
});

0 commit comments

Comments
 (0)