diff --git a/lib/stack/bulkOperation/index.js b/lib/stack/bulkOperation/index.js index 945f8dd9..8534d99a 100644 --- a/lib/stack/bulkOperation/index.js +++ b/lib/stack/bulkOperation/index.js @@ -27,6 +27,24 @@ export function BulkOperation (http, data = {}) { } }; + this.jobStatus = async ({ job_id, bulk_version = "" }) => { + this.urlPath = `/bulk/jobs/${job_id}`; + const headers = { + headers: { + ...cloneDeep(this.stackHeaders), + }, + }; + if (bulk_version) headers.headers.bulk_version = bulk_version; + try { + const response = await http.get(this.urlPath, headers); + if (response.data) { + return response.data; + } + } catch (error) { + console.error(error); + } + }; + /** * The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time. * @memberof BulkOperation diff --git a/test/sanity-check/api/release-test.js b/test/sanity-check/api/release-test.js index 8b4a1a7c..5d5e7684 100644 --- a/test/sanity-check/api/release-test.js +++ b/test/sanity-check/api/release-test.js @@ -13,6 +13,7 @@ let releaseUID = '' let releaseUID2 = '' let entries = {} const itemToDelete = {} +const jobId = '' describe('Relases api Test', () => { setup(() => { @@ -238,6 +239,7 @@ describe('Relases api Test', () => { } doBulkOperation().addItems({ data: items, bulk_version: '2.0' }) .then((response) => { + jobId = response.job_id expect(response.notice).to.equal('Your add to release request is in progress.') expect(response.job_id).to.not.equal(undefined) done() @@ -245,6 +247,16 @@ describe('Relases api Test', () => { .catch(done) }) + it('Bulk Operation: should fetch job status details', done => { + doBulkOperation().jobStatus({ job_id: jobId, bulk_version: '2.0' }) + .then((response) => { + expect(response.job).to.not.equal(undefined) + expect(response.job._id).to.equal(jobId) + done() + }) + .catch(done) + }) + it('should delete specific Releases with Uid ', done => { makeRelease(releaseUID) .delete() diff --git a/test/unit/bulkOperation-test.js b/test/unit/bulkOperation-test.js index 0f21f6fd..89fa9a01 100644 --- a/test/unit/bulkOperation-test.js +++ b/test/unit/bulkOperation-test.js @@ -179,6 +179,23 @@ describe('Contentstack BulkOperation test', () => { expect(response.notice).to.equal('Your update request is in progress.'); expect(response.job_id).to.not.equal(undefined); }); + + it('should fetch job status', async () => { + const jobId = 'job_id'; + const jobStatusDetails = { + job_id: jobId, + }; + + var mock = new MockAdapter(Axios); + mock.onGet(`/bulk/jobs/${jobId}`).reply(200, { + notice: 'Your job status request is successful.', + status: 'completed', + }); + + const response = await makeBulkOperation().jobStatus(jobStatusDetails); + expect(response.notice).to.equal('Your job status request is successful.'); + expect(response.status).to.equal('completed'); + }); }); function makeBulkOperation(data) { diff --git a/types/stack/bulkOperation/index.d.ts b/types/stack/bulkOperation/index.d.ts index feb2160d..6f1dd731 100644 --- a/types/stack/bulkOperation/index.d.ts +++ b/types/stack/bulkOperation/index.d.ts @@ -7,6 +7,8 @@ export interface BulkOperation extends SystemFields { unpublish(config: BulkOperationConfig): Promise delete(config: BulkDeleteConfig): Promise addItems(config: AddItemsConfig): Promise + + jobStatus(config: BulkJobStatus): Promise } export interface BulkOperationConfig { details: PublishItems @@ -50,4 +52,9 @@ export interface BranchData extends AnyProperty { export interface BulkAddItemsConfig { data: AnyProperty; bulk_version?: string; +} + +export interface BulkJobStatus { + job_id: AnyProperty; + bulk_version?: string; } \ No newline at end of file