@@ -1366,6 +1366,105 @@ class APICleanup {
13661366}
13671367}
13681368
1369+ /**
1370+ * Fetch all search jobs
1371+ *@returns {Promise<Array> } Array of search job objects
1372+ */
1373+ async fetchSearchJobs ( ) {
1374+ try {
1375+ const response = await fetch ( `${ this . baseUrl } /api/${ this . org } /search_jobs?type=logs` , {
1376+ method :'GET' ,
1377+ headers :{
1378+ 'Authorization' :this . authHeader ,
1379+ 'Content-Type' :'application/json'
1380+ }
1381+ } ) ;
1382+
1383+ if ( ! response . ok ) {
1384+ testLogger . error ( 'Failed to fetch search jobs' , { status :response . status } ) ;
1385+ return [ ] ;
1386+ }
1387+
1388+ const searchJobs = await response . json ( ) ;
1389+ return searchJobs || [ ] ;
1390+ } catch ( error ) {
1391+ testLogger . error ( 'Failed to fetch search jobs' , { error :error . message } ) ;
1392+ return [ ] ;
1393+ }
1394+ }
1395+
1396+ /**
1397+ * Delete a single search job
1398+ *@param {string } jobId - The search job ID
1399+ *@returns {Promise<Object> } Deletion result
1400+ */
1401+ async deleteSearchJob ( jobId ) {
1402+ try {
1403+ const response = await fetch ( `${ this . baseUrl } /api/${ this . org } /search_jobs/${ jobId } ` , {
1404+ method :'DELETE' ,
1405+ headers :{
1406+ 'Authorization' :this . authHeader ,
1407+ 'Content-Type' :'application/json'
1408+ }
1409+ } ) ;
1410+
1411+ if ( ! response . ok ) {
1412+ testLogger . error ( 'Failed to delete search job' , { jobId, status :response . status } ) ;
1413+ return { code :response . status , message :'Failed to delete search job' } ;
1414+ }
1415+
1416+ const result = await response . json ( ) ;
1417+ return { code :200 , ...result } ;
1418+ } catch ( error ) {
1419+ testLogger . error ( 'Failed to delete search job' , { jobId, error :error . message } ) ;
1420+ return { code :500 , error :error . message } ;
1421+ }
1422+ }
1423+
1424+ /**
1425+ * Clean up all search jobs
1426+ * Deletes all search jobs for the organization
1427+ */
1428+ async cleanupSearchJobs ( ) {
1429+ testLogger . info ( 'Starting search jobs cleanup' ) ;
1430+
1431+ try {
1432+ // Fetch all search jobs
1433+ const searchJobs = await this . fetchSearchJobs ( ) ;
1434+ testLogger . info ( 'Fetched search jobs' , { total :searchJobs . length } ) ;
1435+
1436+ if ( searchJobs . length === 0 ) {
1437+ testLogger . info ( 'No search jobs to clean up' ) ;
1438+ return ;
1439+ }
1440+
1441+ // Delete each search job
1442+ let deletedCount = 0 ;
1443+ let failedCount = 0 ;
1444+
1445+ for ( const job of searchJobs ) {
1446+ const result = await this . deleteSearchJob ( job . id ) ;
1447+
1448+ if ( result . code === 200 ) {
1449+ deletedCount ++ ;
1450+ testLogger . debug ( 'Deleted search job' , { jobId :job . id , userId :job . user_id } ) ;
1451+ } else {
1452+ failedCount ++ ;
1453+ testLogger . warn ( 'Failed to delete search job' , { jobId :job . id , userId :job . user_id , result} ) ;
1454+ }
1455+ }
1456+
1457+ testLogger . info ( 'Search jobs cleanup completed' , {
1458+ total :searchJobs . length ,
1459+ deleted :deletedCount ,
1460+ failed :failedCount
1461+ } ) ;
1462+
1463+ } catch ( error ) {
1464+ testLogger . error ( 'Search jobs cleanup failed' , { error :error . message } ) ;
1465+ }
1466+ }
1467+
13691468/**
13701469 * Fetch all saved views
13711470 *@returns {Promise<Array> } Array of saved view objects