@@ -354,4 +354,50 @@ describe('DefaultCmabClient', () => {
354354
355355 await expect ( cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ) . rejects . toThrow ( 'error' ) ;
356356 } ) ;
357+
358+ it ( 'should use custom prediction endpoint template when provided' , async ( ) => {
359+ const requestHandler = getMockRequestHandler ( ) ;
360+
361+ const mockMakeRequest : MockInstance < RequestHandler [ 'makeRequest' ] > = requestHandler . makeRequest ;
362+ mockMakeRequest . mockReturnValue ( getMockAbortableRequest ( mockSuccessResponse ( 'var456' ) ) ) ;
363+
364+ const customEndpoint = 'https://custom.example.com/predict/%s' ;
365+ const cmabClient = new DefaultCmabClient ( {
366+ requestHandler,
367+ predictionEndpointTemplate : customEndpoint ,
368+ } ) ;
369+ const ruleId = '789' ;
370+ const userId = 'user789' ;
371+ const attributes = {
372+ browser : 'firefox' ,
373+ } ;
374+ const cmabUuid = 'uuid789' ;
375+ const variation = await cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ;
376+ const [ requestUrl ] = mockMakeRequest . mock . calls [ 0 ] ;
377+
378+ expect ( variation ) . toBe ( 'var456' ) ;
379+ expect ( mockMakeRequest . mock . calls . length ) . toBe ( 1 ) ;
380+ expect ( requestUrl ) . toBe ( 'https://custom.example.com/predict/789' ) ;
381+ } ) ;
382+
383+ it ( 'should use default prediction endpoint template when not provided' , async ( ) => {
384+ const requestHandler = getMockRequestHandler ( ) ;
385+ const mockMakeRequest : MockInstance < RequestHandler [ 'makeRequest' ] > = requestHandler . makeRequest ;
386+ mockMakeRequest . mockReturnValue ( getMockAbortableRequest ( mockSuccessResponse ( 'var999' ) ) ) ;
387+ const cmabClient = new DefaultCmabClient ( {
388+ requestHandler,
389+ } ) ;
390+ const ruleId = '555' ;
391+ const userId = 'user555' ;
392+ const attributes = {
393+ browser : 'safari' ,
394+ } ;
395+ const cmabUuid = 'uuid555' ;
396+ const variation = await cmabClient . fetchDecision ( ruleId , userId , attributes , cmabUuid ) ;
397+ const [ requestUrl ] = mockMakeRequest . mock . calls [ 0 ] ;
398+
399+ expect ( variation ) . toBe ( 'var999' ) ;
400+ expect ( mockMakeRequest . mock . calls . length ) . toBe ( 1 ) ;
401+ expect ( requestUrl ) . toBe ( 'https://prediction.cmab.optimizely.com/predict/555' ) ;
402+ } ) ;
357403} ) ;
0 commit comments