11import axios from 'axios'
22
3- import { createApiClient } from './client'
3+ import { bindApiClient } from './client'
44
55jest . mock ( 'axios' , ( ) => {
66 const mockResponseInterceptors = { use : jest . fn ( ) }
@@ -21,9 +21,9 @@ beforeEach(() => {
2121 jest . clearAllMocks ( )
2222} )
2323
24- describe ( 'createApiClient ' , ( ) => {
24+ describe ( 'bindApiClient ' , ( ) => {
2525 it ( 'should create client with correct baseURL' , ( ) => {
26- createApiClient ( 'https://flowise.example.com' )
26+ bindApiClient ( 'https://flowise.example.com' )
2727 expect ( mockedAxios . create ) . toHaveBeenCalledWith (
2828 expect . objectContaining ( {
2929 baseURL : 'https://flowise.example.com/api/v1'
@@ -32,7 +32,7 @@ describe('createApiClient', () => {
3232 } )
3333
3434 it ( 'should set Content-Type header' , ( ) => {
35- createApiClient ( 'https://flowise.example.com' )
35+ bindApiClient ( 'https://flowise.example.com' )
3636 expect ( mockedAxios . create ) . toHaveBeenCalledWith (
3737 expect . objectContaining ( {
3838 headers : expect . objectContaining ( {
@@ -43,7 +43,7 @@ describe('createApiClient', () => {
4343 } )
4444
4545 it ( 'should set Authorization header when token is provided' , ( ) => {
46- createApiClient ( 'https://flowise.example.com' , 'my-token' )
46+ bindApiClient ( 'https://flowise.example.com' , 'my-token' )
4747 expect ( mockedAxios . create ) . toHaveBeenCalledWith (
4848 expect . objectContaining ( {
4949 headers : expect . objectContaining ( {
@@ -54,40 +54,40 @@ describe('createApiClient', () => {
5454 } )
5555
5656 it ( 'should not set Authorization header when no token' , ( ) => {
57- createApiClient ( 'https://flowise.example.com' )
57+ bindApiClient ( 'https://flowise.example.com' )
5858 const headers = mockedAxios . create . mock . calls [ 0 ] [ 0 ] ?. headers as Record < string , string >
5959 expect ( headers [ 'Authorization' ] ) . toBeUndefined ( )
6060 } )
6161
6262 it ( 'should register request and response interceptors' , ( ) => {
63- const client = createApiClient ( 'https://flowise.example.com' )
63+ const client = bindApiClient ( 'https://flowise.example.com' )
6464 expect ( client . interceptors . request . use ) . toHaveBeenCalledTimes ( 1 )
6565 expect ( client . interceptors . response . use ) . toHaveBeenCalledTimes ( 1 )
6666 } )
6767
6868 it ( 'should pass config through request interceptor' , ( ) => {
69- const client = createApiClient ( 'https://flowise.example.com' )
69+ const client = bindApiClient ( 'https://flowise.example.com' )
7070 const successHandler = ( client . interceptors . request . use as jest . Mock ) . mock . calls [ 0 ] [ 0 ]
7171 const config = { url : '/chatflows' , headers : { } }
7272 expect ( successHandler ( config ) ) . toBe ( config )
7373 } )
7474
7575 it ( 'should pass response through response interceptor' , ( ) => {
76- const client = createApiClient ( 'https://flowise.example.com' )
76+ const client = bindApiClient ( 'https://flowise.example.com' )
7777 const successHandler = ( client . interceptors . response . use as jest . Mock ) . mock . calls [ 0 ] [ 0 ]
7878 const response = { data : { } , status : 200 }
7979 expect ( successHandler ( response ) ) . toBe ( response )
8080 } )
8181
8282 it ( 'should reject request interceptor errors' , async ( ) => {
83- const client = createApiClient ( 'https://flowise.example.com' )
83+ const client = bindApiClient ( 'https://flowise.example.com' )
8484 const errorHandler = ( client . interceptors . request . use as jest . Mock ) . mock . calls [ 0 ] [ 1 ]
8585 const error = new Error ( 'Network error' )
8686 await expect ( errorHandler ( error ) ) . rejects . toBe ( error )
8787 } )
8888
8989 it ( 'should reject 401 errors through response interceptor' , async ( ) => {
90- const client = createApiClient ( 'https://flowise.example.com' , 'tok' )
90+ const client = bindApiClient ( 'https://flowise.example.com' , 'tok' )
9191 const errorHandler = ( client . interceptors . response . use as jest . Mock ) . mock . calls [ 0 ] [ 1 ]
9292
9393 const error = {
@@ -106,7 +106,7 @@ describe('createApiClient', () => {
106106 } )
107107
108108 it ( 'should pass through non-401 errors without logging' , async ( ) => {
109- const client = createApiClient ( 'https://flowise.example.com' )
109+ const client = bindApiClient ( 'https://flowise.example.com' )
110110 const errorHandler = ( client . interceptors . response . use as jest . Mock ) . mock . calls [ 0 ] [ 1 ]
111111
112112 const error = { response : { status : 500 } , message : 'Server error' }
@@ -117,7 +117,7 @@ describe('createApiClient', () => {
117117 } )
118118
119119 it ( 'should not set withCredentials by default' , ( ) => {
120- createApiClient ( 'https://flowise.example.com' )
120+ bindApiClient ( 'https://flowise.example.com' )
121121 expect ( mockedAxios . create ) . toHaveBeenCalledWith (
122122 expect . not . objectContaining ( {
123123 withCredentials : true
@@ -130,7 +130,7 @@ describe('createApiClient', () => {
130130 config . withCredentials = true
131131 return config
132132 } )
133- const client = createApiClient ( 'https://flowise.example.com' , undefined , interceptor )
133+ const client = bindApiClient ( 'https://flowise.example.com' , undefined , interceptor )
134134 const successHandler = ( client . interceptors . request . use as jest . Mock ) . mock . calls [ 0 ] [ 0 ]
135135 const config = { url : '/chatflows' , headers : { } }
136136 const result = successHandler ( config )
@@ -139,7 +139,7 @@ describe('createApiClient', () => {
139139 } )
140140
141141 it ( 'should pass config through when no requestInterceptor is provided' , ( ) => {
142- const client = createApiClient ( 'https://flowise.example.com' )
142+ const client = bindApiClient ( 'https://flowise.example.com' )
143143 const successHandler = ( client . interceptors . request . use as jest . Mock ) . mock . calls [ 0 ] [ 0 ]
144144 const config = { url : '/chatflows' , headers : { } }
145145 expect ( successHandler ( config ) ) . toBe ( config )
@@ -149,7 +149,7 @@ describe('createApiClient', () => {
149149 const interceptor = jest . fn ( ( ) => {
150150 throw new Error ( 'interceptor broke' )
151151 } )
152- const client = createApiClient ( 'https://flowise.example.com' , undefined , interceptor )
152+ const client = bindApiClient ( 'https://flowise.example.com' , undefined , interceptor )
153153 const successHandler = ( client . interceptors . request . use as jest . Mock ) . mock . calls [ 0 ] [ 0 ]
154154 const config = { url : '/chatflows' , headers : { } }
155155 const consoleSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( )
0 commit comments