Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dx | 1592 fetch job status #233

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading