File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed
types/stack/bulkOperation Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,24 @@ export function BulkOperation (http, data = {}) {
2727 }
2828 } ;
2929
30+ this . jobStatus = async ( { job_id, bulk_version = "" } ) => {
31+ this . urlPath = `/bulk/jobs/${ job_id } ` ;
32+ const headers = {
33+ headers : {
34+ ...cloneDeep ( this . stackHeaders ) ,
35+ } ,
36+ } ;
37+ if ( bulk_version ) headers . headers . bulk_version = bulk_version ;
38+ try {
39+ const response = await http . get ( this . urlPath , headers ) ;
40+ if ( response . data ) {
41+ return response . data ;
42+ }
43+ } catch ( error ) {
44+ console . error ( error ) ;
45+ }
46+ } ;
47+
3048 /**
3149 * The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time.
3250 * @memberof BulkOperation
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ let releaseUID = ''
1313let releaseUID2 = ''
1414let entries = { }
1515const itemToDelete = { }
16+ const jobId = ''
1617
1718describe ( 'Relases api Test' , ( ) => {
1819 setup ( ( ) => {
@@ -238,13 +239,24 @@ describe('Relases api Test', () => {
238239 }
239240 doBulkOperation ( ) . addItems ( { data : items , bulk_version : '2.0' } )
240241 . then ( ( response ) => {
242+ jobId = response . job_id
241243 expect ( response . notice ) . to . equal ( 'Your add to release request is in progress.' )
242244 expect ( response . job_id ) . to . not . equal ( undefined )
243245 done ( )
244246 } )
245247 . catch ( done )
246248 } )
247249
250+ it ( 'Bulk Operation: should fetch job status details' , done => {
251+ doBulkOperation ( ) . jobStatus ( { job_id : jobId , bulk_version : '2.0' } )
252+ . then ( ( response ) => {
253+ expect ( response . job ) . to . not . equal ( undefined )
254+ expect ( response . job . _id ) . to . equal ( jobId )
255+ done ( )
256+ } )
257+ . catch ( done )
258+ } )
259+
248260 it ( 'should delete specific Releases with Uid ' , done => {
249261 makeRelease ( releaseUID )
250262 . delete ( )
Original file line number Diff line number Diff line change @@ -179,6 +179,23 @@ describe('Contentstack BulkOperation test', () => {
179179 expect ( response . notice ) . to . equal ( 'Your update request is in progress.' ) ;
180180 expect ( response . job_id ) . to . not . equal ( undefined ) ;
181181 } ) ;
182+
183+ it ( 'should fetch job status' , async ( ) => {
184+ const jobId = 'job_id' ;
185+ const jobStatusDetails = {
186+ job_id : jobId ,
187+ } ;
188+
189+ var mock = new MockAdapter ( Axios ) ;
190+ mock . onGet ( `/bulk/jobs/${ jobId } ` ) . reply ( 200 , {
191+ notice : 'Your job status request is successful.' ,
192+ status : 'completed' ,
193+ } ) ;
194+
195+ const response = await makeBulkOperation ( ) . jobStatus ( jobStatusDetails ) ;
196+ expect ( response . notice ) . to . equal ( 'Your job status request is successful.' ) ;
197+ expect ( response . status ) . to . equal ( 'completed' ) ;
198+ } ) ;
182199} ) ;
183200
184201function makeBulkOperation ( data ) {
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ export interface BulkOperation extends SystemFields {
77 unpublish ( config : BulkOperationConfig ) : Promise < Response >
88 delete ( config : BulkDeleteConfig ) : Promise < Response >
99 addItems ( config : AddItemsConfig ) : Promise < Response >
10+
11+ jobStatus ( config : BulkJobStatus ) : Promise < Response >
1012}
1113export interface BulkOperationConfig {
1214 details : PublishItems
@@ -50,4 +52,9 @@ export interface BranchData extends AnyProperty {
5052export interface BulkAddItemsConfig {
5153 data : AnyProperty ;
5254 bulk_version ?: string ;
55+ }
56+
57+ export interface BulkJobStatus {
58+ job_id : AnyProperty ;
59+ bulk_version ?: string ;
5360}
You can’t perform that action at this time.
0 commit comments