File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff 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+
1017describe ( '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
5772describe ( 'createClient' , ( ) => {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments