Skip to content

Commit c3dbc84

Browse files
Merge pull request #134 from contentstack/test/cs-43466-bulk-operation-sanity-test
test: sanity test for bulk operation
2 parents 5380a43 + 8979e0d commit c3dbc84

File tree

10 files changed

+137
-8
lines changed

10 files changed

+137
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [v1.15.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-03-26)
4+
- Fixes
5+
- sanity test and dependency upgrades
36
## [v1.15.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.3) (2024-02-16)
47
- Fix
58
- Fix for updating entry

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.15.3",
3+
"version": "1.15.4",
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",

sanity-report.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ console.log(`Pending Tests: ${pendingTests}`)
2525
console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`)
2626

2727
const slackMessage = `
28-
*Test Summary*
28+
*JavaScript CMA Report*
2929
• Total Suites: *${totalSuites}*
3030
• Total Tests: *${totalTests}*
3131
• Passed Tests: *${passedTests}*

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path'
22
import { expect } from 'chai'
33
import { describe, it, setup } from 'mocha'
4-
import { jsonReader, writeDownloadedFile } from '../utility/fileOperations/readwrite'
4+
import { jsonReader, jsonWrite, writeDownloadedFile } from '../utility/fileOperations/readwrite'
55
import { contentstackClient } from '../utility/ContentstackClient.js'
66

77
var client = {}
@@ -25,6 +25,7 @@ describe('Assets api Test', () => {
2525
}
2626
makeAsset().create(asset)
2727
.then((asset) => {
28+
jsonWrite(asset, 'publishAsset2.json')
2829
assetUID = asset.uid
2930
assetURL = asset.url
3031
expect(asset.uid).to.be.not.equal(null)
@@ -76,6 +77,7 @@ describe('Assets api Test', () => {
7677
}
7778
makeAsset().create(asset)
7879
.then((asset) => {
80+
jsonWrite(asset, 'publishAsset1.json')
7981
publishAssetUID = asset.uid
8082
expect(asset.uid).to.be.not.equal(null)
8183
expect(asset.url).to.be.not.equal(null)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader } from '../../sanity-check/utility/fileOperations/readwrite'
4+
import { contentstackClient } from '../../sanity-check/utility/ContentstackClient'
5+
import { singlepageCT, multiPageCT } from '../mock/content-type.js'
6+
import dotenv from 'dotenv'
7+
dotenv.config()
8+
9+
let client = {}
10+
let entryUid1 = ''
11+
let assetUid1 = ''
12+
let entryUid2 = ''
13+
let assetUid2 = ''
14+
15+
describe('BulkOperation api test', () => {
16+
setup(() => {
17+
const user = jsonReader('loggedinuser.json')
18+
const entryRead1 = jsonReader('publishEntry1.json')
19+
const assetRead1 = jsonReader('publishAsset1.json')
20+
entryUid1 = entryRead1.uid
21+
assetUid1 = assetRead1.uid
22+
const entryRead2 = jsonReader('publishEntry2.json')
23+
const assetRead2 = jsonReader('publishAsset2.json')
24+
entryUid2 = entryRead2.uid
25+
assetUid2 = assetRead2.uid
26+
client = contentstackClient(user.authtoken)
27+
})
28+
29+
it('should publish one entry when publishDetails of an entry is passed', done => {
30+
const publishDetails = {
31+
entries: [
32+
{
33+
uid: entryUid1,
34+
content_type: multiPageCT.content_type.title,
35+
locale: 'en-us'
36+
}
37+
],
38+
locales: [
39+
'en-us'
40+
],
41+
environments: [
42+
'development'
43+
]
44+
}
45+
doBulkOperation()
46+
.publish({ details: publishDetails, api_version: '3.2' })
47+
.then((response) => {
48+
expect(response.notice).to.not.equal(undefined)
49+
expect(response.job_id).to.not.equal(undefined)
50+
done()
51+
})
52+
.catch(done)
53+
})
54+
55+
it('should publish one asset when publishDetails of an asset is passed', done => {
56+
const publishDetails = {
57+
assets: [
58+
{
59+
uid: assetUid1
60+
}
61+
],
62+
locales: [
63+
'en-us'
64+
],
65+
environments: [
66+
'development'
67+
]
68+
}
69+
doBulkOperation()
70+
.publish({ details: publishDetails, api_version: '3.2' })
71+
.then((response) => {
72+
expect(response.notice).to.not.equal(undefined)
73+
expect(response.job_id).to.not.equal(undefined)
74+
done()
75+
})
76+
.catch(done)
77+
})
78+
79+
it('should publish multiple entries assets when publishDetails of entries and assets are passed', done => {
80+
const publishDetails = {
81+
entries: [
82+
{
83+
uid: entryUid1,
84+
content_type: multiPageCT.content_type.uid,
85+
locale: 'en-us'
86+
},
87+
{
88+
uid: entryUid2,
89+
content_type: singlepageCT.content_type.uid,
90+
locale: 'en-us'
91+
}
92+
],
93+
assets: [
94+
{
95+
uid: assetUid1
96+
},
97+
{
98+
uid: assetUid2
99+
}
100+
],
101+
locales: [
102+
'en-us'
103+
],
104+
environments: [
105+
'development'
106+
]
107+
}
108+
doBulkOperation()
109+
.publish({ details: publishDetails, api_version: '3.2' })
110+
.then((response) => {
111+
expect(response.notice).to.not.equal(undefined)
112+
expect(response.job_id).to.not.equal(undefined)
113+
done()
114+
})
115+
.catch(done)
116+
})
117+
})
118+
119+
function doBulkOperation (uid = null) {
120+
return client.stack({ api_key: process.env.API_KEY }).bulkOperation()
121+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('Entry api Test', () => {
5050
return entry.update({ locale: 'en-at' })
5151
})
5252
.then((entryResponse) => {
53+
jsonWrite(entryResponse, 'publishEntry2.json')
5354
entryUTD = entryResponse.uid
5455
expect(entryResponse.title).to.be.equal('Sample Entry in en-at')
5556
expect(entryResponse.uid).to.be.not.equal(null)
@@ -182,6 +183,7 @@ describe('Entry api Test', () => {
182183
entry: path.join(__dirname, '../mock/entry.json')
183184
})
184185
.then((response) => {
186+
jsonWrite(response, 'publishEntry1.json')
185187
expect(response.uid).to.be.not.equal(null)
186188
done()
187189
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai'
22
import { describe, it } from 'mocha'
3-
import { contentstackClient } from '../../utility/ContentstackClient'
4-
import { jsonWrite } from '../../utility/fileOperations/readwrite'
3+
import { contentstackClient } from '../../sanity-check/utility/ContentstackClient'
4+
import { jsonWrite } from '../../sanity-check/utility/fileOperations/readwrite'
55
import axios from 'axios'
66
import dotenv from 'dotenv'
77

test/sanity-check/sanity.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require('./api/contentType-test')
1313
require('./api/asset-test')
1414
require('./api/extension-test')
1515
require('./api/entry-test')
16+
require('./api/bulkOperation-test')
1617
require('./api/webhook-test')
1718
require('./api/workflow-test')
1819
require('./api/globalfield-test')

test/sanity-check/utility/fileOperations/readwrite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
3-
const dataFiles = './test/utility/dataFiles/'
3+
const dataFiles = './test/sanity-check/utility/dataFiles/'
44
export function jsonReader (fileName) {
55
if (!fs.existsSync(`${dataFiles}${fileName}`)) {
66
return

0 commit comments

Comments
 (0)