From 4af8bda5e5ae00fcdd958e5be030609bf3a00aff Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 19 Jan 2024 18:51:31 +0530 Subject: [PATCH 01/16] test: Added locale test suit and delete test suit to sanity folder --- package.json | 5 +- sanity-report.mjs | 31 ++++--- test/sanity-check/api/create-test.js | 0 test/sanity-check/api/delete-test.js | 68 ++++++++++++++ test/sanity-check/api/locale-test.js | 127 +++++++++++++++++++++++++++ test/sanity-check/sanity.js | 2 + 6 files changed, 221 insertions(+), 12 deletions(-) create mode 100644 test/sanity-check/api/create-test.js create mode 100644 test/sanity-check/api/delete-test.js create mode 100644 test/sanity-check/api/locale-test.js diff --git a/package.json b/package.json index 6eede519..d4b6711b 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "buildnativescript": "webpack --config webpack/webpack.nativescript.js --mode production", "buildweb": "webpack --config webpack/webpack.web.js --mode production", "test": "npm run test:api && npm run test:unit", - "test:sanity": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill", - "test:sanity-report": "node sanity-report.mjs", + "test:sanity": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json && marge mochawesome-report/mochawesome.json -f sanity-report.html --inline", + "test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs", "test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill", "test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill", "test:unit:report:json": "BABEL_ENV=test nyc --reporter=clover --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter json --reporter-options output=report.json --require babel-polyfill", @@ -92,6 +92,7 @@ "jest": "^28.1.0", "jsdoc": "^4.0.2", "mocha": "^9.2.2", + "mocha-html-reporter": "^0.0.1", "mochawesome": "^7.1.3", "multiparty": "^4.2.3", "nock": "^10.0.6", diff --git a/sanity-report.mjs b/sanity-report.mjs index 224457ae..2014ae87 100644 --- a/sanity-report.mjs +++ b/sanity-report.mjs @@ -6,29 +6,32 @@ dotenv.config() const mochawesomeJsonOutput = fs.readFileSync('./mochawesome-report/mochawesome.json', 'utf-8') const mochawesomeReport = JSON.parse(mochawesomeJsonOutput) +const report = `./mochawesome-report/sanity-report.html` const totalSuites = mochawesomeReport.stats.suites const totalTests = mochawesomeReport.stats.tests const passedTests = mochawesomeReport.stats.passes const failedTests = mochawesomeReport.stats.failures const pendingTests = mochawesomeReport.stats.pending -const durationInSeconds = mochawesomeReport.stats.duration / 1000 +let durationInSeconds = mochawesomeReport.stats.duration / 1000 +const durationInMinutes = Math.floor(durationInSeconds / 60) +durationInSeconds %= 60 console.log(`Total Suites: ${totalSuites}`) console.log(`Total Tests: ${totalTests}`) console.log(`Passed Tests: ${passedTests}`) console.log(`Failed Tests: ${failedTests}`) console.log(`Pending Tests: ${pendingTests}`) -console.log(`Total Duration: ${durationInSeconds.toFixed(2)} seconds`) +console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`) const slackMessage = ` *Test Summary* -Total Suites: ${totalSuites} -Total Tests: ${totalTests} -Passed Tests: ${passedTests} -Failed Tests: ${failedTests} -Pending Tests: ${pendingTests} -Total Duration: ${durationInSeconds.toFixed(2)} seconds +• Total Suites: *${totalSuites}* +• Total Tests: *${totalTests}* +• Passed Tests: *${passedTests}* +• Failed Tests: *${failedTests}* +• Pending Tests: *${pendingTests}* +• Total Duration: *${durationInMinutes}m ${durationInSeconds.toFixed(2)}s* ` const app = new Slack.App({ @@ -36,12 +39,20 @@ const app = new Slack.App({ signingSecret: process.env.SLACK_SIGNING_SECRET }) -async function publishMessage (text) { +async function publishMessage (text, report) { await app.client.chat.postMessage({ token: process.env.SLACK_BOT_TOKEN, channel: process.env.SLACK_CHANNEL, text: text }) + await app.client.files.upload({ + token: process.env.SLACK_BOT_TOKEN, + channels: process.env.SLACK_CHANNEL, + initial_comment: '*Here is the report generated*', + filetype: 'html', + filename: 'sanity-report.html', + file: fs.createReadStream(report) + }) } -publishMessage(slackMessage) +publishMessage(slackMessage, report) diff --git a/test/sanity-check/api/create-test.js b/test/sanity-check/api/create-test.js new file mode 100644 index 00000000..e69de29b diff --git a/test/sanity-check/api/delete-test.js b/test/sanity-check/api/delete-test.js new file mode 100644 index 00000000..de5f8739 --- /dev/null +++ b/test/sanity-check/api/delete-test.js @@ -0,0 +1,68 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite' +import { environmentCreate, environmentProdCreate } from '../mock/environment.js' +import { contentstackClient } from '../utility/ContentstackClient.js' + +let client = {} + +describe('Delete Environment api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + it('should delete an environment', done => { + makeEnvironment(environmentCreate.environment.name) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Environment deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete the prod environment', done => { + makeEnvironment(environmentProdCreate.environment.name) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Environment deleted successfully.') + done() + }) + .catch(done) + }) +}) + +describe('Delete Locale api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should delete language: Hindi - India', done => { + makeLocale('hi-in') + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Language removed successfully.') + done() + }) + .catch(done) + }) + + it('should delete language: English - Austria', done => { + makeLocale('en-at') + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Language removed successfully.') + done() + }) + .catch(done) + }) +}) + +function makeEnvironment (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).environment(uid) +} + +function makeLocale (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).locale(uid) +} diff --git a/test/sanity-check/api/locale-test.js b/test/sanity-check/api/locale-test.js new file mode 100644 index 00000000..913a5188 --- /dev/null +++ b/test/sanity-check/api/locale-test.js @@ -0,0 +1,127 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite' +import { contentstackClient } from '../utility/ContentstackClient.js' + +let client = {} + +describe('Locale api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should add a language English - Austria', done => { + makeLocale() + .create({ locale: { code: 'en-at' } }) + .then((locale) => { + expect(locale.code).to.be.equal('en-at') + expect(locale.name).to.be.equal('English - Austria') + expect(locale.fallback_locale).to.be.equal('en-us') + expect(locale.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should add a language Hindi - India', done => { + makeLocale() + .create({ locale: { code: 'hi-in' } }) + .then((locale) => { + expect(locale.code).to.be.equal('hi-in') + expect(locale.name).to.be.equal('Hindi - India') + expect(locale.fallback_locale).to.be.equal('en-us') + expect(locale.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should add a language Marathi - India with Fallback en-at', done => { + makeLocale() + .create({ locale: { code: 'mr-in', fallback_locale: 'en-at' } }) + .then((locale) => { + expect(locale.code).to.be.equal('mr-in') + expect(locale.name).to.be.equal('Marathi - India') + expect(locale.fallback_locale).to.be.equal('en-at') + expect(locale.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should get a all languages', done => { + makeLocale() + .query() + .find() + .then((locales) => { + locales.items.forEach((locale) => { + expect(locale.code).to.be.not.equal(null) + expect(locale.name).to.be.not.equal(null) + expect(locale.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should query a language Hindi - India', done => { + makeLocale() + .query({ query: { name: 'Hindi - India' } }) + .find() + .then((locales) => { + locales.items.forEach((locale) => { + expect(locale.code).to.be.equal('hi-in') + expect(locale.name).to.be.equal('Hindi - India') + expect(locale.fallback_locale).to.be.equal('en-us') + expect(locale.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should get a language Hindi - India', done => { + makeLocale('hi-in') + .fetch() + .then((locale) => { + expect(locale.code).to.be.equal('hi-in') + expect(locale.name).to.be.equal('Hindi - India') + expect(locale.fallback_locale).to.be.equal('en-us') + expect(locale.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should get and update a language Hindi - India', done => { + makeLocale('hi-in') + .fetch() + .then((locale) => { + locale.fallback_locale = 'en-at' + return locale.update() + }) + .then((locale) => { + expect(locale.code).to.be.equal('hi-in') + expect(locale.name).to.be.equal('Hindi - India') + expect(locale.fallback_locale).to.be.equal('en-at') + expect(locale.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should delete language: Hindi - India', done => { + makeLocale('mr-in') + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Language removed successfully.') + done() + }) + .catch(done) + }) +}) + +function makeLocale (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).locale(uid) +} diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index 960b4567..13843af7 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -1,6 +1,7 @@ require('./api/user-test') require('./api/organization-test') require('./api/stack-test') +require('./api/locale-test') require('./api/environment-test') require('./api/contentType-test') require('./api/asset-test') @@ -10,3 +11,4 @@ require('./api/branchAlias-test') require('./api/contentType-delete-test') require('./api/taxonomy-test') require('./api/terms-test') +require('./api/delete-test') From 564d77c081dc5f8f513d4d9b65a5e75d2a5767f3 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Fri, 19 Jan 2024 19:03:20 +0530 Subject: [PATCH 02/16] chore: updated package-lock file --- package-lock.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/package-lock.json b/package-lock.json index 4c8de3e7..e723019e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,6 +45,7 @@ "jest": "^28.1.0", "jsdoc": "^4.0.2", "mocha": "^9.2.2", + "mocha-html-reporter": "^0.0.1", "mochawesome": "^7.1.3", "multiparty": "^4.2.3", "nock": "^10.0.6", @@ -10213,6 +10214,15 @@ "url": "https://opencollective.com/mochajs" } }, + "node_modules/mocha-html-reporter": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mocha-html-reporter/-/mocha-html-reporter-0.0.1.tgz", + "integrity": "sha512-AqkAOBOm5/V9arNsb69H+5NhFKM8w/M00882czB9S07dc/eWhodBuGUcp6ZbZBapKZ+OY8YVv7+aAIWUuSeEoQ==", + "dev": true, + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/mocha/node_modules/cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", @@ -21441,6 +21451,12 @@ } } }, + "mocha-html-reporter": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/mocha-html-reporter/-/mocha-html-reporter-0.0.1.tgz", + "integrity": "sha512-AqkAOBOm5/V9arNsb69H+5NhFKM8w/M00882czB9S07dc/eWhodBuGUcp6ZbZBapKZ+OY8YVv7+aAIWUuSeEoQ==", + "dev": true + }, "mochawesome": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/mochawesome/-/mochawesome-7.1.3.tgz", From cb20b8b73ac30e554486c317523e028cb11f6fff Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 22 Jan 2024 17:30:42 +0530 Subject: [PATCH 03/16] Added taxonomy import/export support (#112) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> --- CHANGELOG.md | 10 +++-- README.md | 2 +- lib/stack/taxonomy/index.js | 82 ++++++++++++++++++++++++++++++++++++- package.json | 2 +- 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23923286..02ac5b48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Changelog -## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13) - - Fixes - - Fix for issue while updating entries with assets - +## [v1.15.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.0) (2024-01-23) + - Feature + - Taxonomy Import/Export feature added ## [v1.14.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.0) (2023-12-19) - Feature - Management token feature added +## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13) + - Fixes + - Fix for issue while updating entries with assets ## [v1.13.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.0) (2023-11-21) - Feature - Teams API support diff --git a/README.md b/README.md index 1296e588..432838fb 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset }) - [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api) ### The MIT License (MIT) -Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved +Copyright © 2012-2024 [Contentstack](https://www.contentstack.com/). All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/lib/stack/taxonomy/index.js b/lib/stack/taxonomy/index.js index b9d03df5..ccac2296 100644 --- a/lib/stack/taxonomy/index.js +++ b/lib/stack/taxonomy/index.js @@ -5,9 +5,14 @@ import { fetch, query, update, - deleteEntity + deleteEntity, + upload, + parseData } from '../../entity' import { Terms, TermsCollection } from './terms' +import FormData from 'form-data' +import { createReadStream } from 'fs' +import error from '../../core/contentstackError' export function Taxonomy (http, data = {}) { this.stackHeaders = data.stackHeaders @@ -69,6 +74,36 @@ export function Taxonomy (http, data = {}) { */ this.fetch = fetch(http, 'taxonomy') + /** + * @description The Export taxonomy call is used to export an existing taxonomy. + * @memberof Taxonomy + * @func export + * @returns {Promise} Promise for Taxonomy instance + * @example + * import * as contentstack from '@contentstack/management' + * const client = contentstack.client() + * + * client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').export() + * .then((taxonomy) => console.log(taxonomy)) + * + */ + this.export = async () => { + try { + const headers = { + headers: { ...cloneDeep(this.stackHeaders) } + } + const response = await http.get(`${this.urlPath}/export`, headers) + if (response.data) { + return response.data + } else { + throw error(response) + } + } catch (err) { + throw error(err) + } + } + + this.terms = (uid = '') => { const data = { stackHeaders: this.stackHeaders } data.taxonomy_uid = this.uid @@ -113,6 +148,42 @@ export function Taxonomy (http, data = {}) { * .then((taxonomies) => console.log(taxonomies) */ this.query = query({ http: http, wrapperCollection: TaxonomyCollection }) + + /** + * @description The 'Import taxonomy' import a single entry by uploading JSON or CSV files. + * @memberof Taxonomy + * @func import + * @param {String} data.taxonomy path to file + * @example + * import * as contentstack from '@contentstack/management' + * const client = contentstack.client() + * + * const data = { + * taxonomy: 'path/to/file.json', + * } + * // Import a Taxonomy + * client.stack({ api_key: 'api_key'}).taxonomy().import(data) + * .then((taxonomy) => console.log(taxonomy)) + */ + this.import = async function (data, params = {}) { + try { + const response = await upload({ + http: http, + urlPath: `${this.urlPath}/import`, + stackHeaders: this.stackHeaders, + formData: createFormData(data), + params: params + }) + if (response.data) { + return new this.constructor(http, parseData(response, this.stackHeaders)) + } else { + throw error(response) + } + } catch (err) { + throw error(err) + } + } + } } export function TaxonomyCollection (http, data) { @@ -122,3 +193,12 @@ export function TaxonomyCollection (http, data) { }) return taxonomyCollection } + +export function createFormData (data) { + return () => { + const formData = new FormData() + const uploadStream = createReadStream(data.taxonomy) + formData.append('taxonomy', uploadStream) + return formData + } +} \ No newline at end of file diff --git a/package.json b/package.json index d4b6711b..83438772 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.14.1", + "version": "1.15.0", "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", From 9c873d8d1afad20348ca2b6d930d478587ebd8c6 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 22 Jan 2024 17:37:19 +0530 Subject: [PATCH 04/16] Validating the object when update the entries with assets (#114) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> --- CHANGELOG.md | 3 +++ lib/entity.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02ac5b48..d28b6df0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [v1.15.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.0) (2024-01-23) - Feature - Taxonomy Import/Export feature added +## [v1.14.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.1) (2024-11-23) + - Fixes + - Fix for validating the data while updating entries with assets ## [v1.14.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.0) (2023-12-19) - Feature - Management token feature added diff --git a/lib/entity.js b/lib/entity.js index 268d930d..c81776ba 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -317,7 +317,7 @@ function isAsset (data) { } export function cleanAssets (data) { - if (typeof data === "object" && Object.keys(data).length > 0) { + if (data && typeof data === "object" && Object.keys(data).length > 0) { const keys = Object.keys(data); for (const key of keys) { if (typeof data[key] === "object" && Object.keys(data[key]).length > 0) { From 698f788489135bd09cbb2a94e44a80c9dff5e13c Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Tue, 23 Jan 2024 13:10:08 +0530 Subject: [PATCH 05/16] test: added delivery token test sanity folder --- package.json | 3 +- test/sanity-check/api/branchAlias-test.js | 23 ---- test/sanity-check/api/delete-test.js | 72 +++++++++- test/sanity-check/api/deliveryToken-test.js | 143 ++++++++++++++++++++ test/sanity-check/mock/deliveryToken.js | 74 ++++++++++ test/sanity-check/sanity.js | 5 +- 6 files changed, 293 insertions(+), 27 deletions(-) create mode 100644 test/sanity-check/api/deliveryToken-test.js create mode 100644 test/sanity-check/mock/deliveryToken.js diff --git a/package.json b/package.json index 83438772..bc59c6f6 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "buildnativescript": "webpack --config webpack/webpack.nativescript.js --mode production", "buildweb": "webpack --config webpack/webpack.web.js --mode production", "test": "npm run test:api && npm run test:unit", - "test:sanity": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json && marge mochawesome-report/mochawesome.json -f sanity-report.html --inline", + "test:sanity-test": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json && marge mochawesome-report/mochawesome.json -f sanity-report.html --inline", + "test:sanity": "npm run test:sanity-test || true", "test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs", "test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill", "test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill", diff --git a/test/sanity-check/api/branchAlias-test.js b/test/sanity-check/api/branchAlias-test.js index 41aa4b78..3451a3ed 100644 --- a/test/sanity-check/api/branchAlias-test.js +++ b/test/sanity-check/api/branchAlias-test.js @@ -55,29 +55,6 @@ describe('Branch Alias api Test', () => { }) .catch(done) }) - - it('Should delete Branch Alias', done => { - try { - makeBranchAlias(`${stageBranch.uid}_alias`) - .delete() - .then((response) => { - expect(response.notice).to.be.equal('Branch alias deleted successfully.') - done() - }) - .catch(done) - } catch (e) { - done() - } - }) - it('Should delete stage branch from uid', done => { - client.stack({ api_key: process.env.API_KEY }).branch(stageBranch.uid) - .delete() - .then((response) => { - expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.') - done() - }) - .catch(done) - }) }) function makeBranchAlias (uid = null) { diff --git a/test/sanity-check/api/delete-test.js b/test/sanity-check/api/delete-test.js index de5f8739..3db3563b 100644 --- a/test/sanity-check/api/delete-test.js +++ b/test/sanity-check/api/delete-test.js @@ -1,9 +1,13 @@ import { expect } from 'chai' import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite' -import { environmentCreate, environmentProdCreate } from '../mock/environment.js' import { contentstackClient } from '../utility/ContentstackClient.js' +import { environmentCreate, environmentProdCreate } from '../mock/environment.js' +import { stageBranch } from '../mock/branch.js' +import { createDeliveryToken } from '../mock/deliveryToken.js' +import dotenv from 'dotenv' +dotenv.config() let client = {} describe('Delete Environment api Test', () => { @@ -59,6 +63,64 @@ describe('Delete Locale api Test', () => { }) }) +describe('Delivery Token delete api Test', () => { + let tokenUID = '' + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should get token uid by name for deleting that token', done => { + makeDeliveryToken() + .query({ query: { name: createDeliveryToken.token.name } }) + .find() + .then((tokens) => { + tokens.items.forEach((token) => { + tokenUID = token.uid + }) + done() + }) + .catch(done) + }) + it('should delete Delivery token from uid', done => { + makeDeliveryToken(tokenUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Delivery Token deleted successfully.') + done() + }) + .catch(done) + }) +}) + +describe('Branch Alias delete api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + it('Should delete Branch Alias', done => { + try { + makeBranchAlias(`${stageBranch.uid}_alias`) + .delete() + .then((response) => { + expect(response.notice).to.be.equal('Branch alias deleted successfully.') + done() + }) + .catch(done) + } catch (e) { + done() + } + }) + it('Should delete stage branch from uid', done => { + client.stack({ api_key: process.env.API_KEY }).branch(stageBranch.uid) + .delete() + .then((response) => { + expect(response.notice).to.be.equal('Your request to delete branch is in progress. Please check organization bulk task queue for more details.') + done() + }) + .catch(done) + }) +}) function makeEnvironment (uid = null) { return client.stack({ api_key: process.env.API_KEY }).environment(uid) } @@ -66,3 +128,11 @@ function makeEnvironment (uid = null) { function makeLocale (uid = null) { return client.stack({ api_key: process.env.API_KEY }).locale(uid) } + +function makeDeliveryToken (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid) +} + +function makeBranchAlias (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid) +} diff --git a/test/sanity-check/api/deliveryToken-test.js b/test/sanity-check/api/deliveryToken-test.js new file mode 100644 index 00000000..98d6a233 --- /dev/null +++ b/test/sanity-check/api/deliveryToken-test.js @@ -0,0 +1,143 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite' +import { createDeliveryToken, createDeliveryToken2 } from '../mock/deliveryToken.js' +import { contentstackClient } from '../utility/ContentstackClient.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} + +let tokenUID = '' +describe('Delivery Token api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should add a Delivery Token for development', done => { + makeDeliveryToken() + .create(createDeliveryToken) + .then((token) => { + expect(token.name).to.be.equal(createDeliveryToken.token.name) + expect(token.description).to.be.equal(createDeliveryToken.token.description) + expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0]) + expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should add a Delivery Token for production', done => { + makeDeliveryToken() + .create(createDeliveryToken2) + .then((token) => { + tokenUID = token.uid + expect(token.name).to.be.equal(createDeliveryToken2.token.name) + expect(token.description).to.be.equal(createDeliveryToken2.token.description) + expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) + expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should get a Delivery Token from uid', done => { + makeDeliveryToken(tokenUID) + .fetch() + .then((token) => { + expect(token.name).to.be.equal(createDeliveryToken2.token.name) + expect(token.description).to.be.equal(createDeliveryToken2.token.description) + expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) + expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should query to get all Delivery Token', done => { + makeDeliveryToken() + .query() + .find() + .then((tokens) => { + tokens.items.forEach((token) => { + expect(token.name).to.be.not.equal(null) + expect(token.description).to.be.not.equal(null) + expect(token.scope[0].environments[0].name).to.be.not.equal(null) + expect(token.scope[0].module).to.be.not.equal(null) + expect(token.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should query to get a Delivery Token from name', done => { + makeDeliveryToken() + .query({ query: { name: createDeliveryToken.token.name } }) + .find() + .then((tokens) => { + tokens.items.forEach((token) => { + expect(token.name).to.be.equal(createDeliveryToken.token.name) + expect(token.description).to.be.equal(createDeliveryToken.token.description) + expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0]) + expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should fetch and update a Delivery Token from uid', done => { + makeDeliveryToken(tokenUID) + .fetch() + .then((token) => { + token.name = 'Update Production Name' + token.description = 'Update Production description' + token.scope = createDeliveryToken2.token.scope + return token.update() + }) + .then((token) => { + expect(token.name).to.be.equal('Update Production Name') + expect(token.description).to.be.equal('Update Production description') + expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) + expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should update a Delivery Token from uid', done => { + const token = makeDeliveryToken(tokenUID) + Object.assign(token, createDeliveryToken2.token) + token.update() + .then((token) => { + expect(token.name).to.be.equal(createDeliveryToken2.token.name) + expect(token.description).to.be.equal(createDeliveryToken2.token.description) + expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) + expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should delete a Delivery Token from uid', done => { + makeDeliveryToken(tokenUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Delivery Token deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeDeliveryToken (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid) +} diff --git a/test/sanity-check/mock/deliveryToken.js b/test/sanity-check/mock/deliveryToken.js new file mode 100644 index 00000000..f04f9c9c --- /dev/null +++ b/test/sanity-check/mock/deliveryToken.js @@ -0,0 +1,74 @@ +const createDeliveryToken = { + token: { + name: 'development test', + description: 'This is a demo token.', + scope: [ + { + module: 'environment', + environments: [ + 'development' + ], + acl: { + read: true + } + }, + { + module: 'branch', + branches: [ + 'main', + 'staging' + ], + acl: { + read: true + } + }, + { + module: 'branch_alias', + branch_aliases: [ + 'staging_alias' + ], + acl: { + read: true + } + } + ] + } +} +const createDeliveryToken2 = { + token: { + name: 'production test', + description: 'This is a demo token.', + scope: [ + { + module: 'environment', + environments: [ + 'production' + ], + acl: { + read: true + } + }, + { + module: 'branch', + branches: [ + 'main', + 'staging' + ], + acl: { + read: true + } + }, + { + module: 'branch_alias', + branch_aliases: [ + 'staging_alias' + ], + acl: { + read: true + } + } + ] + } +} + +export { createDeliveryToken, createDeliveryToken2 } diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index 13843af7..b61130f8 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -3,11 +3,12 @@ require('./api/organization-test') require('./api/stack-test') require('./api/locale-test') require('./api/environment-test') +require('./api/branch-test') +require('./api/branchAlias-test') +require('./api/deliveryToken-test') require('./api/contentType-test') require('./api/asset-test') require('./api/entry-test') -require('./api/branch-test') -require('./api/branchAlias-test') require('./api/contentType-delete-test') require('./api/taxonomy-test') require('./api/terms-test') From 497ce9cbf891fd29ca7e16a644f34d74e9285297 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 24 Jan 2024 11:29:40 +0530 Subject: [PATCH 06/16] test: added extension test suit to sanity --- test/sanity-check/api/extension-test.js | 389 ++++++++++++++++++++++++ test/sanity-check/mock/extension.js | 91 ++++++ test/sanity-check/sanity.js | 1 + 3 files changed, 481 insertions(+) create mode 100644 test/sanity-check/api/extension-test.js create mode 100644 test/sanity-check/mock/extension.js diff --git a/test/sanity-check/api/extension-test.js b/test/sanity-check/api/extension-test.js new file mode 100644 index 00000000..f6690c81 --- /dev/null +++ b/test/sanity-check/api/extension-test.js @@ -0,0 +1,389 @@ +import path from 'path' +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite' +import { customFieldURL, customFieldSRC, customWidgetURL, customWidgetSRC, customDashboardURL, customDashboardSRC } from '../mock/extension' +import { contentstackClient } from '../utility/ContentstackClient.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} + +let customFieldUID = '' +let customWidgetUID = '' +let customDashboardUID = '' +let customFieldSrcUID = '' +let customWidgetSrcUID = '' +let customDashboardSrcUID = '' +let customFieldUploadUID = '' +let customWidgetUploadUID = '' +let customDashboardUploadUID = '' + +describe('Extension api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + it('Create Custom field with source URL', done => { + makeExtension() + .create(customFieldURL) + .then((extension) => { + expect(extension.uid).to.be.not.equal(null) + customFieldUID = extension.uid + expect(extension.title).to.be.equal(customFieldURL.extension.title) + expect(extension.src).to.be.equal(customFieldURL.extension.src) + expect(extension.type).to.be.equal(customFieldURL.extension.type) + expect(extension.tag).to.be.equal(customFieldURL.extension.tag) + done() + }) + .catch(done) + }) + + it('Create Custom field with source Code', done => { + makeExtension() + .create(customFieldSRC) + .then((extension) => { + customFieldSrcUID = extension.uid + expect(extension.uid).to.be.not.equal(null) + expect(extension.title).to.be.equal(customFieldSRC.extension.title) + expect(extension.src).to.be.equal(customFieldSRC.extension.src) + expect(extension.type).to.be.equal(customFieldSRC.extension.type) + expect(extension.tag).to.be.equal(customFieldSRC.extension.tag) + done() + }) + .catch(done) + }) + + it('Create Custom widget with source URL', done => { + makeExtension() + .create(customWidgetURL) + .then((extension) => { + expect(extension.uid).to.be.not.equal(null) + customWidgetUID = extension.uid + expect(extension.title).to.be.equal(customWidgetURL.extension.title) + expect(extension.src).to.be.equal(customWidgetURL.extension.src) + expect(extension.type).to.be.equal(customWidgetURL.extension.type) + expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) + done() + }) + .catch(done) + }) + + it('Create Custom widget with source Code', done => { + makeExtension() + .create(customWidgetSRC) + .then((extension) => { + customWidgetSrcUID = extension.uid + expect(extension.uid).to.be.not.equal(null) + expect(extension.title).to.be.equal(customWidgetSRC.extension.title) + expect(extension.src).to.be.equal(customWidgetSRC.extension.src) + expect(extension.type).to.be.equal(customWidgetSRC.extension.type) + expect(extension.tag).to.be.equal(customWidgetSRC.extension.tag) + done() + }) + .catch(done) + }) + + it('Create Custom dashboard with source URL', done => { + makeExtension() + .create(customDashboardURL) + .then((extension) => { + expect(extension.uid).to.be.not.equal(null) + customDashboardUID = extension.uid + expect(extension.title).to.be.equal(customDashboardURL.extension.title) + expect(extension.src).to.be.equal(customDashboardURL.extension.src) + expect(extension.type).to.be.equal(customDashboardURL.extension.type) + expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) + done() + }) + .catch(done) + }) + + it('Create Custom dashboard with source Code', done => { + makeExtension() + .create(customDashboardSRC) + .then((extension) => { + customDashboardSrcUID = extension.uid + expect(extension.uid).to.be.not.equal(null) + expect(extension.title).to.be.equal(customDashboardSRC.extension.title) + expect(extension.src).to.be.equal(customDashboardSRC.extension.src) + expect(extension.type).to.be.equal(customDashboardSRC.extension.type) + expect(extension.tag).to.be.equal(customDashboardSRC.extension.tag) + done() + }) + .catch(done) + }) + + it('fetch and Update Custom fields', done => { + makeExtension(customFieldUID) + .fetch() + .then((extension) => { + expect(extension.title).to.be.equal(customFieldURL.extension.title) + expect(extension.src).to.be.equal(customFieldURL.extension.src) + expect(extension.type).to.be.equal(customFieldURL.extension.type) + expect(extension.tag).to.be.equal(customFieldURL.extension.tag) + extension.title = 'Old field' + return extension.update() + }) + .then((extension) => { + expect(extension.uid).to.be.equal(customFieldUID) + expect(extension.title).to.be.equal('Old field') + expect(extension.src).to.be.equal(customFieldURL.extension.src) + expect(extension.type).to.be.equal(customFieldURL.extension.type) + expect(extension.tag).to.be.equal(customFieldURL.extension.tag) + done() + }) + .catch(done) + }) + + it('fetch and Update Custom Widget', done => { + makeExtension(customWidgetUID) + .fetch() + .then((extension) => { + expect(extension.title).to.be.equal(customWidgetURL.extension.title) + expect(extension.src).to.be.equal(customWidgetURL.extension.src) + expect(extension.type).to.be.equal(customWidgetURL.extension.type) + expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) + extension.title = 'Old widget' + return extension.update() + }) + .then((extension) => { + expect(extension.uid).to.be.equal(customWidgetUID) + expect(extension.title).to.be.equal('Old widget') + expect(extension.src).to.be.equal(customWidgetURL.extension.src) + expect(extension.type).to.be.equal(customWidgetURL.extension.type) + expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) + done() + }) + .catch(done) + }) + + it('fetch and Update Custom dashboard', done => { + makeExtension(customDashboardUID) + .fetch() + .then((extension) => { + expect(extension.title).to.be.equal(customDashboardURL.extension.title) + expect(extension.src).to.be.equal(customDashboardURL.extension.src) + expect(extension.type).to.be.equal(customDashboardURL.extension.type) + expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) + extension.title = 'Old dashboard' + return extension.update() + }) + .then((extension) => { + expect(extension.uid).to.be.equal(customDashboardUID) + expect(extension.title).to.be.equal('Old dashboard') + expect(extension.src).to.be.equal(customDashboardURL.extension.src) + expect(extension.type).to.be.equal(customDashboardURL.extension.type) + expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) + done() + }) + .catch(done) + }) + + it('Query Custom field', done => { + makeExtension() + .query({ query: { type: 'field' } }) + .find() + .then((extensions) => { + extensions.items.forEach(extension => { + expect(extension.uid).to.be.not.equal(null) + expect(extension.title).to.be.not.equal(null) + expect(extension.type).to.be.equal('field') + }) + done() + }) + .catch(done) + }) + + it('Query Custom widget', done => { + makeExtension() + .query({ query: { type: 'widget' } }) + .find() + .then((extensions) => { + extensions.items.forEach(extension => { + expect(extension.uid).to.be.not.equal(null) + expect(extension.title).to.be.not.equal(null) + expect(extension.type).to.be.equal('widget') + }) + done() + }) + .catch(done) + }) + + it('Query Custom dashboard', done => { + makeExtension() + .query({ query: { type: 'dashboard' } }) + .find() + .then((extensions) => { + extensions.items.forEach(extension => { + expect(extension.uid).to.be.not.equal(null) + expect(extension.title).to.be.not.equal(null) + expect(extension.type).to.be.equal('dashboard') + }) + done() + }) + .catch(done) + }) + + it('Upload Custom field', done => { + makeExtension() + .upload({ + title: 'Custom field Upload', + data_type: customFieldURL.extension.data_type, + type: customFieldURL.extension.type, + tags: customFieldURL.extension.tags, + multiple: customFieldURL.extension.multiple, + upload: path.join(__dirname, '../mock/customUpload.html') + }) + .then((extension) => { + customFieldUploadUID = extension.uid + expect(extension.uid).to.be.not.equal(null) + expect(extension.title).to.be.equal('Custom field Upload') + expect(extension.data_type).to.be.equal(customFieldURL.extension.data_type) + expect(extension.type).to.be.equal(customFieldURL.extension.type) + expect(extension.tag).to.be.equal(customFieldURL.extension.tag) + done() + }) + .catch(done) + }) + + it('Upload Custom widget', done => { + makeExtension() + .upload({ + title: 'Custom widget Upload', + data_type: customWidgetURL.extension.data_type, + type: customWidgetURL.extension.type, + scope: customWidgetURL.extension.scope, + tags: customWidgetURL.extension.tags.join(','), + upload: path.join(__dirname, '../mock/customUpload.html') + }) + .then((extension) => { + expect(extension.uid).to.be.not.equal(null) + customWidgetUploadUID = extension.uid + expect(extension.title).to.be.equal('Custom widget Upload') + expect(extension.type).to.be.equal(customWidgetURL.extension.type) + expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) + done() + }) + .catch(done) + }) + + it('Upload dashboard', done => { + makeExtension() + .upload({ + title: 'Custom dashboard Upload', + data_type: customDashboardURL.extension.data_type, + type: customDashboardURL.extension.type, + tags: customDashboardURL.extension.tags, + enable: customDashboardURL.extension.enable, + default_width: customDashboardURL.extension.default_width, + upload: path.join(__dirname, '../mock/customUpload.html') + }) + .then((extension) => { + expect(extension.uid).to.be.not.equal(null) + customDashboardUploadUID = extension.uid + expect(extension.title).to.be.equal('Custom dashboard Upload') + expect(extension.data_type).to.be.equal(customDashboardURL.extension.data_type) + expect(extension.type).to.be.equal(customDashboardURL.extension.type) + expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) + expect(extension.enable).to.be.equal(customDashboardURL.extension.enable) + expect(extension.default_width).to.be.equal(customDashboardURL.extension.default_width) + done() + }) + .catch(done) + }) + + it('Delete Custom field', done => { + makeExtension(customFieldUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom widget', done => { + makeExtension(customWidgetUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom dashboard', done => { + makeExtension(customDashboardUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom field created from src', done => { + makeExtension(customFieldSrcUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom widget created from src', done => { + makeExtension(customWidgetSrcUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom dashboard created from src', done => { + makeExtension(customDashboardSrcUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom field uploaded', done => { + makeExtension(customFieldUploadUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom widget uploaded', done => { + makeExtension(customWidgetUploadUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) + + it('Delete Custom dashboard uploaded', done => { + makeExtension(customDashboardUploadUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeExtension (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).extension(uid) +} diff --git a/test/sanity-check/mock/extension.js b/test/sanity-check/mock/extension.js new file mode 100644 index 00000000..94b515ad --- /dev/null +++ b/test/sanity-check/mock/extension.js @@ -0,0 +1,91 @@ +const customFieldURL = { + extension: { + tags: [ + 'tag1', + 'tag2' + ], + data_type: 'text', + title: 'New Custom Field URL', + src: 'https://www.sample.com', + multiple: false, + config: '{}', + type: 'field' + } +} +const customFieldSRC = { + extension: { + tags: [ + 'tag1', + 'tag2' + ], + data_type: 'text', + title: 'New Custom Field source code', + srcdoc: 'Source code of the extension', + multiple: false, + config: '{}', + type: 'field' + } +} + +const customWidgetURL = { + extension: { + tags: [ + 'tag1', + 'tag2' + ], + data_type: 'text', + title: 'New Widget URL', + src: 'https://www.sample.com', + config: '{}', + type: 'widget', + scope: { + content_types: ['single_page'] + } + } +} + +const customWidgetSRC = { + extension: { + tags: [ + 'tag1', + 'tag2' + ], + title: 'New Widget SRC', + srcdoc: 'Source code of the widget', + config: '{}', + type: 'widget', + scope: { + content_types: ['single_page'] + } + } +} + +const customDashboardURL = { + extension: { + tags: [ + 'tag' + ], + title: 'New Dashboard Widget URL', + src: 'https://www.sample.com', + config: '{}', + type: 'dashboard', + enable: true, + default_width: 'half' + } +} + +const customDashboardSRC = { + extension: { + tags: [ + 'tag1', + 'tag2' + ], + type: 'dashboard', + title: 'New Dashboard Widget SRC', + srcdoc: 'xyz', + config: '{}', + enable: true, + default_width: 'half' + } +} +export { customFieldURL, customFieldSRC, customWidgetURL, customWidgetSRC, customDashboardURL, customDashboardSRC } diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index b61130f8..74ab6d47 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -8,6 +8,7 @@ require('./api/branchAlias-test') require('./api/deliveryToken-test') require('./api/contentType-test') require('./api/asset-test') +require('./api/extension-test') require('./api/entry-test') require('./api/contentType-delete-test') require('./api/taxonomy-test') From 33651be47c77498f16d01a87e1d4a38ef75d8eed Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 24 Jan 2024 12:06:00 +0530 Subject: [PATCH 07/16] test: updated test msg --- test/sanity-check/api/extension-test.js | 50 ++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/test/sanity-check/api/extension-test.js b/test/sanity-check/api/extension-test.js index f6690c81..3ffc6957 100644 --- a/test/sanity-check/api/extension-test.js +++ b/test/sanity-check/api/extension-test.js @@ -24,7 +24,7 @@ describe('Extension api Test', () => { const user = jsonReader('loggedinuser.json') client = contentstackClient(user.authtoken) }) - it('Create Custom field with source URL', done => { + it('should create Custom field with source URL', done => { makeExtension() .create(customFieldURL) .then((extension) => { @@ -39,7 +39,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Create Custom field with source Code', done => { + it('should create Custom field with source Code', done => { makeExtension() .create(customFieldSRC) .then((extension) => { @@ -54,7 +54,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Create Custom widget with source URL', done => { + it('should create Custom widget with source URL', done => { makeExtension() .create(customWidgetURL) .then((extension) => { @@ -69,7 +69,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Create Custom widget with source Code', done => { + it('should create Custom widget with source Code', done => { makeExtension() .create(customWidgetSRC) .then((extension) => { @@ -84,7 +84,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Create Custom dashboard with source URL', done => { + it('should create Custom dashboard with source URL', done => { makeExtension() .create(customDashboardURL) .then((extension) => { @@ -99,7 +99,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Create Custom dashboard with source Code', done => { + it('should create Custom dashboard with source Code', done => { makeExtension() .create(customDashboardSRC) .then((extension) => { @@ -114,7 +114,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('fetch and Update Custom fields', done => { + it('should fetch and Update Custom fields', done => { makeExtension(customFieldUID) .fetch() .then((extension) => { @@ -136,7 +136,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('fetch and Update Custom Widget', done => { + it('should fetch and Update Custom Widget', done => { makeExtension(customWidgetUID) .fetch() .then((extension) => { @@ -158,7 +158,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('fetch and Update Custom dashboard', done => { + it('should fetch and Update Custom dashboard', done => { makeExtension(customDashboardUID) .fetch() .then((extension) => { @@ -180,7 +180,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Query Custom field', done => { + it('should query Custom field', done => { makeExtension() .query({ query: { type: 'field' } }) .find() @@ -195,7 +195,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Query Custom widget', done => { + it('should query Custom widget', done => { makeExtension() .query({ query: { type: 'widget' } }) .find() @@ -210,7 +210,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Query Custom dashboard', done => { + it('should query Custom dashboard', done => { makeExtension() .query({ query: { type: 'dashboard' } }) .find() @@ -218,14 +218,14 @@ describe('Extension api Test', () => { extensions.items.forEach(extension => { expect(extension.uid).to.be.not.equal(null) expect(extension.title).to.be.not.equal(null) - expect(extension.type).to.be.equal('dashboard') + expect(extension.type).to.be.equal('should dashboard') }) done() }) .catch(done) }) - it('Upload Custom field', done => { + it('should upload Custom field', done => { makeExtension() .upload({ title: 'Custom field Upload', @@ -247,7 +247,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Upload Custom widget', done => { + it('should upload Custom widget', done => { makeExtension() .upload({ title: 'Custom widget Upload', @@ -268,7 +268,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Upload dashboard', done => { + it('should upload dashboard', done => { makeExtension() .upload({ title: 'Custom dashboard Upload', @@ -293,7 +293,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom field', done => { + it('should delete Custom field', done => { makeExtension(customFieldUID) .delete() .then((data) => { @@ -303,7 +303,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom widget', done => { + it('should delete Custom widget', done => { makeExtension(customWidgetUID) .delete() .then((data) => { @@ -313,7 +313,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom dashboard', done => { + it('should delete Custom dashboard', done => { makeExtension(customDashboardUID) .delete() .then((data) => { @@ -323,7 +323,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom field created from src', done => { + it('should delete Custom field created from src', done => { makeExtension(customFieldSrcUID) .delete() .then((data) => { @@ -333,7 +333,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom widget created from src', done => { + it('should delete Custom widget created from src', done => { makeExtension(customWidgetSrcUID) .delete() .then((data) => { @@ -343,7 +343,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom dashboard created from src', done => { + it('should delete Custom dashboard created from src', done => { makeExtension(customDashboardSrcUID) .delete() .then((data) => { @@ -353,7 +353,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom field uploaded', done => { + it('should delete Custom field uploaded', done => { makeExtension(customFieldUploadUID) .delete() .then((data) => { @@ -363,7 +363,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom widget uploaded', done => { + it('should delete Custom widget uploaded', done => { makeExtension(customWidgetUploadUID) .delete() .then((data) => { @@ -373,7 +373,7 @@ describe('Extension api Test', () => { .catch(done) }) - it('Delete Custom dashboard uploaded', done => { + it('should delete Custom dashboard uploaded', done => { makeExtension(customDashboardUploadUID) .delete() .then((data) => { From bb3795c705c70687dd02a927e4561a1a339976ce Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 24 Jan 2024 15:47:18 +0530 Subject: [PATCH 08/16] cleared assertion error --- test/sanity-check/api/extension-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sanity-check/api/extension-test.js b/test/sanity-check/api/extension-test.js index 3ffc6957..93be566a 100644 --- a/test/sanity-check/api/extension-test.js +++ b/test/sanity-check/api/extension-test.js @@ -218,7 +218,7 @@ describe('Extension api Test', () => { extensions.items.forEach(extension => { expect(extension.uid).to.be.not.equal(null) expect(extension.title).to.be.not.equal(null) - expect(extension.type).to.be.equal('should dashboard') + expect(extension.type).to.be.equal('dashboard') }) done() }) From dcbff01410ac5e7537a9658988e63ac26c12401e Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 25 Jan 2024 12:17:29 +0530 Subject: [PATCH 09/16] test: added assertions for failing tests --- test/sanity-check/api/extension-test.js | 129 +++++++++++++++++++++--- 1 file changed, 113 insertions(+), 16 deletions(-) diff --git a/test/sanity-check/api/extension-test.js b/test/sanity-check/api/extension-test.js index 93be566a..250c9c1c 100644 --- a/test/sanity-check/api/extension-test.js +++ b/test/sanity-check/api/extension-test.js @@ -24,6 +24,7 @@ describe('Extension api Test', () => { const user = jsonReader('loggedinuser.json') client = contentstackClient(user.authtoken) }) + it('should create Custom field with source URL', done => { makeExtension() .create(customFieldURL) @@ -51,7 +52,13 @@ describe('Extension api Test', () => { expect(extension.tag).to.be.equal(customFieldSRC.extension.tag) done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(422, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension creation failed. Please try again.', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(344, 'Error code does not match') + done() + }) }) it('should create Custom widget with source URL', done => { @@ -66,7 +73,13 @@ describe('Extension api Test', () => { expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(422, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension creation failed. Please try again.', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(344, 'Error code does not match') + done() + }) }) it('should create Custom widget with source Code', done => { @@ -81,7 +94,13 @@ describe('Extension api Test', () => { expect(extension.tag).to.be.equal(customWidgetSRC.extension.tag) done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(422, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension creation failed. Please try again.', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(344, 'Error code does not match') + done() + }) }) it('should create Custom dashboard with source URL', done => { @@ -96,7 +115,13 @@ describe('Extension api Test', () => { expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(422, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension creation failed. Please try again.', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(344, 'Error code does not match') + done() + }) }) it('should create Custom dashboard with source Code', done => { @@ -133,7 +158,13 @@ describe('Extension api Test', () => { expect(extension.tag).to.be.equal(customFieldURL.extension.tag) done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should fetch and Update Custom Widget', done => { @@ -155,7 +186,13 @@ describe('Extension api Test', () => { expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should fetch and Update Custom dashboard', done => { @@ -177,7 +214,13 @@ describe('Extension api Test', () => { expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should query Custom field', done => { @@ -300,7 +343,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom widget', done => { @@ -310,7 +359,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom dashboard', done => { @@ -320,7 +375,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom field created from src', done => { @@ -330,7 +391,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom widget created from src', done => { @@ -340,7 +407,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom dashboard created from src', done => { @@ -350,7 +423,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom field uploaded', done => { @@ -360,7 +439,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom widget uploaded', done => { @@ -370,7 +455,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) it('should delete Custom dashboard uploaded', done => { @@ -380,7 +471,13 @@ describe('Extension api Test', () => { expect(data.notice).to.be.equal('Extension deleted successfully.') done() }) - .catch(done) + .catch((error) => { + const jsonMessage = JSON.parse(error.message) + expect(jsonMessage.status).to.be.equal(404, 'Status code does not match') + expect(jsonMessage.errorMessage).to.not.equal('Extension was not found', 'Error message not proper') + expect(jsonMessage.errorCode).to.be.equal(347, 'Error code does not match') + done() + }) }) }) From b031839280d3769f23d29bc6eb2976abb0588d30 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:56:10 +0530 Subject: [PATCH 10/16] Feat/cs 43619 taxonomy import export testcases (#118) * Next (#115) * test: Added locale test suit and delete test suit to sanity folder * chore: updated package-lock file * Added taxonomy import/export support (#112) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Validating the object when update the entries with assets (#114) Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> --------- Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> * Added taxonomy import/export testcases. --------- Co-authored-by: Nadeem <110535104+nadeem-cs@users.noreply.github.com> Co-authored-by: harshithad0703 Co-authored-by: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> --- CHANGELOG.md | 3 ++ package.json | 2 +- test/api/mock/taxonomy.json | 8 +++++ test/api/taxonomy-test.js | 25 ++++++++++++++ test/sanity-check/api/delete-test.js | 2 ++ test/unit/mock/objects.js | 7 ++++ test/unit/taxonomy-test.js | 50 ++++++++++++++++++++++++++-- 7 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 test/api/mock/taxonomy.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d28b6df0..9e9f7378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## [v1.15.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.1) (2024-01-29) + - Feature + - Taxonomy Import/Export test cases are added ## [v1.15.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.0) (2024-01-23) - Feature - Taxonomy Import/Export feature added diff --git a/package.json b/package.json index bc59c6f6..ec1c5e7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.15.0", + "version": "1.15.1", "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", diff --git a/test/api/mock/taxonomy.json b/test/api/mock/taxonomy.json new file mode 100644 index 00000000..51df5308 --- /dev/null +++ b/test/api/mock/taxonomy.json @@ -0,0 +1,8 @@ +{ + "taxonomy": { + "uid": "UID", + "name": "name", + "description": "test" + }, + "terms": [] +} \ No newline at end of file diff --git a/test/api/taxonomy-test.js b/test/api/taxonomy-test.js index 968a7025..b8e331a6 100644 --- a/test/api/taxonomy-test.js +++ b/test/api/taxonomy-test.js @@ -1,4 +1,5 @@ import { expect } from 'chai' +import path from 'path' import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite' import { contentstackClient } from '../utility/ContentstackClient.js' @@ -12,6 +13,8 @@ const taxonomy = { description: 'Description for Taxonomy testing' } +const importTaxonomy = { taxonomy: path.join(__dirname, './mock/taxonomy.json') } + var taxonomyUID = '' var taxonomyDelUID = 'taxonomy_testing' @@ -32,6 +35,28 @@ describe('taxonomy api Test', () => { .catch(done) }) + it('Import taxonomy', done => { + makeTaxonomy() + .import(importTaxonomy) + .then((taxonomyResponse) => { + expect(taxonomyResponse.name).to.be.equal("name") + done() + }) + .catch(done) + }) + + it('Export taxonomy', done => { + makeTaxonomy(taxonomyUID) + .export() + .then((taxonomyResponse) => { + expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) + expect(taxonomyResponse.name).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('Fetch taxonomy from uid', done => { makeTaxonomy(taxonomyUID) .fetch() diff --git a/test/sanity-check/api/delete-test.js b/test/sanity-check/api/delete-test.js index 3db3563b..1eb145f7 100644 --- a/test/sanity-check/api/delete-test.js +++ b/test/sanity-check/api/delete-test.js @@ -121,6 +121,7 @@ describe('Branch Alias delete api Test', () => { .catch(done) }) }) + function makeEnvironment (uid = null) { return client.stack({ api_key: process.env.API_KEY }).environment(uid) } @@ -136,3 +137,4 @@ function makeDeliveryToken (uid = null) { function makeBranchAlias (uid = null) { return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid) } + diff --git a/test/unit/mock/objects.js b/test/unit/mock/objects.js index 85f0cc09..5c44bad5 100644 --- a/test/unit/mock/objects.js +++ b/test/unit/mock/objects.js @@ -741,6 +741,12 @@ const auditLogsMock = { ] } +const taxonomyImportMock = { + "uid": "UID", + "name": "name", + "description": "test" +} + const taxonomyMock = { uid: 'UID', name: 'name', @@ -883,6 +889,7 @@ export { auditLogsMock, auditLogItemMock, taxonomyMock, + taxonomyImportMock, termsMock, teamsMock, teamUsersMock, diff --git a/test/unit/taxonomy-test.js b/test/unit/taxonomy-test.js index c5f67190..a20d303a 100644 --- a/test/unit/taxonomy-test.js +++ b/test/unit/taxonomy-test.js @@ -1,9 +1,10 @@ import Axios from 'axios' +import path from 'path' import { expect } from 'chai' import { describe, it } from 'mocha' import MockAdapter from 'axios-mock-adapter' -import { Taxonomy } from '../../lib/stack/taxonomy' -import { systemUidMock, stackHeadersMock, taxonomyMock, noticeMock, termsMock } from './mock/objects' +import { Taxonomy, createFormData, TaxonomyCollection } from '../../lib/stack/taxonomy' +import { systemUidMock, stackHeadersMock, taxonomyMock, noticeMock, termsMock, taxonomyImportMock } from './mock/objects' describe('Contentstack Taxonomy test', () => { it('taxonomy create test', done => { @@ -122,6 +123,51 @@ describe('Contentstack Taxonomy test', () => { done() }) + it('Taxonomy export test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/taxonomies/UID/export').reply(200, { + taxonomy: { + ...taxonomyImportMock + } + }) + makeTaxonomy({ + taxonomy: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .export() + .then((taxonomy) => { + expect(taxonomy['taxonomy']['uid']).to.be.equal('UID') + expect(taxonomy['taxonomy']['name']).to.be.equal('name') + done() + }) + .catch(done) + }) + + it('Taxonomy import test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/taxonomies/import').reply(200, { + taxonomy: { + ...taxonomyMock + } + }) + const taxonomyUpload = { taxonomy: path.join(__dirname, '../api/mock/taxonomy.json') } + const form = createFormData(taxonomyUpload)() + var boundary = form.getBoundary() + + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) + makeTaxonomy() + .import(taxonomyUpload) + .then((taxonomy) => { + checkTaxonomy(taxonomy) + done() + }) + .catch(done) + }) + + it('term create test', done => { var mock = new MockAdapter(Axios) mock.onPost(`/taxonomies/taxonomy_uid/terms`).reply(200, { From e0075bd0d81c7578845f7c8588467516d53095f1 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 25 Jan 2024 16:37:49 +0530 Subject: [PATCH 11/16] test: added global field test suit to sanity --- test/sanity-check/api/globalfield-test.js | 140 ++++++++++++++++++++++ test/sanity-check/mock/globalfield.js | 28 +++++ test/sanity-check/mock/globalfield.json | 34 ++++++ test/sanity-check/sanity.js | 1 + 4 files changed, 203 insertions(+) create mode 100644 test/sanity-check/api/globalfield-test.js create mode 100644 test/sanity-check/mock/globalfield.js create mode 100644 test/sanity-check/mock/globalfield.json diff --git a/test/sanity-check/api/globalfield-test.js b/test/sanity-check/api/globalfield-test.js new file mode 100644 index 00000000..acecd852 --- /dev/null +++ b/test/sanity-check/api/globalfield-test.js @@ -0,0 +1,140 @@ +import path from 'path' +import { expect } from 'chai' +import { cloneDeep } from 'lodash' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite' +import { createGlobalField } from '../mock/globalfield' +import { contentstackClient } from '../utility/ContentstackClient.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} +let createGlobalFieldUid = '' + +describe('Global Field api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should create global field', done => { + makeGlobalField().create(createGlobalField) + .then((globalField) => { + expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid) + expect(globalField.title).to.be.equal(createGlobalField.global_field.title) + expect(globalField.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) + expect(globalField.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) + expect(globalField.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) + done() + }) + .catch(done) + }) + + it('should fetch global Field', done => { + makeGlobalField(createGlobalField.global_field.uid).fetch() + .then((globalField) => { + expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid) + expect(globalField.title).to.be.equal(createGlobalField.global_field.title) + expect(globalField.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) + expect(globalField.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) + expect(globalField.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) + done() + }) + .catch(done) + }) + + it('should fetch and update global Field', done => { + makeGlobalField(createGlobalField.global_field.uid).fetch() + .then((globalField) => { + globalField.title = 'Update title' + return globalField.update() + }) + .then((updateGlobal) => { + expect(updateGlobal.uid).to.be.equal(createGlobalField.global_field.uid) + expect(updateGlobal.title).to.be.equal('Update title') + expect(updateGlobal.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) + expect(updateGlobal.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) + expect(updateGlobal.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) + done() + }) + .catch(done) + }) + + it('should update global Field', done => { + const globalField = makeGlobalField(createGlobalField.global_field.uid) + Object.assign(globalField, cloneDeep(createGlobalField.global_field)) + globalField.update() + .then((updateGlobal) => { + expect(updateGlobal.uid).to.be.equal(createGlobalField.global_field.uid) + expect(updateGlobal.title).to.be.equal(createGlobalField.global_field.title) + expect(updateGlobal.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) + expect(updateGlobal.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) + expect(updateGlobal.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) + done() + }) + .catch(done) + }) + + it('should import global Field', done => { + makeGlobalField().import({ + global_field: path.join(__dirname, '../mock/globalfield.json') + }) + .then((response) => { + createGlobalFieldUid = response.uid + expect(response.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should get all global field from Query', done => { + makeGlobalField().query() + .find() + .then((collection) => { + collection.items.forEach(globalField => { + expect(globalField.uid).to.be.not.equal(null) + expect(globalField.title).to.be.not.equal(null) + expect(globalField.schema).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should get global field title matching Upload', done => { + makeGlobalField().query({ query: { title: 'Upload' } }) + .find() + .then((collection) => { + collection.items.forEach(globalField => { + expect(globalField.uid).to.be.not.equal(null) + expect(globalField.title).to.be.equal('Upload') + }) + done() + }) + .catch(done) + }) + + it('should delete global Field', done => { + makeGlobalField(createGlobalField.global_field.uid) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Global Field deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete imported global Field', done => { + makeGlobalField(createGlobalFieldUid) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Global Field deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeGlobalField (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).globalField(uid) +} diff --git a/test/sanity-check/mock/globalfield.js b/test/sanity-check/mock/globalfield.js new file mode 100644 index 00000000..22f07718 --- /dev/null +++ b/test/sanity-check/mock/globalfield.js @@ -0,0 +1,28 @@ +const createGlobalField = { + global_field: { + title: 'First', + uid: 'first', + schema: [{ + display_name: 'Name', + uid: 'name', + data_type: 'text' + }, { + data_type: 'text', + display_name: 'Rich text editor', + uid: 'description', + field_metadata: { + allow_rich_text: true, + description: '', + multiline: false, + rich_text_type: 'advanced', + options: [], + version: 3 + }, + multiple: false, + mandatory: false, + unique: false + }] + } +} + +export { createGlobalField } diff --git a/test/sanity-check/mock/globalfield.json b/test/sanity-check/mock/globalfield.json new file mode 100644 index 00000000..56b6de61 --- /dev/null +++ b/test/sanity-check/mock/globalfield.json @@ -0,0 +1,34 @@ +{ + "title": "Upload", + "uid": "upload", + "schema": [ + { + "display_name": "Name", + "uid": "name", + "data_type": "text", + "multiple": false, + "mandatory": false, + "unique": false, + "non_localizable": false + }, + { + "display_name": "Add", + "uid": "add", + "data_type": "text", + "multiple": false, + "mandatory": false, + "unique": false, + "non_localizable": false + }, + { + "display_name": "std", + "uid": "std", + "data_type": "text", + "multiple": false, + "mandatory": false, + "unique": false, + "non_localizable": false + } + ], + "description": "" + } \ No newline at end of file diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index 74ab6d47..cebee4d2 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -10,6 +10,7 @@ require('./api/contentType-test') require('./api/asset-test') require('./api/extension-test') require('./api/entry-test') +require('./api/globalfield-test') require('./api/contentType-delete-test') require('./api/taxonomy-test') require('./api/terms-test') From c13e146a6bc00fbe3a9cccda925c69b4462de949 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Mon, 29 Jan 2024 15:01:12 +0530 Subject: [PATCH 12/16] test: add sanity test for label --- .../api/contentType-delete-test.js | 10 ++ test/sanity-check/api/contentType-test.js | 12 -- test/sanity-check/api/delete-test.js | 1 - test/sanity-check/api/label-test.js | 137 ++++++++++++++++++ test/sanity-check/sanity.js | 6 + 5 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 test/sanity-check/api/label-test.js diff --git a/test/sanity-check/api/contentType-delete-test.js b/test/sanity-check/api/contentType-delete-test.js index 148a48ce..2802afb9 100644 --- a/test/sanity-check/api/contentType-delete-test.js +++ b/test/sanity-check/api/contentType-delete-test.js @@ -21,6 +21,16 @@ describe('Content Type delete api Test', () => { makeContentType(singlepageCT.content_type.uid).delete() .catch(done) }) + + it('should delete ContentTypes', done => { + makeContentType('multi_page_from_json') + .delete() + .then((contentType) => { + expect(contentType.notice).to.be.equal('Content Type deleted successfully.') + done() + }) + .catch(done) + }) }) function makeContentType (uid = null) { diff --git a/test/sanity-check/api/contentType-test.js b/test/sanity-check/api/contentType-test.js index fbb99a0a..7de179bd 100644 --- a/test/sanity-check/api/contentType-test.js +++ b/test/sanity-check/api/contentType-test.js @@ -7,7 +7,6 @@ import { contentstackClient } from '../utility/ContentstackClient.js' let client = {} let multiPageCTUid = '' -let importCTUid = '' describe('Content Type api Test', () => { setup(() => { @@ -100,22 +99,11 @@ describe('Content Type api Test', () => { content_type: path.join(__dirname, '../mock/contentType.json') }) .then((response) => { - importCTUid = response.uid expect(response.uid).to.be.not.equal(null) done() }) .catch(done) }) - - it('should delete ContentTypes', done => { - makeContentType(importCTUid) - .delete() - .then((contentType) => { - expect(contentType.notice).to.be.equal('Content Type deleted successfully.') - done() - }) - .catch(done) - }) }) function makeContentType (uid = null) { diff --git a/test/sanity-check/api/delete-test.js b/test/sanity-check/api/delete-test.js index 6775266d..6764a85f 100644 --- a/test/sanity-check/api/delete-test.js +++ b/test/sanity-check/api/delete-test.js @@ -138,4 +138,3 @@ function makeDeliveryToken (uid = null) { function makeBranchAlias (uid = null) { return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid) } - diff --git a/test/sanity-check/api/label-test.js b/test/sanity-check/api/label-test.js new file mode 100644 index 00000000..6e2412eb --- /dev/null +++ b/test/sanity-check/api/label-test.js @@ -0,0 +1,137 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite.js' +import { singlepageCT } from '../mock/content-type.js' +import { contentstackClient } from '../utility/ContentstackClient.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} + +const label = { + name: 'First label', + content_types: [singlepageCT.content_type.uid] +} + +let labelUID = '' +let deleteLabelUID = '' +describe('Label api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should create a Label', done => { + makeLabel() + .create({ label }) + .then((labelResponse) => { + labelUID = labelResponse.uid + expect(labelResponse.uid).to.be.not.equal(null) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should create Label with parent uid', done => { + const label = { + name: 'With Parent label', + parent: [labelUID], + content_types: [singlepageCT.content_type.uid] + } + makeLabel() + .create({ label }) + .then((labelResponse) => { + deleteLabelUID = labelResponse.uid + expect(labelResponse.uid).to.be.not.equal(null) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.parent[0]).to.be.equal(label.parent[0]) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should fetch label from uid', done => { + makeLabel(labelUID) + .fetch() + .then((labelResponse) => { + expect(labelResponse.uid).to.be.equal(labelUID) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should query to get all labels', done => { + makeLabel() + .query({ query: { name: label.name } }) + .find() + .then((response) => { + response.items.forEach((labelResponse) => { + expect(labelResponse.uid).to.be.not.equal(null) + expect(labelResponse.name).to.be.not.equal(null) + expect(labelResponse.content_types).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should query label with name', done => { + makeLabel() + .query({ query: { name: label.name } }) + .find() + .then((response) => { + response.items.forEach((labelResponse) => { + expect(labelResponse.uid).to.be.equal(labelUID) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + }) + done() + }) + .catch(done) + }) + + it('should fetch and update label from uid', done => { + makeLabel(labelUID) + .fetch() + .then((labelResponse) => { + labelResponse.name = 'Update Name' + return labelResponse.update() + }) + .then((labelResponse) => { + expect(labelResponse.uid).to.be.equal(labelUID) + expect(labelResponse.name).to.be.equal('Update Name') + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should delete parent label from uid', done => { + makeLabel(deleteLabelUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Label deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete label from uid', done => { + makeLabel(labelUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Label deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeLabel (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).label(uid) +} diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index cebee4d2..af0acaa7 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -5,12 +5,18 @@ require('./api/locale-test') require('./api/environment-test') require('./api/branch-test') require('./api/branchAlias-test') +// require('./api/role-test') require('./api/deliveryToken-test') +// require('./api/managementToken-test') require('./api/contentType-test') require('./api/asset-test') require('./api/extension-test') require('./api/entry-test') +// require('./api/webhook-test') +// require('./api/workflow-test') require('./api/globalfield-test') +// require('./api/release-test') +require('./api/label-test') require('./api/contentType-delete-test') require('./api/taxonomy-test') require('./api/terms-test') From fcc808451772284e9638cf3acfa93676b73eb4e4 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 31 Jan 2024 15:06:40 +0530 Subject: [PATCH 13/16] test: added sanity test for workflow-webhook-release --- test/sanity-check/api/release-test.js | 239 +++++++++++++++++++++++++ test/sanity-check/api/webhook-test.js | 172 ++++++++++++++++++ test/sanity-check/api/workflow-test.js | 143 +++++++++++++++ test/sanity-check/mock/release.js | 10 ++ test/sanity-check/mock/webhook.js | 40 +++++ test/sanity-check/mock/webhook.json | 17 ++ test/sanity-check/mock/workflow.js | 126 +++++++++++++ 7 files changed, 747 insertions(+) create mode 100644 test/sanity-check/api/release-test.js create mode 100644 test/sanity-check/api/webhook-test.js create mode 100644 test/sanity-check/api/workflow-test.js create mode 100644 test/sanity-check/mock/release.js create mode 100644 test/sanity-check/mock/webhook.js create mode 100644 test/sanity-check/mock/webhook.json create mode 100644 test/sanity-check/mock/workflow.js diff --git a/test/sanity-check/api/release-test.js b/test/sanity-check/api/release-test.js new file mode 100644 index 00000000..20c9c822 --- /dev/null +++ b/test/sanity-check/api/release-test.js @@ -0,0 +1,239 @@ +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite.js' +import { releaseCreate } from '../mock/release.js' +import { expect } from 'chai' +import { cloneDeep } from 'lodash' +import { contentstackClient } from '../utility/ContentstackClient.js' +import { multiPageCT } from '../mock/content-type.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} +let releaseUID = '' +let releaseUID2 = '' +let entries = {} +const itemToDelete = {} + +describe('Relases api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + entries = jsonReader('entry.json') + client = contentstackClient(user.authtoken) + }) + + it('should create a Release', done => { + makeRelease() + .create(releaseCreate) + .then((release) => { + releaseUID = release.uid + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should fetch a Release from Uid', done => { + makeRelease(releaseUID) + .fetch() + .then((release) => { + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.equal(releaseUID) + done() + }) + .catch(done) + }) + + it('should create release item', done => { + const item = { + version: entries[0]._version, + uid: entries[0].uid, + content_type_uid: multiPageCT.content_type.uid, + action: 'publish', + locale: 'en-us' + } + makeRelease(releaseUID) + .item() + .create({ item }) + .then((release) => { + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.equal(releaseUID) + expect(release.items.length).to.be.equal(1) + done() + }) + .catch(done) + }) + + it('should create release items', done => { + const items = [ + { + version: entries[1]._version, + uid: entries[1].uid, + content_type_uid: multiPageCT.content_type.uid, + action: 'publish', + locale: 'en-us' + }, + { + version: entries[2]._version, + uid: entries[2].uid, + content_type_uid: multiPageCT.content_type.uid, + action: 'publish', + locale: 'en-us' + } + ] + makeRelease(releaseUID) + .item() + .create({ items }) + .then((release) => { + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.equal(releaseUID) + expect(release.items.length).to.be.equal(3) + done() + }) + .catch(done) + }) + + it('should fetch a Release items from Uid', done => { + makeRelease(releaseUID) + .item() + .findAll() + .then((collection) => { + const itemdelete = collection.items[0] + itemToDelete['version'] = itemdelete.version + itemToDelete.action = itemdelete.action + itemToDelete.uid = itemdelete.uid + itemToDelete.locale = itemdelete.locale + itemToDelete.content_type_uid = itemdelete.content_type_uid + expect(collection.items.length).to.be.equal(3) + done() + }) + .catch(done) + }) + + it('should delete specific item', done => { + makeRelease(releaseUID) + .item() + .delete({ items: [itemToDelete] }) + .then((release) => { + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.equal(releaseUID) + expect(release.items.length).to.be.equal(2) + done() + }) + .catch(done) + }) + + it('should delete all items', done => { + makeRelease(releaseUID) + .item() + .delete() + .then((release) => { + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.equal(releaseUID) + expect(release.items.length).to.be.equal(0) + done() + }) + .catch(done) + }) + + it('should fetch and Update a Release from Uid', done => { + makeRelease(releaseUID) + .fetch() + .then((release) => { + release.name = 'Update release name' + return release.update() + }) + .then((release) => { + expect(release.name).to.be.equal('Update release name') + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should update a Release from Uid', done => { + const relaseObject = makeRelease(releaseUID) + Object.assign(relaseObject, cloneDeep(releaseCreate.release)) + relaseObject + .update() + .then((release) => { + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.description).to.be.equal(releaseCreate.release.description) + expect(release.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should get all Releases', done => { + makeRelease() + .query() + .find() + .then((releaseCollection) => { + releaseCollection.items.forEach(release => { + expect(release.name).to.be.not.equal(null) + expect(release.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should get specific Releases with name ', done => { + makeRelease() + .query({ query: { name: releaseCreate.release.name } }) + .find() + .then((releaseCollection) => { + releaseCollection.items.forEach(release => { + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should clone specific Releases with Uid ', done => { + makeRelease(releaseUID) + .clone({ name: 'New Clone Name', description: 'New Desc' }) + .then((release) => { + releaseUID2 = release.uid + expect(release.name).to.be.equal('New Clone Name') + expect(release.description).to.be.equal('New Desc') + expect(release.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should delete specific Releases with Uid ', done => { + makeRelease(releaseUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Release deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete cloned Release with Uid', done => { + makeRelease(releaseUID2) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Release deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeRelease (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).release(uid) +} diff --git a/test/sanity-check/api/webhook-test.js b/test/sanity-check/api/webhook-test.js new file mode 100644 index 00000000..014c8921 --- /dev/null +++ b/test/sanity-check/api/webhook-test.js @@ -0,0 +1,172 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import path from 'path' +import { jsonReader } from '../utility/fileOperations/readwrite.js' +import { webhook, updateWebhook } from '../mock/webhook.js' +import { cloneDeep } from 'lodash' +import { contentstackClient } from '../utility/ContentstackClient.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} + +let webhookUid = '' +let webhookUid2 = '' +describe('Webhook api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should create Webhook', done => { + makeWebhook() + .create(webhook) + .then((response) => { + webhookUid = response.uid + expect(response.uid).to.be.not.equal(null) + expect(response.name).to.be.equal(webhook.webhook.name) + expect(response.destinations[0].target_url).to.be.equal(webhook.webhook.destinations[0].target_url) + expect(response.destinations[0].http_basic_auth).to.be.equal(webhook.webhook.destinations[0].http_basic_auth) + expect(response.destinations[0].http_basic_password).to.be.equal(webhook.webhook.destinations[0].http_basic_password) + expect(response.channels[0]).to.be.equal(webhook.webhook.channels[0]) + expect(response.retry_policy).to.be.equal(webhook.webhook.retry_policy) + expect(response.disabled).to.be.equal(webhook.webhook.disabled) + done() + }) + .catch(done) + }) + + it('should fetch Webhook', done => { + makeWebhook(webhookUid) + .fetch() + .then((response) => { + expect(response.uid).to.be.equal(webhookUid) + expect(response.name).to.be.equal(webhook.webhook.name) + expect(response.destinations[0].target_url).to.be.equal(webhook.webhook.destinations[0].target_url) + expect(response.destinations[0].http_basic_auth).to.be.equal(webhook.webhook.destinations[0].http_basic_auth) + expect(response.destinations[0].http_basic_password).to.be.equal(webhook.webhook.destinations[0].http_basic_password) + expect(response.channels[0]).to.be.equal(webhook.webhook.channels[0]) + expect(response.retry_policy).to.be.equal(webhook.webhook.retry_policy) + expect(response.disabled).to.be.equal(webhook.webhook.disabled) + done() + }) + .catch(done) + }) + + it('should fetch and update Webhook', done => { + makeWebhook(webhookUid) + .fetch() + .then((webhookRes) => { + Object.assign(webhookRes, cloneDeep(updateWebhook.webhook)) + return webhookRes.update() + }) + .then((response) => { + expect(response.uid).to.be.equal(webhookUid) + expect(response.name).to.be.equal(updateWebhook.webhook.name) + expect(response.destinations[0].target_url).to.be.equal(updateWebhook.webhook.destinations[0].target_url) + expect(response.destinations[0].http_basic_auth).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_auth) + expect(response.destinations[0].http_basic_password).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_password) + expect(response.channels[0]).to.be.equal(updateWebhook.webhook.channels[0]) + expect(response.retry_policy).to.be.equal(updateWebhook.webhook.retry_policy) + expect(response.disabled).to.be.equal(updateWebhook.webhook.disabled) + done() + }) + .catch(done) + }) + + it('should update Webhook', done => { + const webhookObject = makeWebhook(webhookUid) + Object.assign(webhookObject, cloneDeep(updateWebhook.webhook)) + webhookObject.update() + .then((response) => { + expect(response.uid).to.be.equal(webhookUid) + expect(response.name).to.be.equal(updateWebhook.webhook.name) + expect(response.destinations[0].target_url).to.be.equal(updateWebhook.webhook.destinations[0].target_url) + expect(response.destinations[0].http_basic_auth).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_auth) + expect(response.destinations[0].http_basic_password).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_password) + expect(response.channels[0]).to.be.equal(updateWebhook.webhook.channels[0]) + expect(response.retry_policy).to.be.equal(updateWebhook.webhook.retry_policy) + expect(response.disabled).to.be.equal(updateWebhook.webhook.disabled) + done() + }) + .catch(done) + }) + + it('should import Webhook', done => { + makeWebhook().import({ + webhook: path.join(__dirname, '../mock/webhook.json') + }) + .then((response) => { + webhookUid2 = response.uid + expect(response.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should get executions of a webhook', done => { + const asset = { + upload: path.join(__dirname, '../mock/webhook.json') + } + client.stack({ api_key: process.env.API_KEY }).asset().create(asset) + .then((assetFile) => { + makeWebhook(webhookUid).executions() + .then((response) => { + response.webhooks.forEach(webhookResponse => { + expect(webhookResponse.uid).to.be.not.equal(null) + expect(webhookResponse.status).to.be.equal(200) + expect(webhookResponse.event_data.module).to.be.equal('asset') + expect(webhookResponse.event_data.api_key).to.be.equal(process.env.API_KEY) + + const webhookasset = webhookResponse.event_data.data.asset + expect(webhookasset.uid).to.be.equal(assetFile.uid) + expect(webhookasset.filename).to.be.equal(assetFile.filename) + expect(webhookasset.url).to.be.equal(assetFile.url) + expect(webhookasset.title).to.be.equal(assetFile.title) + + expect(webhookResponse.webhooks[0]).to.be.equal(webhookUid) + expect(webhookResponse.channel[0]).to.be.equal('assets.create') + }) + done() + }) + .catch(done) + }).catch(done) + }) + + it('should get all Webhook', done => { + makeWebhook().fetchAll() + .then((collection) => { + collection.items.forEach(webhookResponse => { + expect(webhookResponse.uid).to.be.not.equal(null) + expect(webhookResponse.name).to.be.not.equal(null) + expect(webhookResponse.org_uid).to.be.equal(process.env.ORGANIZATION) + }) + done() + }) + .catch(done) + }) + + it('should delete the created webhook', done => { + makeWebhook(webhookUid) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('The Webhook was deleted successfully') + done() + }) + .catch(done) + }) + + it('should delete the created webhook', done => { + makeWebhook(webhookUid2) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('The Webhook was deleted successfully') + done() + }) + .catch(done) + }) +}) + +function makeWebhook (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).webhook(uid) +} diff --git a/test/sanity-check/api/workflow-test.js b/test/sanity-check/api/workflow-test.js new file mode 100644 index 00000000..01c96545 --- /dev/null +++ b/test/sanity-check/api/workflow-test.js @@ -0,0 +1,143 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite.js' +import { contentstackClient } from '../utility/ContentstackClient.js' +import { firstWorkflow, secondWorkflow, finalWorkflow } from '../mock/workflow.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} + +let user = {} +let workflowUid = '' +let workflowUid2 = '' +let workflowUid3 = '' + +describe('Workflow api Test', () => { + setup(async () => { + user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should create Workflow Content type Multi page from JSON', done => { + const workflow = { ...firstWorkflow } + makeWorkflow() + .create({ workflow }) + .then(workflowResponse => { + workflowUid = workflowResponse.uid + expect(workflowResponse.name).to.be.equal(firstWorkflow.name) + expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) + expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) + done() + }) + .catch(done) + }) + + it('should create Workflow Content type Multi page', done => { + const workflow = { ...secondWorkflow } + makeWorkflow() + .create({ workflow }) + .then(workflowResponse => { + workflowUid2 = workflowResponse.uid + expect(workflowResponse.name).to.be.equal(secondWorkflow.name) + expect(workflowResponse.content_types.length).to.be.equal(secondWorkflow.content_types.length) + expect(workflowResponse.workflow_stages.length).to.be.equal(secondWorkflow.workflow_stages.length) + done() + }) + .catch(done) + }) + + it('should create Workflow Content type single page', done => { + const workflow = { ...finalWorkflow } + makeWorkflow() + .create({ workflow }) + .then(workflowResponse => { + workflowUid3 = workflowResponse.uid + expect(workflowResponse.name).to.be.equal(finalWorkflow.name) + expect(workflowResponse.content_types.length).to.be.equal(finalWorkflow.content_types.length) + expect(workflowResponse.workflow_stages.length).to.be.equal(finalWorkflow.workflow_stages.length) + done() + }) + .catch(done) + }) + + it('should fetch Workflow from UID', done => { + makeWorkflow(workflowUid) + .fetch() + .then(workflowResponse => { + workflowUid = workflowResponse.uid + expect(workflowResponse.name).to.be.equal(firstWorkflow.name) + expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) + expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) + done() + }) + .catch(done) + }) + + it('should update Workflow from UID', done => { + const workflowObj = makeWorkflow(workflowUid) + Object.assign(workflowObj, firstWorkflow) + workflowObj.name = 'Updated name' + + workflowObj + .update() + .then(workflowResponse => { + workflowUid = workflowResponse.uid + expect(workflowResponse.name).to.be.equal('Updated name') + expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) + expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) + done() + }) + .catch(done) + }) + + it('should fetch and update Workflow from UID', done => { + makeWorkflow(workflowUid) + .fetch() + .then(workflowResponse => { + workflowResponse.name = firstWorkflow.name + return workflowResponse.update() + }) + .then(workflowResponse => { + expect(workflowResponse.name).to.be.equal(firstWorkflow.name) + expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) + expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) + done() + }) + .catch(done) + }) + + it('should delete Workflow from UID', done => { + makeWorkflow(workflowUid) + .delete() + .then(response => { + expect(response.notice).to.be.equal('Workflow deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete Workflow from UID2 ', done => { + makeWorkflow(workflowUid2) + .delete() + .then(response => { + expect(response.notice).to.be.equal('Workflow deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete Workflow from UID3 ', done => { + makeWorkflow(workflowUid3) + .delete() + .then(response => { + expect(response.notice).to.be.equal('Workflow deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeWorkflow (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).workflow(uid) +} diff --git a/test/sanity-check/mock/release.js b/test/sanity-check/mock/release.js new file mode 100644 index 00000000..9bb45e77 --- /dev/null +++ b/test/sanity-check/mock/release.js @@ -0,0 +1,10 @@ +const releaseCreate = { + release: { + name: 'First release', + description: 'Adding release date 2020-21-07', + locked: false, + archived: false + } +} + +export { releaseCreate } diff --git a/test/sanity-check/mock/webhook.js b/test/sanity-check/mock/webhook.js new file mode 100644 index 00000000..86af1eb4 --- /dev/null +++ b/test/sanity-check/mock/webhook.js @@ -0,0 +1,40 @@ +const webhook = { + webhook: { + name: 'Test', + destinations: [{ + target_url: 'http://example.com', + http_basic_auth: 'basic', + http_basic_password: 'test', + custom_header: [{ + header_name: 'Custom', + value: 'testing' + }] + }], + channels: [ + 'assets.create' + ], + retry_policy: 'manual', + disabled: false + } +} + +const updateWebhook = { + webhook: { + name: 'Updated webhook', + destinations: [{ + target_url: 'http://example.com', + http_basic_auth: 'basic', + http_basic_password: 'test', + custom_header: [{ + header_name: 'Custom', + value: 'testing' + }] + }], + channels: [ + 'assets.create' + ], + retry_policy: 'manual', + disabled: true + } +} +export { webhook, updateWebhook } diff --git a/test/sanity-check/mock/webhook.json b/test/sanity-check/mock/webhook.json new file mode 100644 index 00000000..5667abc9 --- /dev/null +++ b/test/sanity-check/mock/webhook.json @@ -0,0 +1,17 @@ +{ + "name": "Upload webhook", + "destinations": [{ + "target_url": "http://example.com", + "http_basic_auth": "basic", + "http_basic_password": "test", + "custom_header": [{ + "header_name": "Custom", + "value": "testing" + }] + }], + "channels": [ + "assets.create" + ], + "retry_policy": "manual", + "disabled": "true" +} \ No newline at end of file diff --git a/test/sanity-check/mock/workflow.js b/test/sanity-check/mock/workflow.js new file mode 100644 index 00000000..4ae2930a --- /dev/null +++ b/test/sanity-check/mock/workflow.js @@ -0,0 +1,126 @@ +const firstWorkflow = { + workflow_stages: [ + { + color: '#2196f3', + SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, + next_available_stages: ['$all'], + allStages: true, + allUsers: true, + specificStages: false, + specificUsers: false, + entry_lock: '$none', + name: 'First stage' + }, + { + color: '#e53935', + SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, + allStages: true, + allUsers: true, + specificStages: false, + specificUsers: false, + next_available_stages: ['$all'], + entry_lock: '$none', + name: 'Second stage' + } + ], + branches: [ + 'main' + ], + admin_users: { users: [] }, + name: 'First Workflow', + content_types: ['multi_page_from_json'] +} +const secondWorkflow = { + workflow_stages: [ + { + color: '#2196f3', + SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, + next_available_stages: ['$all'], + allStages: true, + allUsers: true, + specificStages: false, + specificUsers: false, + entry_lock: '$none', + name: 'first stage' + }, + { + isNew: true, + color: '#e53935', + SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, + allStages: true, + allUsers: true, + specificStages: false, + specificUsers: false, + next_available_stages: ['$all'], + entry_lock: '$none', + name: 'stage 2' + } + ], + branches: [ + 'main' + ], + admin_users: { users: [] }, + name: 'Second workflow', + enabled: true, + content_types: ['multi_page'] +} +const finalWorkflow = { + workflow_stages: [ + { + color: '#2196f3', + SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, + next_available_stages: ['$all'], + allStages: true, + allUsers: true, + specificStages: false, + specificUsers: false, + entry_lock: '$none', + name: 'Review' + }, + { + color: '#74ba76', + SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, + allStages: true, + allUsers: true, + specificStages: false, + specificUsers: false, + next_available_stages: ['$all'], + entry_lock: '$none', + name: 'Complet' + } + ], + branches: [ + 'main' + ], + admin_users: { users: [] }, + name: 'Workflow', + enabled: true, + content_types: ['single_page'] +} + +const firstPublishRules = { + isNew: true, + actions: ['publish'], + content_types: ['multi_page_from_json'], + locales: ['en-at'], + environment: 'environment_name', + workflow_stage: '', + approvers: { users: ['user_id'], roles: ['role_uid'] } +} +const secondPublishRules = { + isNew: true, + actions: ['publish'], + content_types: ['multi_page'], + locales: ['en-at'], + environment: 'environment_name', + workflow_stage: '', + approvers: { users: ['user_id'], roles: ['role_uid'] } +} + +export { + firstWorkflow, + secondWorkflow, + finalWorkflow, + firstPublishRules, + secondPublishRules +} From 6b40b3268f0f0b04e86c83bce6bcf26dc2abb75c Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 31 Jan 2024 15:13:27 +0530 Subject: [PATCH 14/16] updated sanity.js file --- test/sanity-check/sanity.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index af0acaa7..e9e30512 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -12,10 +12,10 @@ require('./api/contentType-test') require('./api/asset-test') require('./api/extension-test') require('./api/entry-test') -// require('./api/webhook-test') -// require('./api/workflow-test') +require('./api/webhook-test') +require('./api/workflow-test') require('./api/globalfield-test') -// require('./api/release-test') +require('./api/release-test') require('./api/label-test') require('./api/contentType-delete-test') require('./api/taxonomy-test') From f8f55ff1cc805905dacd33c4c7f567da09460254 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 31 Jan 2024 15:53:38 +0530 Subject: [PATCH 15/16] test: added basic sanity for role --- test/sanity-check/api/organization-test.js | 6 +- test/sanity-check/api/role-test.js | 148 +++++++++++++++++++++ test/sanity-check/mock/role.js | 82 ++++++++++++ test/sanity-check/sanity.js | 2 +- 4 files changed, 233 insertions(+), 5 deletions(-) create mode 100644 test/sanity-check/api/role-test.js create mode 100644 test/sanity-check/mock/role.js diff --git a/test/sanity-check/api/organization-test.js b/test/sanity-check/api/organization-test.js index 7e1f2b8f..da25c4b9 100644 --- a/test/sanity-check/api/organization-test.js +++ b/test/sanity-check/api/organization-test.js @@ -1,6 +1,6 @@ import { expect } from 'chai' import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' +import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite' import { contentstackClient } from '../utility/ContentstackClient' var user = {} @@ -79,6 +79,7 @@ describe('Organization api test', () => { organization.roles() .then((roles) => { for (const i in roles.items) { + jsonWrite(roles.items, 'orgRoles.json') expect(roles.items[i].uid).to.not.equal(null, 'Role uid cannot be null') expect(roles.items[i].name).to.not.equal(null, 'Role name cannot be null') expect(roles.items[i].org_uid).to.be.equal(organization.uid, 'Role org_uid not match') @@ -102,7 +103,4 @@ describe('Organization api test', () => { }) .catch(done) }) - - // addUser - // Resend invitation }) diff --git a/test/sanity-check/api/role-test.js b/test/sanity-check/api/role-test.js new file mode 100644 index 00000000..d1a190c1 --- /dev/null +++ b/test/sanity-check/api/role-test.js @@ -0,0 +1,148 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import role from '../mock/role.js' +import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite' +import { contentstackClient } from '../utility/ContentstackClient.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} +let roleUID = '' + +describe('Role api test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should get all role in stack', done => { + getRole() + .fetchAll() + .then((roles) => { + jsonWrite(roles.items, 'roles.json') + for (const index in roles.items) { + const role1 = roles.items[index] + expect(role1.uid).to.not.equal(null, 'Role uid cannot be null') + } + done() + }) + .catch(done) + }) + + it('should get 1 role in stack with limit', done => { + getRole() + .fetchAll({ limit: 2 }) + .then((roles) => { + expect(roles.items.length).to.not.equal(1) + done() + }) + .catch(done) + }) + + it('should get role in stack with skip first', done => { + getRole() + .fetchAll({ skip: 1 }) + .then((roles) => { + expect(roles.items.lenth).to.not.equal(1, 'Role fetch with limit 1 not work') + done() + }) + .catch(done) + }) + + it('should create new role in stack', done => { + getRole() + .create(role) + .then((roles) => { + roleUID = roles.uid + expect(roles.name).to.be.equal(role.role.name, 'Role name not match') + expect(roles.description).to.be.equal(role.role.description, 'Role description not match') + done() + }) + .catch(done) + }) + + it('should get role in stack', done => { + getRole(roleUID) + .fetch() + .then((roles) => { + jsonWrite(roles, 'role.json') + expect(roles.name).to.be.equal(role.role.name, 'Role name not match') + expect(roles.description).to.be.equal(role.role.description, 'Role description not match') + expect(roles.stack.api_key).to.be.equal(process.env.API_KEY, 'Role stack uid not match') + done() + }) + .catch(done) + }) + + it('should update role in stack', done => { + getRole(roleUID) + .fetch({ include_rules: true, include_permissions: true }) + .then((roles) => { + roles.name = 'Update test name' + roles.description = 'Update description' + return roles.update() + }) + .then((roles) => { + expect(roles.name).to.be.equal('Update test name', 'Role name not match') + expect(roles.description).to.be.equal('Update description', 'Role description not match') + done() + }) + .catch(done) + }) + + it('should get all Roles with query', done => { + getRole() + .query() + .find() + .then((response) => { + for (const index in response.items) { + const role = response.items[index] + expect(role.name).to.not.equal(null) + expect(role.uid).to.not.equal(null) + } + done() + }) + .catch(done) + }) + + it('should get query Role', done => { + getRole() + .query({ query: { name: 'Developer' } }) + .find() + .then((response) => { + for (const index in response.items) { + const stack = response.items[index] + expect(stack.name).to.be.equal('Developer') + } + done() + }) + .catch(done) + }) + + it('should find one role', done => { + getRole() + .query({ name: 'Developer' }) + .findOne() + .then((response) => { + const stack = response.items[0] + expect(response.items.length).to.be.equal(1) + expect(stack.name).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should delete role in stack', done => { + getRole(roleUID) + .delete() + .then((roles) => { + expect(roles.notice).to.be.equal('The role deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function getRole (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).role(uid) +} diff --git a/test/sanity-check/mock/role.js b/test/sanity-check/mock/role.js new file mode 100644 index 00000000..7364ae8d --- /dev/null +++ b/test/sanity-check/mock/role.js @@ -0,0 +1,82 @@ +const role = { + role: { + name: 'testRole', + description: 'This is a test role.', + rules: [ + { + module: 'branch', + branches: [ + 'main' + ], + acl: { + read: true + } + }, + { + module: 'branch_alias', + branch_aliases: [ + 'staging_alias' + ], + acl: { + read: true + } + }, + { + module: 'content_type', + content_types: [ + '$all' + ], + acl: { + read: true, + sub_acl: { + read: true + } + } + }, + { + module: 'asset', + assets: [ + '$all' + ], + acl: { + read: true, + update: true, + publish: true, + delete: true + } + }, + { + module: 'folder', + folders: [ + '$all' + ], + acl: { + read: true, + sub_acl: { + read: true + } + } + }, + { + module: 'environment', + environments: [ + '$all' + ], + acl: { + read: true + } + }, + { + module: 'locale', + locales: [ + 'en-us' + ], + acl: { + read: true + } + } + ] + } +} + +export default role diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index e9e30512..09c1aa64 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -5,7 +5,7 @@ require('./api/locale-test') require('./api/environment-test') require('./api/branch-test') require('./api/branchAlias-test') -// require('./api/role-test') +require('./api/role-test') require('./api/deliveryToken-test') // require('./api/managementToken-test') require('./api/contentType-test') From 76de3170e7d9e470f445a8bfdf0d7759f74b24c3 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 31 Jan 2024 15:55:11 +0530 Subject: [PATCH 16/16] test: added basic sanity for management token test suit --- test/sanity-check/api/managementToken-test.js | 146 ++++++++++++++++++ test/sanity-check/mock/managementToken.js | 72 +++++++++ test/sanity-check/sanity.js | 2 +- 3 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 test/sanity-check/api/managementToken-test.js create mode 100644 test/sanity-check/mock/managementToken.js diff --git a/test/sanity-check/api/managementToken-test.js b/test/sanity-check/api/managementToken-test.js new file mode 100644 index 00000000..b676b195 --- /dev/null +++ b/test/sanity-check/api/managementToken-test.js @@ -0,0 +1,146 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite.js' +import { createManagementToken, createManagementToken2 } from '../mock/managementToken.js' +import { contentstackClient } from '../utility/ContentstackClient.js' + +let client = {} + +let tokenUidProd = '' +let tokenUidDev = '' +describe('Management Token api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should add a Management Token', done => { + makeManagementToken() + .create(createManagementToken) + .then((token) => { + tokenUidDev = token.uid + expect(token.name).to.be.equal(createManagementToken.token.name) + expect(token.description).to.be.equal(createManagementToken.token.description) + expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should add a Management Token for production', done => { + makeManagementToken() + .create(createManagementToken2) + .then((token) => { + tokenUidProd = token.uid + expect(token.name).to.be.equal(createManagementToken2.token.name) + expect(token.description).to.be.equal(createManagementToken2.token.description) + expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should get a Management Token from uid', done => { + makeManagementToken(tokenUidProd) + .fetch() + .then((token) => { + expect(token.name).to.be.equal(createManagementToken2.token.name) + expect(token.description).to.be.equal(createManagementToken2.token.description) + expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should query to get all Management Token', done => { + makeManagementToken() + .query() + .find() + .then((tokens) => { + tokens.items.forEach((token) => { + expect(token.name).to.be.not.equal(null) + expect(token.description).to.be.not.equal(null) + expect(token.scope[0].module).to.be.not.equal(null) + expect(token.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should query to get a Management Token from name', done => { + makeManagementToken() + .query({ query: { name: createManagementToken.token.name } }) + .find() + .then((tokens) => { + tokens.items.forEach((token) => { + expect(token.name).to.be.equal(createManagementToken.token.name) + expect(token.description).to.be.equal(createManagementToken.token.description) + expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should fetch and update a Management Token from uid', done => { + makeManagementToken(tokenUidProd) + .fetch() + .then((token) => { + token.name = 'Update Production Name' + token.description = 'Update Production description' + token.scope = createManagementToken2.token.scope + return token.update() + }) + .then((token) => { + expect(token.name).to.be.equal('Update Production Name') + expect(token.description).to.be.equal('Update Production description') + expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should update a Management Token from uid', done => { + const token = makeManagementToken(tokenUidProd) + Object.assign(token, createManagementToken2.token) + token.update() + .then((token) => { + expect(token.name).to.be.equal(createManagementToken2.token.name) + expect(token.description).to.be.equal(createManagementToken2.token.description) + expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) + expect(token.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + + it('should delete a Management Token from uid', done => { + makeManagementToken(tokenUidProd) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Management Token deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete a Management Token from uid 2', done => { + makeManagementToken(tokenUidDev) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Management Token deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeManagementToken (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).managementToken(uid) +} diff --git a/test/sanity-check/mock/managementToken.js b/test/sanity-check/mock/managementToken.js new file mode 100644 index 00000000..263b786f --- /dev/null +++ b/test/sanity-check/mock/managementToken.js @@ -0,0 +1,72 @@ +const createManagementToken = { + token: { + name: 'Dev Token', + description: 'This is a sample management token.', + scope: [ + { + module: 'content_type', + acl: { + read: true, + write: true + } + }, + { + module: 'branch', + branches: [ + 'main' + ], + acl: { + read: true + } + }, + { + module: 'branch_alias', + branch_aliases: [ + 'sb1_alias' + ], + acl: { + read: true + } + } + ], + expires_on: '2024-12-10', + is_email_notification_enabled: true + } +} +const createManagementToken2 = { + token: { + name: 'Prod Token', + description: 'This is a sample management token.', + scope: [ + { + module: 'content_type', + acl: { + read: true, + write: true + } + }, + { + module: 'branch', + branches: [ + 'main' + ], + acl: { + read: true + } + }, + { + module: 'branch_alias', + branch_aliases: [ + 'sb1_alias' + ], + acl: { + read: true + } + } + ], + expires_on: '2024-12-10', + is_email_notification_enabled: true + } +} + +export { createManagementToken, createManagementToken2 } diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index 09c1aa64..d1643fb6 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -7,7 +7,7 @@ require('./api/branch-test') require('./api/branchAlias-test') require('./api/role-test') require('./api/deliveryToken-test') -// require('./api/managementToken-test') +require('./api/managementToken-test') require('./api/contentType-test') require('./api/asset-test') require('./api/extension-test')