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

test: sanity test for bulk operation #134

Merged
merged 2 commits into from
Mar 22, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [v1.15.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-03-26)
- Fixes
- sanity test and dependency upgrades
## [v1.15.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.3) (2024-02-16)
- Fix
- Fix for updating entry
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.15.3",
"version": "1.15.4",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down
2 changes: 1 addition & 1 deletion sanity-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ console.log(`Pending Tests: ${pendingTests}`)
console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`)

const slackMessage = `
*Test Summary*
*JavaScript CMA Report*
• Total Suites: *${totalSuites}*
• Total Tests: *${totalTests}*
• Passed Tests: *${passedTests}*
Expand Down
4 changes: 3 additions & 1 deletion test/sanity-check/api/asset-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader, writeDownloadedFile } from '../utility/fileOperations/readwrite'
import { jsonReader, jsonWrite, writeDownloadedFile } from '../utility/fileOperations/readwrite'
import { contentstackClient } from '../utility/ContentstackClient.js'

var client = {}
Expand All @@ -25,6 +25,7 @@ describe('Assets api Test', () => {
}
makeAsset().create(asset)
.then((asset) => {
jsonWrite(asset, 'publishAsset2.json')
assetUID = asset.uid
assetURL = asset.url
expect(asset.uid).to.be.not.equal(null)
Expand Down Expand Up @@ -76,6 +77,7 @@ describe('Assets api Test', () => {
}
makeAsset().create(asset)
.then((asset) => {
jsonWrite(asset, 'publishAsset1.json')
publishAssetUID = asset.uid
expect(asset.uid).to.be.not.equal(null)
expect(asset.url).to.be.not.equal(null)
Expand Down
121 changes: 121 additions & 0 deletions test/sanity-check/api/bulkOperation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../../sanity-check/utility/fileOperations/readwrite'
import { contentstackClient } from '../../sanity-check/utility/ContentstackClient'
import { singlepageCT, multiPageCT } from '../mock/content-type.js'
import dotenv from 'dotenv'
dotenv.config()

let client = {}
let entryUid1 = ''
let assetUid1 = ''
let entryUid2 = ''
let assetUid2 = ''

describe('BulkOperation api test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
const entryRead1 = jsonReader('publishEntry1.json')
const assetRead1 = jsonReader('publishAsset1.json')
entryUid1 = entryRead1.uid
assetUid1 = assetRead1.uid
const entryRead2 = jsonReader('publishEntry2.json')
const assetRead2 = jsonReader('publishAsset2.json')
entryUid2 = entryRead2.uid
assetUid2 = assetRead2.uid
client = contentstackClient(user.authtoken)
})

it('should publish one entry when publishDetails of an entry is passed', done => {
const publishDetails = {
entries: [
{
uid: entryUid1,
content_type: multiPageCT.content_type.title,
locale: 'en-us'
}
],
locales: [
'en-us'
],
environments: [
'development'
]
}
doBulkOperation()
.publish({ details: publishDetails, api_version: '3.2' })
.then((response) => {
expect(response.notice).to.not.equal(undefined)
expect(response.job_id).to.not.equal(undefined)
done()
})
.catch(done)
})

it('should publish one asset when publishDetails of an asset is passed', done => {
const publishDetails = {
assets: [
{
uid: assetUid1
}
],
locales: [
'en-us'
],
environments: [
'development'
]
}
doBulkOperation()
.publish({ details: publishDetails, api_version: '3.2' })
.then((response) => {
expect(response.notice).to.not.equal(undefined)
expect(response.job_id).to.not.equal(undefined)
done()
})
.catch(done)
})

it('should publish multiple entries assets when publishDetails of entries and assets are passed', done => {
const publishDetails = {
entries: [
{
uid: entryUid1,
content_type: multiPageCT.content_type.uid,
locale: 'en-us'
},
{
uid: entryUid2,
content_type: singlepageCT.content_type.uid,
locale: 'en-us'
}
],
assets: [
{
uid: assetUid1
},
{
uid: assetUid2
}
],
locales: [
'en-us'
],
environments: [
'development'
]
}
doBulkOperation()
.publish({ details: publishDetails, api_version: '3.2' })
.then((response) => {
expect(response.notice).to.not.equal(undefined)
expect(response.job_id).to.not.equal(undefined)
done()
})
.catch(done)
})
})

function doBulkOperation (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).bulkOperation()
}
2 changes: 2 additions & 0 deletions test/sanity-check/api/entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('Entry api Test', () => {
return entry.update({ locale: 'en-at' })
})
.then((entryResponse) => {
jsonWrite(entryResponse, 'publishEntry2.json')
entryUTD = entryResponse.uid
expect(entryResponse.title).to.be.equal('Sample Entry in en-at')
expect(entryResponse.uid).to.be.not.equal(null)
Expand Down Expand Up @@ -182,6 +183,7 @@ describe('Entry api Test', () => {
entry: path.join(__dirname, '../mock/entry.json')
})
.then((response) => {
jsonWrite(response, 'publishEntry1.json')
expect(response.uid).to.be.not.equal(null)
done()
})
Expand Down
4 changes: 2 additions & 2 deletions test/sanity-check/api/user-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { contentstackClient } from '../../utility/ContentstackClient'
import { jsonWrite } from '../../utility/fileOperations/readwrite'
import { contentstackClient } from '../../sanity-check/utility/ContentstackClient'
import { jsonWrite } from '../../sanity-check/utility/fileOperations/readwrite'
import axios from 'axios'
import dotenv from 'dotenv'

Expand Down
1 change: 1 addition & 0 deletions test/sanity-check/sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require('./api/contentType-test')
require('./api/asset-test')
require('./api/extension-test')
require('./api/entry-test')
require('./api/bulkOperation-test')
require('./api/webhook-test')
require('./api/workflow-test')
require('./api/globalfield-test')
Expand Down
2 changes: 1 addition & 1 deletion test/sanity-check/utility/fileOperations/readwrite.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
const dataFiles = './test/utility/dataFiles/'
const dataFiles = './test/sanity-check/utility/dataFiles/'
export function jsonReader (fileName) {
if (!fs.existsSync(`${dataFiles}${fileName}`)) {
return
Expand Down
Loading