1- import axios from 'axios' ;
21import MockAdapter from 'axios-mock-adapter' ;
3- import { createAxiosClient } from '../axios-client' ;
42import {
53 isValidUuid ,
6- RoutingConfigurationApiClient ,
4+ routingConfigurationApiClient as client ,
5+ httpClient ,
76} from '../routing-config-api-client' ;
87import { RoutingConfig , RoutingConfigStatus } from '../types/generated' ;
98import { ErrorCase } from '../types/error-cases' ;
109
11- jest . mock ( '../axios-client' , ( ) => {
12- const actual = jest . requireActual ( '../axios-client' ) ;
13- return {
14- ...actual ,
15- createAxiosClient : jest . fn ( ) ,
16- } ;
17- } ) ;
18-
19- const createAxiosClientMock = jest . mocked ( createAxiosClient ) ;
20-
2110const validRoutingConfigId = '2a4b6c8d-0e1f-4a2b-9c3d-5e6f7a8b9c0d' ;
2211const notFoundRoutingConfigId = '3b5d7f9a-1c2e-4b3d-8f0a-6e7d8c9b0a1f' ;
2312const invalidRoutingConfigId = 'not-a-uuid' ;
2413
2514describe ( 'RoutingConfigurationApiClient' , ( ) => {
26- const axiosMock = new MockAdapter ( axios ) ;
15+ const axiosMock = new MockAdapter ( httpClient ) ;
2716
2817 beforeEach ( ( ) => {
2918 axiosMock . reset ( ) ;
30- createAxiosClientMock . mockReturnValue ( axios ) ;
3119 } ) ;
3220
3321 describe ( 'get' , ( ) => {
@@ -40,8 +28,6 @@ describe('RoutingConfigurationApiClient', () => {
4028 details : { message : 'Routing configuration not found' } ,
4129 } ) ;
4230
43- const client = new RoutingConfigurationApiClient ( ) ;
44-
4531 const response = await client . get ( 'mock-token' , notFoundRoutingConfigId ) ;
4632
4733 expect ( response . error ) . toEqual ( {
@@ -56,8 +42,6 @@ describe('RoutingConfigurationApiClient', () => {
5642 } ) ;
5743
5844 it ( 'should return error for invalid routing config ID' , async ( ) => {
59- const client = new RoutingConfigurationApiClient ( ) ;
60-
6145 const response = await client . get ( 'mock-token' , invalidRoutingConfigId ) ;
6246
6347 expect ( response . error ) . toEqual ( {
@@ -91,8 +75,6 @@ describe('RoutingConfigurationApiClient', () => {
9175 data,
9276 } ) ;
9377
94- const client = new RoutingConfigurationApiClient ( ) ;
95-
9678 const response = await client . get ( 'mock-token' , validRoutingConfigId ) ;
9779
9880 expect ( response . error ) . toBeUndefined ( ) ;
@@ -111,8 +93,6 @@ describe('RoutingConfigurationApiClient', () => {
11193 } ,
11294 } ) ;
11395
114- const client = new RoutingConfigurationApiClient ( ) ;
115-
11696 const result = await client . create (
11797 {
11898 name : 'test' ,
@@ -163,8 +143,6 @@ describe('RoutingConfigurationApiClient', () => {
163143 name : data . name ,
164144 } ;
165145
166- const client = new RoutingConfigurationApiClient ( ) ;
167-
168146 const result = await client . create ( body , 'test-token' ) ;
169147
170148 expect ( axiosMock . history . post . length ) . toBe ( 1 ) ;
@@ -189,8 +167,6 @@ describe('RoutingConfigurationApiClient', () => {
189167 details : { message : 'Routing configuration not found' } ,
190168 } ) ;
191169
192- const client = new RoutingConfigurationApiClient ( ) ;
193-
194170 const body = {
195171 id : notFoundRoutingConfigId ,
196172 name : 'Test plan' ,
@@ -221,8 +197,6 @@ describe('RoutingConfigurationApiClient', () => {
221197 } ) ;
222198
223199 it ( 'should return error for invalid routing config ID' , async ( ) => {
224- const client = new RoutingConfigurationApiClient ( ) ;
225-
226200 const body = {
227201 id : invalidRoutingConfigId ,
228202 name : 'Test plan' ,
@@ -255,7 +229,7 @@ describe('RoutingConfigurationApiClient', () => {
255229
256230 it ( 'should return updated routing configuration on success' , async ( ) => {
257231 const body = {
258- id : '4c6e8f0a-2b3d-4c5e-9a1b-7d8c9b0a1f2e' ,
232+ id : validRoutingConfigId ,
259233 name : 'Updated Plan' ,
260234 status : 'DRAFT' as RoutingConfigStatus ,
261235 clientId : 'client-1' ,
@@ -266,15 +240,15 @@ describe('RoutingConfigurationApiClient', () => {
266240 cascadeGroupOverrides : [ ] ,
267241 } ;
268242
269- axiosMock . onPut ( '/v1/routing-configuration/routing-config-2' ) . reply ( 200 , {
270- data : body ,
271- } ) ;
272-
273- const client = new RoutingConfigurationApiClient ( ) ;
243+ axiosMock
244+ . onPut ( `/v1/routing-configuration/ ${ validRoutingConfigId } ` )
245+ . reply ( 200 , {
246+ data : body ,
247+ } ) ;
274248
275249 const response = await client . update (
276250 'test-token' ,
277- '4c6e8f0a-2b3d-4c5e-9a1b-7d8c9b0a1f2e' ,
251+ validRoutingConfigId ,
278252 body
279253 ) ;
280254
0 commit comments