Skip to content

Commit

Permalink
implementation, api and unit test case for fetch by job status
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Dec 17, 2024
1 parent 3fba7cf commit d96c4ac
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/stack/bulkOperation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/sanity-check/api/release-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let releaseUID = ''
let releaseUID2 = ''
let entries = {}
const itemToDelete = {}
const jobId = ''

describe('Relases api Test', () => {
setup(() => {
Expand Down Expand Up @@ -238,13 +239,24 @@ 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()
})
.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()
Expand Down
17 changes: 17 additions & 0 deletions test/unit/bulkOperation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions types/stack/bulkOperation/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface BulkOperation extends SystemFields {
unpublish(config: BulkOperationConfig): Promise<Response>
delete(config: BulkDeleteConfig): Promise<Response>
addItems(config: AddItemsConfig): Promise<Response>

jobStatus(config: BulkJobStatus): Promise<Response>
}
export interface BulkOperationConfig {
details: PublishItems
Expand Down Expand Up @@ -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;
}

0 comments on commit d96c4ac

Please sign in to comment.