@@ -297,7 +297,9 @@ describe('listBusinessPlatformStores', () => {
297297 status : 'unavailable' ,
298298 error : expect . any ( AbortError ) ,
299299 } )
300- expect ( result . status === 'unavailable' ? result . error . message : '' ) . toContain ( 'Access denied for accessibleShops' )
300+ expect ( result . status === 'unavailable' ? ( result . error as Error ) . message : '' ) . toContain (
301+ 'Access denied for accessibleShops' ,
302+ )
301303 expect ( output . debug ( ) ) . toContain (
302304 'Business Platform store listing failed for organization Acme (1234): Access denied for accessibleShops' ,
303305 )
@@ -306,14 +308,31 @@ describe('listBusinessPlatformStores', () => {
306308 )
307309 } )
308310
309- test ( 'rethrows non-abort errors' , async ( ) => {
311+ test ( 'returns an unavailable status for non-abort errors so auto can fall back' , async ( ) => {
312+ const output = mockAndCaptureOutput ( )
313+
310314 vi . mocked ( ensureAuthenticatedBusinessPlatform ) . mockResolvedValue ( 'bp-token' )
311315 vi . mocked ( fetchOrganizationsWithAccessInfo ) . mockResolvedValue ( {
312316 organizations : [ { id : '1234' , businessName : 'Acme' } ] ,
313317 currentUserResolved : true ,
314318 } )
315319 vi . mocked ( businessPlatformOrganizationsRequestDoc ) . mockRejectedValueOnce ( new Error ( 'Network exploded' ) )
316320
317- await expect ( listBusinessPlatformStores ( ) ) . rejects . toThrow ( 'Network exploded' )
321+ const result = await listBusinessPlatformStores ( )
322+
323+ expect ( result ) . toMatchObject ( { status : 'unavailable' } )
324+ expect ( result . status === 'unavailable' ? ( result . error as Error ) . message : '' ) . toContain ( 'Network exploded' )
325+ expect ( output . debug ( ) ) . toContain (
326+ 'Business Platform store listing failed for the current session: Network exploded' ,
327+ )
328+ } )
329+
330+ test ( 'returns an unavailable status when Business Platform authentication fails' , async ( ) => {
331+ vi . mocked ( ensureAuthenticatedBusinessPlatform ) . mockRejectedValue ( new Error ( 'Network exploded' ) )
332+
333+ const result = await listBusinessPlatformStores ( )
334+
335+ expect ( result ) . toMatchObject ( { status : 'unavailable' } )
336+ expect ( result . status === 'unavailable' ? ( result . error as Error ) . message : '' ) . toContain ( 'Network exploded' )
318337 } )
319338} )
0 commit comments