Skip to content

Commit

Permalink
test: sanity test for bulk operation
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Mar 22, 2024
1 parent 5380a43 commit b52229f
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 5 deletions.
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

0 comments on commit b52229f

Please sign in to comment.