@@ -105,6 +105,29 @@ function rootChildren(driveId: string, items: unknown[]) {
105105 }
106106}
107107
108+ /** Builds a Graph pagination chain with an optional continuation beyond the final allowed page. */
109+ function paginatedRoutes (
110+ initialUrl : string ,
111+ routePrefix : string ,
112+ pageCount : number ,
113+ continueAfterLast : boolean
114+ ) : Record < string , GraphRoute > {
115+ const routes : Record < string , GraphRoute > = { }
116+
117+ for ( let page = 0 ; page < pageCount ; page ++ ) {
118+ const url = page === 0 ? initialUrl : `${ GRAPH } /${ routePrefix } /${ page } `
119+ const hasNextPage = page < pageCount - 1 || continueAfterLast
120+ routes [ url ] = {
121+ body : {
122+ value : [ ] ,
123+ ...( hasNextPage ? { '@odata.nextLink' : `${ GRAPH } /${ routePrefix } /${ page + 1 } ` } : { } ) ,
124+ } ,
125+ }
126+ }
127+
128+ return routes
129+ }
130+
108131function resolve ( folderPath ?: string ) {
109132 return resolveFolderTarget ( 'token' , SITE_ID , SITE_URL , 'Contoso' , folderPath )
110133}
@@ -322,6 +345,51 @@ describe('resolveFolderTarget', () => {
322345 )
323346 } )
324347
348+ it ( 'surfaces a terminal document-library listing failure' , async ( ) => {
349+ mockGraph ( {
350+ ...defaultDriveRoute ,
351+ [ `${ GRAPH } /sites/${ SITE_ID } /drives?$select=id,name,webUrl` ] : {
352+ status : 503 ,
353+ body : { error : { message : 'Service unavailable' } } ,
354+ } ,
355+ } )
356+
357+ await expect ( resolve ( 'Missing' ) ) . rejects . toThrow (
358+ / F a i l e d t o l i s t S h a r e P o i n t d o c u m e n t l i b r a r i e s : 5 0 3 /
359+ )
360+ } )
361+
362+ it ( 'rejects a document-library listing that continues beyond its safety limit' , async ( ) => {
363+ const initialUrl = `${ GRAPH } /sites/${ SITE_ID } /drives?$select=id,name,webUrl`
364+ mockGraph ( {
365+ ...defaultDriveRoute ,
366+ ...paginatedRoutes ( initialUrl , 'drive-pages' , 20 , true ) ,
367+ } )
368+
369+ await expect ( resolve ( 'Missing' ) ) . rejects . toThrow (
370+ / d o c u m e n t - l i b r a r y l i s t i n g e x c e e d e d t h e 2 0 - p a g e s a f e t y l i m i t /
371+ )
372+ } )
373+
374+ it ( 'surfaces a 404 encountered while traversing a folder collection' , async ( ) => {
375+ mockGraph ( { ...defaultDriveRoute , ...sitesDrivesRoute } )
376+
377+ await expect ( resolve ( 'Missing' ) ) . rejects . toThrow ( / F a i l e d t o l i s t f o l d e r c o n t e n t s : 4 0 4 / )
378+ } )
379+
380+ it ( 'rejects a folder listing that continues beyond its safety limit' , async ( ) => {
381+ const initialUrl = `${ GRAPH } /drives/${ DEFAULT_DRIVE_ID } /root/children?$top=200&$select=id,name,folder`
382+ mockGraph ( {
383+ ...defaultDriveRoute ,
384+ ...sitesDrivesRoute ,
385+ ...paginatedRoutes ( initialUrl , 'folder-pages' , 50 , true ) ,
386+ } )
387+
388+ await expect ( resolve ( 'Missing' ) ) . rejects . toThrow (
389+ / f o l d e r l i s t i n g e x c e e d e d t h e 5 0 - p a g e s a f e t y l i m i t /
390+ )
391+ } )
392+
325393 it ( 'accepts an address-bar folder URL carrying the path in the id parameter' , async ( ) => {
326394 mockGraph ( {
327395 ...defaultDriveRoute ,
0 commit comments