@@ -87,6 +87,40 @@ describe('WaterCrawlAPI', () => {
8787 expect ( Array . isArray ( response . results ) ) . toBe ( true ) ;
8888 } , 60000 ) ;
8989
90+ test ( 'getCrawlRequestResults with pagination and download' , async ( ) => {
91+ // Find a crawl request with results
92+ const crawlList = await api . getCrawlRequestsList ( ) ;
93+ let targetCrawl : CrawlRequest | undefined ;
94+ for ( const crawl of crawlList . results ) {
95+ const results = await api . getCrawlRequestResults ( crawl . uuid ) ;
96+ if ( results . results . length > 1 ) {
97+ targetCrawl = crawl ;
98+ break ;
99+ }
100+ }
101+
102+ if ( ! targetCrawl ) {
103+ console . log ( 'Skipping pagination test: No suitable crawl with multiple results found.' ) ;
104+ return ;
105+ }
106+
107+ // Test pagination
108+ const pageSize = 1 ;
109+ const paginatedResponse = await api . getCrawlRequestResults ( targetCrawl . uuid , 1 , pageSize ) ;
110+ expect ( Array . isArray ( paginatedResponse . results ) ) . toBe ( true ) ;
111+ expect ( paginatedResponse . results . length ) . toBe ( pageSize ) ;
112+
113+ // Test download=true
114+ const downloadResponse = await api . getCrawlRequestResults ( targetCrawl . uuid , 1 , pageSize , true ) ;
115+ expect ( Array . isArray ( downloadResponse . results ) ) . toBe ( true ) ;
116+ if ( downloadResponse . results . length > 0 ) {
117+ const result = downloadResponse . results [ 0 ] ;
118+ // When downloaded, the result object should be more than just a URL string
119+ expect ( typeof result . result ) . toBe ( 'object' ) ;
120+ expect ( result . result ) . not . toBeNull ( ) ;
121+ }
122+ } , 60000 ) ;
123+
90124 test ( 'downloadResult downloads a specific result' , async ( ) => {
91125 const resultCrawl = await api . getCrawlRequestsList ( ) ;
92126 let index = 0 ;
@@ -123,7 +157,7 @@ describe('WaterCrawlAPI', () => {
123157 const items = await api . getCrawlRequestsList ( ) ;
124158 const completedItem = items . results . find (
125159 ( item ) =>
126- item . status === ( 'completed' as CrawlStatus ) || item . status === ( ' finished' as CrawlStatus ) ,
160+ item . status === ( 'finished' as CrawlStatus ) ,
127161 ) ;
128162
129163 if ( completedItem ) {
0 commit comments