From b52229f689570a2c1dc1a1156a6dcf9fad7d1e05 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 22 Mar 2024 11:21:58 +0530 Subject: [PATCH] test: sanity test for bulk operation --- sanity-report.mjs | 2 +- test/sanity-check/api/asset-test.js | 4 +- test/sanity-check/api/bulkOperation-test.js | 121 ++++++++++++++++++ test/sanity-check/api/entry-test.js | 2 + test/sanity-check/api/user-test.js | 4 +- test/sanity-check/sanity.js | 1 + .../utility/fileOperations/readwrite.js | 2 +- 7 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 test/sanity-check/api/bulkOperation-test.js diff --git a/sanity-report.mjs b/sanity-report.mjs index 2014ae87..6a2fe583 100644 --- a/sanity-report.mjs +++ b/sanity-report.mjs @@ -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}* diff --git a/test/sanity-check/api/asset-test.js b/test/sanity-check/api/asset-test.js index 70d7fbe0..db3e68b4 100644 --- a/test/sanity-check/api/asset-test.js +++ b/test/sanity-check/api/asset-test.js @@ -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 = {} @@ -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) @@ -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) diff --git a/test/sanity-check/api/bulkOperation-test.js b/test/sanity-check/api/bulkOperation-test.js new file mode 100644 index 00000000..afa79406 --- /dev/null +++ b/test/sanity-check/api/bulkOperation-test.js @@ -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() +} diff --git a/test/sanity-check/api/entry-test.js b/test/sanity-check/api/entry-test.js index fc2f02bd..e22da61b 100644 --- a/test/sanity-check/api/entry-test.js +++ b/test/sanity-check/api/entry-test.js @@ -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) @@ -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() }) diff --git a/test/sanity-check/api/user-test.js b/test/sanity-check/api/user-test.js index aa7e21f2..838828cf 100644 --- a/test/sanity-check/api/user-test.js +++ b/test/sanity-check/api/user-test.js @@ -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' diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index bb69aafd..169a91d2 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -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') diff --git a/test/sanity-check/utility/fileOperations/readwrite.js b/test/sanity-check/utility/fileOperations/readwrite.js index c06fe895..b5ae4900 100644 --- a/test/sanity-check/utility/fileOperations/readwrite.js +++ b/test/sanity-check/utility/fileOperations/readwrite.js @@ -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