Skip to content

Commit fa5b22a

Browse files
authored
fix: use custom httpClient passed to createAdvancedClient (#143)
1 parent d16c11d commit fa5b22a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/clients/src/scw/__tests__/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const withApiURL =
77
(apiURL: string): ClientConfig =>
88
(obj: Settings): Settings => ({ ...obj, apiURL })
99

10+
const withPassthroughFetch =
11+
(res: string): ClientConfig =>
12+
(obj: Settings): Settings => ({
13+
...obj,
14+
httpClient: () => Promise.resolve(new Response(res)),
15+
})
16+
1017
describe('createAdvancedClient', () => {
1118
it('initializes without throwing', () => {
1219
expect(() => {
@@ -52,6 +59,14 @@ describe('createAdvancedClient', () => {
5259
const client = createAdvancedClient(withApiURL(betaApiRoot))
5360
expect(client.settings.apiURL).toBe(betaApiRoot)
5461
})
62+
63+
it('contains override of httpClient', () => {
64+
const client = createAdvancedClient(withPassthroughFetch('hello world'))
65+
66+
return expect(
67+
client.settings.httpClient('any-url').then(obj => obj.text()),
68+
).resolves.toBe('hello world')
69+
})
5570
})
5671

5772
describe('createClient', () => {

packages/clients/src/scw/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const createAdvancedClient = (...configs: ClientConfig[]): Client => {
5858
getLogger().info(`init Scaleway SDK version ${version}`)
5959

6060
return {
61-
fetch: buildFetcher(settings, fetch),
61+
fetch: buildFetcher(settings, settings.httpClient),
6262
settings,
6363
}
6464
}

0 commit comments

Comments
 (0)