@@ -40,7 +40,7 @@ function assetsWithValidUids () {
4040 return [ assetUid1 , assetUid2 ] . filter ( uid => uid && String ( uid ) . trim ( ) ) . map ( uid => ( { uid } ) )
4141}
4242
43- async function waitForJobReady ( jobId , maxAttempts = 10 ) {
43+ async function waitForJobReady ( jobId , maxAttempts = 15 ) {
4444 for ( let attempt = 1 ; attempt <= maxAttempts ; attempt ++ ) {
4545 try {
4646 const response = await doBulkOperationWithManagementToken ( tokenUidDev )
@@ -49,10 +49,13 @@ async function waitForJobReady (jobId, maxAttempts = 10) {
4949 if ( response && response . status ) {
5050 return response
5151 }
52+ if ( attempt === 1 ) {
53+ console . log ( ` jobStatus for ${ jobId } returned undefined on first attempt, will keep polling...` )
54+ }
5255 } catch ( error ) {
53- console . log ( `Attempt ${ attempt } : Job not ready yet, retrying...` )
56+ console . log ( `Attempt ${ attempt } / ${ maxAttempts } : Job ${ jobId } not ready — ${ error . message || ' retrying...' } ` )
5457 }
55- await delay ( 2000 )
58+ await delay ( 5000 )
5659 }
5760 throw new Error ( `Job ${ jobId } did not become ready after ${ maxAttempts } attempts` )
5861}
@@ -357,12 +360,11 @@ describe('BulkOperation api test', () => {
357360 } )
358361
359362 it ( 'should wait for all jobs to be processed before checking status' , async ( ) => {
360- await delay ( 5000 ) // Wait 5 seconds for jobs to be processed
363+ await delay ( 15000 )
361364 } )
362365
363- it ( 'should wait for jobs to be ready and get job status for the first publish job' , async ( ) => {
366+ it ( 'should wait for jobs to be ready and get job status for the first publish job' , async function ( ) {
364367 const response = await waitForJobReady ( jobId1 )
365-
366368 expect ( response ) . to . not . equal ( undefined )
367369 expect ( response . uid ) . to . not . equal ( undefined )
368370 expect ( response . status ) . to . not . equal ( undefined )
@@ -371,26 +373,20 @@ describe('BulkOperation api test', () => {
371373 expect ( response . body ) . to . not . equal ( undefined )
372374 } )
373375
374- it ( 'should validate detailed job status response structure' , async ( ) => {
376+ it ( 'should validate detailed job status response structure' , async function ( ) {
375377 const response = await waitForJobReady ( jobId1 )
376-
377378 expect ( response ) . to . not . equal ( undefined )
378- // Validate main job properties
379379 expect ( response . uid ) . to . not . equal ( undefined )
380380 expect ( response . api_key ) . to . not . equal ( undefined )
381381 expect ( response . status ) . to . not . equal ( undefined )
382-
383- // Validate body structure
384382 expect ( response . body ) . to . not . equal ( undefined )
385383 expect ( response . body . locales ) . to . be . an ( 'array' )
386384 expect ( response . body . environments ) . to . be . an ( 'array' )
387- // Validate summary structure
388385 expect ( response . summary ) . to . not . equal ( undefined )
389386 } )
390387
391- it ( 'should get job status for the second publish job' , async ( ) => {
388+ it ( 'should get job status for the second publish job' , async function ( ) {
392389 const response = await waitForJobReady ( jobId2 )
393-
394390 expect ( response ) . to . not . equal ( undefined )
395391 expect ( response . uid ) . to . not . equal ( undefined )
396392 expect ( response . status ) . to . not . equal ( undefined )
@@ -399,9 +395,8 @@ describe('BulkOperation api test', () => {
399395 expect ( response . body ) . to . not . equal ( undefined )
400396 } )
401397
402- it ( 'should get job status for the third publish job' , async ( ) => {
398+ it ( 'should get job status for the third publish job' , async function ( ) {
403399 const response = await waitForJobReady ( jobId3 )
404-
405400 expect ( response ) . to . not . equal ( undefined )
406401 expect ( response . uid ) . to . not . equal ( undefined )
407402 expect ( response . status ) . to . not . equal ( undefined )
@@ -410,9 +405,8 @@ describe('BulkOperation api test', () => {
410405 expect ( response . body ) . to . not . equal ( undefined )
411406 } )
412407
413- it ( 'should get job status for publishAllLocalized=true job' , async ( ) => {
408+ it ( 'should get job status for publishAllLocalized=true job' , async function ( ) {
414409 const response = await waitForJobReady ( jobId4 )
415-
416410 expect ( response ) . to . not . equal ( undefined )
417411 expect ( response . uid ) . to . not . equal ( undefined )
418412 expect ( response . status ) . to . not . equal ( undefined )
@@ -421,9 +415,8 @@ describe('BulkOperation api test', () => {
421415 expect ( response . body ) . to . not . equal ( undefined )
422416 } )
423417
424- it ( 'should get job status for publishAllLocalized=false job' , async ( ) => {
418+ it ( 'should get job status for publishAllLocalized=false job' , async function ( ) {
425419 const response = await waitForJobReady ( jobId5 )
426-
427420 expect ( response ) . to . not . equal ( undefined )
428421 expect ( response . uid ) . to . not . equal ( undefined )
429422 expect ( response . status ) . to . not . equal ( undefined )
@@ -432,9 +425,8 @@ describe('BulkOperation api test', () => {
432425 expect ( response . body ) . to . not . equal ( undefined )
433426 } )
434427
435- it ( 'should get job status for asset publishAllLocalized job' , async ( ) => {
428+ it ( 'should get job status for asset publishAllLocalized job' , async function ( ) {
436429 const response = await waitForJobReady ( jobId6 )
437-
438430 expect ( response ) . to . not . equal ( undefined )
439431 expect ( response . uid ) . to . not . equal ( undefined )
440432 expect ( response . status ) . to . not . equal ( undefined )
@@ -443,9 +435,8 @@ describe('BulkOperation api test', () => {
443435 expect ( response . body ) . to . not . equal ( undefined )
444436 } )
445437
446- it ( 'should get job status for unpublishAllLocalized=true job' , async ( ) => {
438+ it ( 'should get job status for unpublishAllLocalized=true job' , async function ( ) {
447439 const response = await waitForJobReady ( jobId7 )
448-
449440 expect ( response ) . to . not . equal ( undefined )
450441 expect ( response . uid ) . to . not . equal ( undefined )
451442 expect ( response . status ) . to . not . equal ( undefined )
@@ -454,9 +445,8 @@ describe('BulkOperation api test', () => {
454445 expect ( response . body ) . to . not . equal ( undefined )
455446 } )
456447
457- it ( 'should get job status for unpublishAllLocalized=false job' , async ( ) => {
448+ it ( 'should get job status for unpublishAllLocalized=false job' , async function ( ) {
458449 const response = await waitForJobReady ( jobId8 )
459-
460450 expect ( response ) . to . not . equal ( undefined )
461451 expect ( response . uid ) . to . not . equal ( undefined )
462452 expect ( response . status ) . to . not . equal ( undefined )
@@ -465,9 +455,8 @@ describe('BulkOperation api test', () => {
465455 expect ( response . body ) . to . not . equal ( undefined )
466456 } )
467457
468- it ( 'should get job status for asset unpublishAllLocalized job' , async ( ) => {
458+ it ( 'should get job status for asset unpublishAllLocalized job' , async function ( ) {
469459 const response = await waitForJobReady ( jobId9 )
470-
471460 expect ( response ) . to . not . equal ( undefined )
472461 expect ( response . uid ) . to . not . equal ( undefined )
473462 expect ( response . status ) . to . not . equal ( undefined )
@@ -476,9 +465,8 @@ describe('BulkOperation api test', () => {
476465 expect ( response . body ) . to . not . equal ( undefined )
477466 } )
478467
479- it ( 'should get job status for multiple parameters job' , async ( ) => {
468+ it ( 'should get job status for multiple parameters job' , async function ( ) {
480469 const response = await waitForJobReady ( jobId10 )
481-
482470 expect ( response ) . to . not . equal ( undefined )
483471 expect ( response . uid ) . to . not . equal ( undefined )
484472 expect ( response . status ) . to . not . equal ( undefined )
@@ -487,12 +475,10 @@ describe('BulkOperation api test', () => {
487475 expect ( response . body ) . to . not . equal ( undefined )
488476 } )
489477
490- it ( 'should get job status with bulk_version parameter' , async ( ) => {
478+ it ( 'should get job status with bulk_version parameter' , async function ( ) {
491479 await waitForJobReady ( jobId1 )
492-
493480 const response = await doBulkOperationWithManagementToken ( tokenUidDev )
494481 . jobStatus ( { job_id : jobId1 , bulk_version : 'v3' , api_version : '3.2' } )
495-
496482 expect ( response ) . to . not . equal ( undefined )
497483 expect ( response . uid ) . to . not . equal ( undefined )
498484 expect ( response . status ) . to . not . equal ( undefined )
@@ -501,22 +487,18 @@ describe('BulkOperation api test', () => {
501487 expect ( response . body ) . to . not . equal ( undefined )
502488 } )
503489
504- it ( 'should get job items for a completed job' , async ( ) => {
490+ it ( 'should get job items for a completed job' , async function ( ) {
505491 await waitForJobReady ( jobId1 )
506-
507492 const response = await doBulkOperationWithManagementToken ( tokenUidDev )
508493 . getJobItems ( jobId1 )
509-
510494 expect ( response ) . to . not . equal ( undefined )
511495 expect ( response . items ) . to . be . an ( 'array' )
512496 } )
513497
514- it ( 'should get job items with explicit api_version' , async ( ) => {
498+ it ( 'should get job items with explicit api_version' , async function ( ) {
515499 await waitForJobReady ( jobId2 )
516-
517500 const response = await doBulkOperationWithManagementToken ( tokenUidDev )
518501 . getJobItems ( jobId2 , { api_version : '3.2' } )
519-
520502 expect ( response ) . to . not . equal ( undefined )
521503 expect ( response . items ) . to . be . an ( 'array' )
522504 } )
0 commit comments