Skip to content

Commit de267b4

Browse files
update items implementation,api and unit test cases and types support
1 parent ee7f925 commit de267b4

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

lib/stack/bulkOperation/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ export function BulkOperation (http, data = {}) {
2727
}
2828
};
2929

30+
this.updateItems = async ({ data, bulk_version = "" }) => {
31+
this.urlPath = `/bulk/release/update_items`;
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.put(this.urlPath, data, headers);
40+
if (response.data) {
41+
return response.data;
42+
}
43+
} catch (error) {
44+
console.error(error);
45+
}
46+
};
47+
3048
this.jobStatus = async ({ job_id, bulk_version = "" }) => {
3149
this.urlPath = `/bulk/jobs/${job_id}`;
3250
const headers = {

lib/stack/release/items/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ export function ReleaseItem (http, data = {}) {
166166
...cloneDeep(param)
167167
}
168168
} || {}
169-
169+
if (param.release_version) {
170+
headers.headers['release_version'] = param.release_version;
171+
delete headers.params.release_version;
172+
}
170173
const response = await http.get(this.urlPath, headers)
171174
if (response.data) {
172175
return new ContentstackCollection(response, http, this.stackHeaders, ReleaseItemCollection)

test/sanity-check/api/release-test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('Relases api Test', () => {
101101
it('should fetch a Release items from Uid', done => {
102102
makeRelease(releaseUID)
103103
.item()
104-
.findAll()
104+
.findAll({release_version: '2.0'})
105105
.then((collection) => {
106106
const itemdelete = collection.items[0]
107107
itemToDelete['version'] = itemdelete.version
@@ -257,6 +257,26 @@ describe('Relases api Test', () => {
257257
.catch(done)
258258
})
259259

260+
261+
it('Bulk Operation: should update items to a release', done => {
262+
const items = {
263+
release: releaseUID,
264+
action: 'publish',
265+
locale: ['en-us'],
266+
reference: true,
267+
items: [
268+
'$all'
269+
],
270+
}
271+
doBulkOperation().updateItems({ data: items, bulk_version: '2.0' })
272+
.then((response) => {
273+
expect(response.notice).to.equal('Your update release items to latest version request is in progress.')
274+
expect(response.job_id).to.not.equal(undefined)
275+
done()
276+
})
277+
.catch(done)
278+
})
279+
260280
it('should delete specific Releases with Uid ', done => {
261281
makeRelease(releaseUID)
262282
.delete()

test/unit/bulkOperation-test.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ describe('Contentstack BulkOperation test', () => {
3131

3232
it('should add items to a release', async () => {
3333
const items = {
34-
release: 'blt05e951e5f3a1d342',
34+
release: 'release_uid',
3535
action: 'publish',
3636
locale: ['en-us'],
3737
reference: true,
3838
items: [
3939
{
4040
content_type_uid: 'ct_1',
41-
uid: 'bltf6e197a18a11ec5f',
41+
uid: 'entry_uid',
4242
version: 2,
4343
locale: 'en-us',
4444
title: 'validation test',
@@ -57,6 +57,29 @@ describe('Contentstack BulkOperation test', () => {
5757
expect(response.job_id).to.not.equal(undefined);
5858
});
5959

60+
it('should update items to a release', async () => {
61+
const items = {
62+
release: 'release_uid',
63+
action: 'publish',
64+
locale: ['en-us'],
65+
reference: true,
66+
items: [
67+
'$all'
68+
],
69+
};
70+
71+
var mock = new MockAdapter(Axios);
72+
mock.onPut('/bulk/release/update_items').reply(200, {
73+
notice: 'Your update release items to latest version request is in progress.',
74+
job_id: 'job_id',
75+
});
76+
77+
const response = await makeBulkOperation().updateItems({ data: items, bulk_version: '2.0' });
78+
console.log("🚀 ~ it ~ response:", response)
79+
expect(response.notice).to.equal('Your update release items to latest version request is in progress.');
80+
expect(response.job_id).to.not.equal(undefined);
81+
});
82+
6083
it('should publish items in bulk', async () => {
6184
const publishDetails = {
6285
entries: [

types/stack/bulkOperation/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface BulkOperation extends SystemFields {
77
unpublish(config: BulkOperationConfig): Promise<Response>
88
delete(config: BulkDeleteConfig): Promise<Response>
99
addItems(config: AddItemsConfig): Promise<Response>
10-
10+
updateItems(config: AddItemsConfig): Promise<Response>
1111
jobStatus(config: BulkJobStatus): Promise<Response>
1212
}
1313
export interface BulkOperationConfig {

0 commit comments

Comments
 (0)