Skip to content

Commit 8b34fd5

Browse files
Added publish_all_localized flag in bulk publish/unpublish
1 parent fcd19fc commit 8b34fd5

File tree

5 files changed

+326
-5
lines changed

5 files changed

+326
-5
lines changed

lib/stack/bulkOperation/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function BulkOperation (http, data = {}) {
187187
*
188188
*/
189189
// eslint-disable-next-line camelcase
190-
this.publish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => {
190+
this.publish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '', publishAllLocalized = false }) => {
191191
var httpBody = {}
192192
if (details) {
193193
httpBody = cloneDeep(details)
@@ -212,6 +212,12 @@ export function BulkOperation (http, data = {}) {
212212
if (approvals) {
213213
headers.headers.approvals = approvals
214214
}
215+
if (publishAllLocalized) {
216+
if (!headers.params) {
217+
headers.params = {}
218+
}
219+
headers.params.publish_all_localized = publishAllLocalized
220+
}
215221

216222
// eslint-disable-next-line camelcase
217223
if (api_version) headers.headers.api_version = api_version
@@ -279,7 +285,7 @@ export function BulkOperation (http, data = {}) {
279285
* .then((response) => { console.log(response.notice) })
280286
*/
281287
// eslint-disable-next-line camelcase
282-
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => {
288+
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '', unpublishAllLocalized = false }) => {
283289
var httpBody = {}
284290
if (details) {
285291
httpBody = cloneDeep(details)
@@ -306,6 +312,13 @@ export function BulkOperation (http, data = {}) {
306312
}
307313
// eslint-disable-next-line camelcase
308314
if (api_version) headers.headers.api_version = api_version
315+
316+
if (unpublishAllLocalized) {
317+
if (!headers.params) {
318+
headers.params = {}
319+
}
320+
headers.params.publish_all_localized = unpublishAllLocalized
321+
}
309322
return publishUnpublish(http, '/bulk/unpublish', httpBody, headers)
310323
}
311324

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.24.0",
3+
"version": "1.25.0",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",

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

Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ let assetUid2 = ''
1616
let jobId1 = ''
1717
let jobId2 = ''
1818
let jobId3 = ''
19+
let jobId4 = ''
20+
let jobId5 = ''
21+
let jobId6 = ''
22+
let jobId7 = ''
23+
let jobId8 = ''
24+
let jobId9 = ''
25+
let jobId10 = ''
1926
let tokenUidDev = ''
2027
let tokenUid = ''
2128

@@ -162,6 +169,228 @@ describe('BulkOperation api test', () => {
162169
.catch(done)
163170
})
164171

172+
it('should publish entries with publishAllLocalized parameter set to true', done => {
173+
const publishDetails = {
174+
entries: [
175+
{
176+
uid: entryUid1,
177+
content_type: multiPageCT.content_type.uid,
178+
locale: 'en-us'
179+
}
180+
],
181+
locales: [
182+
'en-us'
183+
],
184+
environments: [
185+
'development'
186+
]
187+
}
188+
doBulkOperation()
189+
.publish({
190+
details: publishDetails,
191+
api_version: '3.2',
192+
publishAllLocalized: true
193+
})
194+
.then((response) => {
195+
expect(response.notice).to.not.equal(undefined)
196+
expect(response.job_id).to.not.equal(undefined)
197+
// Store job ID for later status check
198+
jobId4 = response.job_id
199+
done()
200+
})
201+
.catch(done)
202+
})
203+
204+
it('should publish entries with publishAllLocalized parameter set to false', done => {
205+
const publishDetails = {
206+
entries: [
207+
{
208+
uid: entryUid2,
209+
content_type: singlepageCT.content_type.uid,
210+
locale: 'en-us'
211+
}
212+
],
213+
locales: [
214+
'en-us'
215+
],
216+
environments: [
217+
'development'
218+
]
219+
}
220+
doBulkOperation()
221+
.publish({
222+
details: publishDetails,
223+
api_version: '3.2',
224+
publishAllLocalized: false
225+
})
226+
.then((response) => {
227+
expect(response.notice).to.not.equal(undefined)
228+
expect(response.job_id).to.not.equal(undefined)
229+
// Store job ID for later status check
230+
jobId5 = response.job_id
231+
done()
232+
})
233+
.catch(done)
234+
})
235+
236+
it('should publish assets with publishAllLocalized parameter', done => {
237+
const publishDetails = {
238+
assets: [
239+
{
240+
uid: assetUid1
241+
}
242+
],
243+
locales: [
244+
'en-us'
245+
],
246+
environments: [
247+
'development'
248+
]
249+
}
250+
doBulkOperation()
251+
.publish({
252+
details: publishDetails,
253+
api_version: '3.2',
254+
publishAllLocalized: true
255+
})
256+
.then((response) => {
257+
expect(response.notice).to.not.equal(undefined)
258+
expect(response.job_id).to.not.equal(undefined)
259+
// Store job ID for later status check
260+
jobId6 = response.job_id
261+
done()
262+
})
263+
.catch(done)
264+
})
265+
266+
it('should unpublish entries with unpublishAllLocalized parameter set to true', done => {
267+
const unpublishDetails = {
268+
entries: [
269+
{
270+
uid: entryUid1,
271+
content_type: multiPageCT.content_type.uid,
272+
locale: 'en-us'
273+
}
274+
],
275+
locales: [
276+
'en-us'
277+
],
278+
environments: [
279+
'development'
280+
]
281+
}
282+
doBulkOperation()
283+
.unpublish({
284+
details: unpublishDetails,
285+
api_version: '3.2',
286+
unpublishAllLocalized: true
287+
})
288+
.then((response) => {
289+
expect(response.notice).to.not.equal(undefined)
290+
expect(response.job_id).to.not.equal(undefined)
291+
// Store job ID for later status check
292+
jobId7 = response.job_id
293+
done()
294+
})
295+
.catch(done)
296+
})
297+
298+
it('should unpublish entries with unpublishAllLocalized parameter set to false', done => {
299+
const unpublishDetails = {
300+
entries: [
301+
{
302+
uid: entryUid2,
303+
content_type: singlepageCT.content_type.uid,
304+
locale: 'en-us'
305+
}
306+
],
307+
locales: [
308+
'en-us'
309+
],
310+
environments: [
311+
'development'
312+
]
313+
}
314+
doBulkOperation()
315+
.unpublish({
316+
details: unpublishDetails,
317+
api_version: '3.2',
318+
unpublishAllLocalized: false
319+
})
320+
.then((response) => {
321+
expect(response.notice).to.not.equal(undefined)
322+
expect(response.job_id).to.not.equal(undefined)
323+
// Store job ID for later status check
324+
jobId8 = response.job_id
325+
done()
326+
})
327+
.catch(done)
328+
})
329+
330+
it('should unpublish assets with unpublishAllLocalized parameter', done => {
331+
const unpublishDetails = {
332+
assets: [
333+
{
334+
uid: assetUid1
335+
}
336+
],
337+
locales: [
338+
'en-us'
339+
],
340+
environments: [
341+
'development'
342+
]
343+
}
344+
doBulkOperation()
345+
.unpublish({
346+
details: unpublishDetails,
347+
api_version: '3.2',
348+
unpublishAllLocalized: true
349+
})
350+
.then((response) => {
351+
expect(response.notice).to.not.equal(undefined)
352+
expect(response.job_id).to.not.equal(undefined)
353+
// Store job ID for later status check
354+
jobId9 = response.job_id
355+
done()
356+
})
357+
.catch(done)
358+
})
359+
360+
it('should publish entries with multiple parameters including publishAllLocalized', done => {
361+
const publishDetails = {
362+
entries: [
363+
{
364+
uid: entryUid1,
365+
content_type: multiPageCT.content_type.uid,
366+
locale: 'en-us'
367+
}
368+
],
369+
locales: [
370+
'en-us'
371+
],
372+
environments: [
373+
'development'
374+
]
375+
}
376+
doBulkOperation()
377+
.publish({
378+
details: publishDetails,
379+
api_version: '3.2',
380+
publishAllLocalized: true,
381+
skip_workflow_stage: true,
382+
approvals: true
383+
})
384+
.then((response) => {
385+
expect(response.notice).to.not.equal(undefined)
386+
expect(response.job_id).to.not.equal(undefined)
387+
// Store job ID for later status check
388+
jobId10 = response.job_id
389+
done()
390+
})
391+
.catch(done)
392+
})
393+
165394
it('should wait for all jobs to be processed before checking status', async () => {
166395
await delay(5000) // Wait 5 seconds for jobs to be processed
167396
})
@@ -216,6 +445,83 @@ describe('BulkOperation api test', () => {
216445
expect(response.body).to.not.equal(undefined)
217446
})
218447

448+
it('should get job status for publishAllLocalized=true job', async () => {
449+
const response = await waitForJobReady(jobId4)
450+
451+
expect(response).to.not.equal(undefined)
452+
expect(response.uid).to.not.equal(undefined)
453+
expect(response.status).to.not.equal(undefined)
454+
expect(response.action).to.not.equal(undefined)
455+
expect(response.summary).to.not.equal(undefined)
456+
expect(response.body).to.not.equal(undefined)
457+
})
458+
459+
it('should get job status for publishAllLocalized=false job', async () => {
460+
const response = await waitForJobReady(jobId5)
461+
462+
expect(response).to.not.equal(undefined)
463+
expect(response.uid).to.not.equal(undefined)
464+
expect(response.status).to.not.equal(undefined)
465+
expect(response.action).to.not.equal(undefined)
466+
expect(response.summary).to.not.equal(undefined)
467+
expect(response.body).to.not.equal(undefined)
468+
})
469+
470+
it('should get job status for asset publishAllLocalized job', async () => {
471+
const response = await waitForJobReady(jobId6)
472+
473+
expect(response).to.not.equal(undefined)
474+
expect(response.uid).to.not.equal(undefined)
475+
expect(response.status).to.not.equal(undefined)
476+
expect(response.action).to.not.equal(undefined)
477+
expect(response.summary).to.not.equal(undefined)
478+
expect(response.body).to.not.equal(undefined)
479+
})
480+
481+
it('should get job status for unpublishAllLocalized=true job', async () => {
482+
const response = await waitForJobReady(jobId7)
483+
484+
expect(response).to.not.equal(undefined)
485+
expect(response.uid).to.not.equal(undefined)
486+
expect(response.status).to.not.equal(undefined)
487+
expect(response.action).to.not.equal(undefined)
488+
expect(response.summary).to.not.equal(undefined)
489+
expect(response.body).to.not.equal(undefined)
490+
})
491+
492+
it('should get job status for unpublishAllLocalized=false job', async () => {
493+
const response = await waitForJobReady(jobId8)
494+
495+
expect(response).to.not.equal(undefined)
496+
expect(response.uid).to.not.equal(undefined)
497+
expect(response.status).to.not.equal(undefined)
498+
expect(response.action).to.not.equal(undefined)
499+
expect(response.summary).to.not.equal(undefined)
500+
expect(response.body).to.not.equal(undefined)
501+
})
502+
503+
it('should get job status for asset unpublishAllLocalized job', async () => {
504+
const response = await waitForJobReady(jobId9)
505+
506+
expect(response).to.not.equal(undefined)
507+
expect(response.uid).to.not.equal(undefined)
508+
expect(response.status).to.not.equal(undefined)
509+
expect(response.action).to.not.equal(undefined)
510+
expect(response.summary).to.not.equal(undefined)
511+
expect(response.body).to.not.equal(undefined)
512+
})
513+
514+
it('should get job status for multiple parameters job', async () => {
515+
const response = await waitForJobReady(jobId10)
516+
517+
expect(response).to.not.equal(undefined)
518+
expect(response.uid).to.not.equal(undefined)
519+
expect(response.status).to.not.equal(undefined)
520+
expect(response.action).to.not.equal(undefined)
521+
expect(response.summary).to.not.equal(undefined)
522+
expect(response.body).to.not.equal(undefined)
523+
})
524+
219525
it('should get job status with bulk_version parameter', async () => {
220526
await waitForJobReady(jobId1)
221527

0 commit comments

Comments
 (0)