@@ -19,6 +19,27 @@ let jobId3 = ''
19
19
let tokenUidDev = ''
20
20
let tokenUid = ''
21
21
22
+ function delay ( ms ) {
23
+ return new Promise ( resolve => setTimeout ( resolve , ms ) )
24
+ }
25
+
26
+ async function waitForJobReady ( jobId , maxAttempts = 10 ) {
27
+ for ( let attempt = 1 ; attempt <= maxAttempts ; attempt ++ ) {
28
+ try {
29
+ const response = await doBulkOperationWithManagementToken ( tokenUidDev )
30
+ . jobStatus ( { job_id : jobId , api_version : '3.2' } )
31
+
32
+ if ( response && response . status ) {
33
+ return response
34
+ }
35
+ } catch ( error ) {
36
+ console . log ( `Attempt ${ attempt } : Job not ready yet, retrying...` )
37
+ }
38
+ await delay ( 2000 )
39
+ }
40
+ throw new Error ( `Job ${ jobId } did not become ready after ${ maxAttempts } attempts` )
41
+ }
42
+
22
43
describe ( 'BulkOperation api test' , ( ) => {
23
44
setup ( ( ) => {
24
45
const user = jsonReader ( 'loggedinuser.json' )
@@ -141,91 +162,72 @@ describe('BulkOperation api test', () => {
141
162
. catch ( done )
142
163
} )
143
164
144
- it ( 'should get job status for the first publish job' , done => {
145
- doBulkOperationWithManagementToken ( tokenUidDev )
146
- . jobStatus ( { job_id : jobId1 , api_version : '3.2' } )
147
- . then ( ( response ) => {
148
- expect ( response ) . to . not . equal ( undefined )
149
- expect ( response . uid ) . to . not . equal ( undefined )
150
- expect ( response . status ) . to . not . equal ( undefined )
151
- expect ( response . action ) . to . not . equal ( undefined )
152
- expect ( response . summary ) . to . not . equal ( undefined )
153
- expect ( response . body ) . to . not . equal ( undefined )
154
- done ( )
155
- } )
156
- . catch ( ( error ) => {
157
- console . error ( 'Job status error:' , error )
158
- done ( error )
159
- } )
165
+ it ( 'should wait for all jobs to be processed before checking status' , async ( ) => {
166
+ await delay ( 5000 ) // Wait 5 seconds for jobs to be processed
160
167
} )
161
168
162
- it ( 'should validate detailed job status response structure' , done => {
163
- doBulkOperationWithManagementToken ( tokenUidDev )
164
- . jobStatus ( { job_id : jobId1 , api_version : '3.2' } )
165
- . then ( ( response ) => {
166
- expect ( response ) . to . not . equal ( undefined )
167
- // Validate main job properties
168
- expect ( response . uid ) . to . not . equal ( undefined )
169
- expect ( response . api_key ) . to . not . equal ( undefined )
170
- expect ( response . status ) . to . not . equal ( undefined )
171
-
172
- // Validate body structure
173
- expect ( response . body ) . to . not . equal ( undefined )
174
- expect ( response . body . locales ) . to . be . an ( 'array' )
175
- expect ( response . body . environments ) . to . be . an ( 'array' )
176
- // Validate summary structure
177
- expect ( response . summary ) . to . not . equal ( undefined )
178
- done ( )
179
- } )
180
- . catch ( ( error ) => {
181
- console . error ( 'Detailed job status error:' , error )
182
- done ( error )
183
- } )
169
+ it ( 'should wait for jobs to be ready and get job status for the first publish job' , async ( ) => {
170
+ const response = await waitForJobReady ( jobId1 )
171
+
172
+ expect ( response ) . to . not . equal ( undefined )
173
+ expect ( response . uid ) . to . not . equal ( undefined )
174
+ expect ( response . status ) . to . not . equal ( undefined )
175
+ expect ( response . action ) . to . not . equal ( undefined )
176
+ expect ( response . summary ) . to . not . equal ( undefined )
177
+ expect ( response . body ) . to . not . equal ( undefined )
184
178
} )
185
179
186
- it ( 'should get job status for the second publish job' , done => {
187
- doBulkOperationWithManagementToken ( tokenUidDev )
188
- . jobStatus ( { job_id : jobId2 , api_version : '3.2' } )
189
- . then ( ( response ) => {
190
- expect ( response ) . to . not . equal ( undefined )
191
- expect ( response . uid ) . to . not . equal ( undefined )
192
- expect ( response . status ) . to . not . equal ( undefined )
193
- expect ( response . action ) . to . not . equal ( undefined )
194
- expect ( response . summary ) . to . not . equal ( undefined )
195
- expect ( response . body ) . to . not . equal ( undefined )
196
- done ( )
197
- } )
198
- . catch ( done )
180
+ it ( 'should validate detailed job status response structure' , async ( ) => {
181
+ const response = await waitForJobReady ( jobId1 )
182
+
183
+ expect ( response ) . to . not . equal ( undefined )
184
+ // Validate main job properties
185
+ expect ( response . uid ) . to . not . equal ( undefined )
186
+ expect ( response . api_key ) . to . not . equal ( undefined )
187
+ expect ( response . status ) . to . not . equal ( undefined )
188
+
189
+ // Validate body structure
190
+ expect ( response . body ) . to . not . equal ( undefined )
191
+ expect ( response . body . locales ) . to . be . an ( 'array' )
192
+ expect ( response . body . environments ) . to . be . an ( 'array' )
193
+ // Validate summary structure
194
+ expect ( response . summary ) . to . not . equal ( undefined )
199
195
} )
200
196
201
- it ( 'should get job status for the third publish job' , done => {
202
- doBulkOperationWithManagementToken ( tokenUidDev )
203
- . jobStatus ( { job_id : jobId3 , api_version : '3.2' } )
204
- . then ( ( response ) => {
205
- expect ( response ) . to . not . equal ( undefined )
206
- expect ( response . uid ) . to . not . equal ( undefined )
207
- expect ( response . status ) . to . not . equal ( undefined )
208
- expect ( response . action ) . to . not . equal ( undefined )
209
- expect ( response . summary ) . to . not . equal ( undefined )
210
- expect ( response . body ) . to . not . equal ( undefined )
211
- done ( )
212
- } )
213
- . catch ( done )
197
+ it ( 'should get job status for the second publish job' , async ( ) => {
198
+ const response = await waitForJobReady ( jobId2 )
199
+
200
+ expect ( response ) . to . not . equal ( undefined )
201
+ expect ( response . uid ) . to . not . equal ( undefined )
202
+ expect ( response . status ) . to . not . equal ( undefined )
203
+ expect ( response . action ) . to . not . equal ( undefined )
204
+ expect ( response . summary ) . to . not . equal ( undefined )
205
+ expect ( response . body ) . to . not . equal ( undefined )
214
206
} )
215
207
216
- it ( 'should get job status with bulk_version parameter' , done => {
217
- doBulkOperationWithManagementToken ( tokenUidDev )
208
+ it ( 'should get job status for the third publish job' , async ( ) => {
209
+ const response = await waitForJobReady ( jobId3 )
210
+
211
+ expect ( response ) . to . not . equal ( undefined )
212
+ expect ( response . uid ) . to . not . equal ( undefined )
213
+ expect ( response . status ) . to . not . equal ( undefined )
214
+ expect ( response . action ) . to . not . equal ( undefined )
215
+ expect ( response . summary ) . to . not . equal ( undefined )
216
+ expect ( response . body ) . to . not . equal ( undefined )
217
+ } )
218
+
219
+ it ( 'should get job status with bulk_version parameter' , async ( ) => {
220
+ await waitForJobReady ( jobId1 )
221
+
222
+ const response = await doBulkOperationWithManagementToken ( tokenUidDev )
218
223
. jobStatus ( { job_id : jobId1 , bulk_version : 'v3' , api_version : '3.2' } )
219
- . then ( ( response ) => {
220
- expect ( response ) . to . not . equal ( undefined )
221
- expect ( response . uid ) . to . not . equal ( undefined )
222
- expect ( response . status ) . to . not . equal ( undefined )
223
- expect ( response . action ) . to . not . equal ( undefined )
224
- expect ( response . summary ) . to . not . equal ( undefined )
225
- expect ( response . body ) . to . not . equal ( undefined )
226
- done ( )
227
- } )
228
- . catch ( done )
224
+
225
+ expect ( response ) . to . not . equal ( undefined )
226
+ expect ( response . uid ) . to . not . equal ( undefined )
227
+ expect ( response . status ) . to . not . equal ( undefined )
228
+ expect ( response . action ) . to . not . equal ( undefined )
229
+ expect ( response . summary ) . to . not . equal ( undefined )
230
+ expect ( response . body ) . to . not . equal ( undefined )
229
231
} )
230
232
231
233
it ( 'should delete a Management Token' , done => {
0 commit comments