Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/clients/src/scw/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ const withApiURL =
(apiURL: string): ClientConfig =>
(obj: Settings): Settings => ({ ...obj, apiURL })

const withPassthroughFetch =
(res: string): ClientConfig =>
(obj: Settings): Settings => ({
...obj,
httpClient: () => Promise.resolve(new Response(res)),
})

describe('createAdvancedClient', () => {
it('initializes without throwing', () => {
expect(() => {
Expand Down Expand Up @@ -52,6 +59,14 @@ describe('createAdvancedClient', () => {
const client = createAdvancedClient(withApiURL(betaApiRoot))
expect(client.settings.apiURL).toBe(betaApiRoot)
})

it('contains override of httpClient', () => {
const client = createAdvancedClient(withPassthroughFetch('hello world'))

return expect(
client.settings.httpClient('any-url').then(obj => obj.text()),
).resolves.toBe('hello world')
})
})

describe('createClient', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/src/scw/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const createAdvancedClient = (...configs: ClientConfig[]): Client => {
getLogger().info(`init Scaleway SDK version ${version}`)

return {
fetch: buildFetcher(settings, fetch),
fetch: buildFetcher(settings, settings.httpClient),
settings,
}
}
Expand Down