@@ -3,21 +3,21 @@ import { describe, it, setup } from 'mocha'
3
3
import { jsonReader } from '../../sanity-check/utility/fileOperations/readwrite'
4
4
import { contentstackClient } from '../../sanity-check/utility/ContentstackClient'
5
5
import { singlepageCT , multiPageCT } from '../mock/content-type.js'
6
- // import { createManagementToken } from '../mock/managementToken.js'
6
+ import { createManagementToken } from '../mock/managementToken.js'
7
7
import dotenv from 'dotenv'
8
8
dotenv . config ( )
9
9
10
10
let client = { }
11
- // let clientWithManagementToken = {}
11
+ let clientWithManagementToken = { }
12
12
let entryUid1 = ''
13
13
let assetUid1 = ''
14
14
let entryUid2 = ''
15
15
let assetUid2 = ''
16
- // let jobId1 = ''
17
- // let jobId2 = ''
18
- // let jobId3 = ''
19
- // let tokenUidDev = ''
20
- // let tokenUid = ''
16
+ let jobId1 = ''
17
+ let jobId2 = ''
18
+ let jobId3 = ''
19
+ let tokenUidDev = ''
20
+ let tokenUid = ''
21
21
22
22
describe ( 'BulkOperation api test' , ( ) => {
23
23
setup ( ( ) => {
@@ -31,23 +31,23 @@ describe('BulkOperation api test', () => {
31
31
entryUid2 = entryRead2 . uid
32
32
assetUid2 = assetRead2 . uid
33
33
client = contentstackClient ( user . authtoken )
34
- // clientWithManagementToken = contentstackClient()
34
+ clientWithManagementToken = contentstackClient ( )
35
35
} )
36
36
37
- // it('should create a Management Token for get job status', done => {
38
- // makeManagementToken()
39
- // .create(createManagementToken)
40
- // .then((token) => {
41
- // tokenUidDev = token.token
42
- // tokenUid = token.uid
43
- // expect(token.name).to.be.equal(createManagementToken.token.name)
44
- // expect(token.description).to.be.equal(createManagementToken.token.description)
45
- // expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module)
46
- // expect(token.uid).to.be.not.equal(null)
47
- // done()
48
- // })
49
- // .catch(done)
50
- // })
37
+ it ( 'should create a Management Token for get job status' , done => {
38
+ makeManagementToken ( )
39
+ . create ( createManagementToken )
40
+ . then ( ( token ) => {
41
+ tokenUidDev = token . token
42
+ tokenUid = token . uid
43
+ expect ( token . name ) . to . be . equal ( createManagementToken . token . name )
44
+ expect ( token . description ) . to . be . equal ( createManagementToken . token . description )
45
+ expect ( token . scope [ 0 ] . module ) . to . be . equal ( createManagementToken . token . scope [ 0 ] . module )
46
+ expect ( token . uid ) . to . be . not . equal ( null )
47
+ done ( )
48
+ } )
49
+ . catch ( done )
50
+ } )
51
51
52
52
it ( 'should publish one entry when publishDetails of an entry is passed' , done => {
53
53
const publishDetails = {
@@ -70,7 +70,7 @@ describe('BulkOperation api test', () => {
70
70
. then ( ( response ) => {
71
71
expect ( response . notice ) . to . not . equal ( undefined )
72
72
expect ( response . job_id ) . to . not . equal ( undefined )
73
- // jobId1 = response.job_id
73
+ jobId1 = response . job_id
74
74
done ( )
75
75
} )
76
76
. catch ( done )
@@ -95,7 +95,7 @@ describe('BulkOperation api test', () => {
95
95
. then ( ( response ) => {
96
96
expect ( response . notice ) . to . not . equal ( undefined )
97
97
expect ( response . job_id ) . to . not . equal ( undefined )
98
- // jobId2 = response.job_id
98
+ jobId2 = response . job_id
99
99
done ( )
100
100
} )
101
101
. catch ( done )
@@ -135,128 +135,121 @@ describe('BulkOperation api test', () => {
135
135
. then ( ( response ) => {
136
136
expect ( response . notice ) . to . not . equal ( undefined )
137
137
expect ( response . job_id ) . to . not . equal ( undefined )
138
- // jobId3 = response.job_id
138
+ jobId3 = response . job_id
139
139
done ( )
140
140
} )
141
141
. catch ( done )
142
142
} )
143
143
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
- // })
160
- // })
161
-
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)
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
+ } )
160
+ } )
171
161
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
- // })
184
- // })
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 )
185
171
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)
199
- // })
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
+ } )
184
+ } )
200
185
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)
214
- // })
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 )
199
+ } )
215
200
216
- // it('should get job status with bulk_version parameter ', done => {
217
- // doBulkOperationWithManagementToken(tokenUidDev)
218
- // .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)
229
- // })
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 )
214
+ } )
230
215
231
- // it('should test job status endpoint accessibility', done => {
232
- // doBulkOperationWithManagementToken(tokenUidDev)
233
- // .jobStatus({ job_id: 'test-job-id', api_version: '3.2' })
234
- // .then((response) => {
235
- // done()
236
- // })
237
- // .catch((error) => {
238
- // console.log('Job status endpoint error (expected for invalid job ID):', error.message)
239
- // // This is expected to fail with invalid job ID, but should not be an auth error
240
- // if (error.message && (error.message.includes('authentication') || error.message.includes('401'))) {
241
- // done(error)
242
- // } else {
243
- // done() // Expected error for invalid job ID
244
- // }
245
- // })
246
- // })
216
+ it ( 'should get job status with bulk_version parameter' , done => {
217
+ doBulkOperationWithManagementToken ( tokenUidDev )
218
+ . 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 )
229
+ } )
247
230
248
- // it('should delete a Management Token', done => {
249
- // makeManagementToken(tokenUid)
250
- // .delete()
251
- // .then((data) => {
252
- // expect(data.notice).to.be.equal('Management Token deleted successfully.')
253
- // done()
254
- // })
255
- // .catch(done)
256
- // })
231
+ it ( 'should delete a Management Token' , done => {
232
+ makeManagementToken ( tokenUid )
233
+ . delete ( )
234
+ . then ( ( data ) => {
235
+ expect ( data . notice ) . to . be . equal ( 'Management Token deleted successfully.' )
236
+ done ( )
237
+ } )
238
+ . catch ( done )
239
+ } )
257
240
} )
258
241
259
242
function doBulkOperation ( uid = null ) {
260
243
// @ts -ignore-next-line secret-detection
261
244
return client . stack ( { api_key : process . env . API_KEY } ) . bulkOperation ( )
262
245
}
246
+
247
+ function doBulkOperationWithManagementToken ( tokenUidDev ) {
248
+ // @ts -ignore-next-line secret-detection
249
+ return clientWithManagementToken . stack ( { api_key : process . env . API_KEY , management_token : tokenUidDev } ) . bulkOperation ( )
250
+ }
251
+
252
+ function makeManagementToken ( uid = null ) {
253
+ // @ts -ignore-next-line secret-detection
254
+ return client . stack ( { api_key : process . env . API_KEY } ) . managementToken ( uid )
255
+ }
0 commit comments