@@ -299,7 +299,86 @@ describe('Region command', function () {
299299 composableStudioUrl : 'https://custom-composable-studio.com' ,
300300 } ;
301301 const result = UserConfig . setCustomRegion ( customRegion ) ;
302- expect ( result ) . to . deep . equal ( customRegion ) ;
302+ expect ( result . cma ) . to . equal ( customRegion . cma ) ;
303+ expect ( result . cda ) . to . equal ( customRegion . cda ) ;
304+ expect ( result . uiHost ) . to . equal ( customRegion . uiHost ) ;
305+ expect ( result . name ) . to . equal ( customRegion . name ) ;
306+ expect ( result . developerHubUrl ) . to . equal ( customRegion . developerHubUrl ) ;
307+ expect ( result . personalizeUrl ) . to . equal ( customRegion . personalizeUrl ) ;
308+ expect ( result . launchHubUrl ) . to . equal ( customRegion . launchHubUrl ) ;
309+ expect ( result . composableStudioUrl ) . to . equal ( customRegion . composableStudioUrl ) ;
310+ } ) ;
311+
312+ it ( 'should include a matching endpoints object for a custom region without an auth host' , function ( ) {
313+ const customRegion = {
314+ cma : 'https://custom-cma.com' ,
315+ cda : 'https://custom-cda.com' ,
316+ uiHost : 'https://custom-ui.com' ,
317+ name : 'Custom Region' ,
318+ developerHubUrl : 'https://custom-developer-hub.com' ,
319+ personalizeUrl : 'https://custom-personalize.com' ,
320+ launchHubUrl : 'https://custom-launch.com' ,
321+ composableStudioUrl : 'https://custom-composable-studio.com' ,
322+ } ;
323+ const result = UserConfig . setCustomRegion ( customRegion ) ;
324+ expect ( result . endpoints ) . to . deep . equal ( {
325+ contentManagement : customRegion . cma ,
326+ contentDelivery : customRegion . cda ,
327+ application : customRegion . uiHost ,
328+ developerHub : customRegion . developerHubUrl ,
329+ launch : customRegion . launchHubUrl ,
330+ personalizeManagement : customRegion . personalizeUrl ,
331+ composableStudio : customRegion . composableStudioUrl ,
332+ auth : undefined ,
333+ } ) ;
334+ } ) ;
335+
336+ it ( 'should preserve an explicitly supplied endpoints object for a custom region' , function ( ) {
337+ const endpoints = {
338+ contentManagement : 'https://custom-cma.com' ,
339+ contentDelivery : 'https://custom-cda.com' ,
340+ application : 'https://custom-ui.com' ,
341+ auth : 'https://custom-auth.com' ,
342+ } ;
343+ const customRegion = {
344+ cma : 'https://custom-cma.com' ,
345+ cda : 'https://custom-cda.com' ,
346+ uiHost : 'https://custom-ui.com' ,
347+ name : 'Custom Region' ,
348+ endpoints,
349+ } ;
350+ const result = UserConfig . setCustomRegion ( customRegion ) ;
351+ expect ( result . cma ) . to . equal ( endpoints . contentManagement ) ;
352+ expect ( result . cda ) . to . equal ( endpoints . contentDelivery ) ;
353+ expect ( result . uiHost ) . to . equal ( endpoints . application ) ;
354+ expect ( result . endpoints ) . to . deep . equal ( endpoints ) ;
355+ } ) ;
356+
357+ it ( 'should not fall back to a stale legacy authUrl input once endpoints.auth is supplied' , function ( ) {
358+ // endpoints is the single source of truth: a stale/mismatched top-level
359+ // authUrl on the raw input is never used — only endpoints.auth matters.
360+ const customRegion = {
361+ cma : 'https://custom-cma.com' ,
362+ cda : 'https://custom-cda.com' ,
363+ uiHost : 'https://custom-ui.com' ,
364+ name : 'Custom Region' ,
365+ authUrl : 'https://stale-auth.com' ,
366+ endpoints : {
367+ contentManagement : 'https://custom-cma.com' ,
368+ contentDelivery : 'https://custom-cda.com' ,
369+ application : 'https://custom-ui.com' ,
370+ auth : 'https://correct-auth.com' ,
371+ } ,
372+ } ;
373+ const result = UserConfig . setCustomRegion ( customRegion ) ;
374+ expect ( result . endpoints . auth ) . to . equal ( 'https://correct-auth.com' ) ;
375+ } ) ;
376+
377+ it ( 'should include the full endpoints passthrough (incl. auth) for named regions' , function ( ) {
378+ const result = UserConfig . setRegion ( 'NA' ) ;
379+ expect ( result . endpoints ) . to . be . an ( 'object' ) ;
380+ expect ( result . endpoints . auth ) . to . equal ( 'https://auth-api.contentstack.com' ) ;
381+ expect ( result . endpoints . contentManagement ) . to . equal ( result . cma ) ;
303382 } ) ;
304383
305384 it ( 'should sanitize region object to only include valid properties' , function ( ) {
0 commit comments