From ad7c7bbce9314bd8b14ff3f1a2d4f7620f9376e7 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:17:58 +0530 Subject: [PATCH] Next (#119) * 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> * test: added delivery token test sanity folder * test: added extension test suit to sanity * test: updated test msg * cleared assertion error * test: added assertions for failing tests * 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> * test: added global field test suit to sanity * test: add sanity test for label --------- 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> --- CHANGELOG.md | 4 + package.json | 5 +- test/api/mock/taxonomy.json | 8 + test/api/taxonomy-test.js | 25 + test/sanity-check/api/branchAlias-test.js | 23 - .../api/contentType-delete-test.js | 10 + test/sanity-check/api/contentType-test.js | 12 - test/sanity-check/api/delete-test.js | 74 ++- test/sanity-check/api/deliveryToken-test.js | 143 ++++++ test/sanity-check/api/extension-test.js | 486 ++++++++++++++++++ test/sanity-check/api/globalfield-test.js | 140 +++++ test/sanity-check/api/label-test.js | 137 +++++ test/sanity-check/mock/deliveryToken.js | 74 +++ test/sanity-check/mock/extension.js | 91 ++++ test/sanity-check/mock/globalfield.js | 28 + test/sanity-check/mock/globalfield.json | 34 ++ test/sanity-check/sanity.js | 13 +- test/unit/mock/objects.js | 7 + test/unit/taxonomy-test.js | 50 +- 19 files changed, 1322 insertions(+), 42 deletions(-) create mode 100644 test/api/mock/taxonomy.json create mode 100644 test/sanity-check/api/deliveryToken-test.js create mode 100644 test/sanity-check/api/extension-test.js create mode 100644 test/sanity-check/api/globalfield-test.js create mode 100644 test/sanity-check/api/label-test.js create mode 100644 test/sanity-check/mock/deliveryToken.js create mode 100644 test/sanity-check/mock/extension.js create mode 100644 test/sanity-check/mock/globalfield.js create mode 100644 test/sanity-check/mock/globalfield.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d28b6df0..47d38c36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # 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 83438772..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", @@ -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/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/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/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 de5f8739..6764a85f 100644 --- a/test/sanity-check/api/delete-test.js +++ b/test/sanity-check/api/delete-test.js @@ -1,8 +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 = {} @@ -59,6 +64,65 @@ 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 +130,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/api/extension-test.js b/test/sanity-check/api/extension-test.js new file mode 100644 index 00000000..250c9c1c --- /dev/null +++ b/test/sanity-check/api/extension-test.js @@ -0,0 +1,486 @@ +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('should 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('should 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((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 => { + 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((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 => { + 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((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 => { + 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((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 => { + 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('should 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((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 => { + 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((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 => { + 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((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 => { + 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('should 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('should 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('should 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('should 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('should 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('should delete Custom field', done => { + makeExtension(customFieldUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customWidgetUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customDashboardUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customFieldSrcUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customWidgetSrcUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customDashboardSrcUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customFieldUploadUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customWidgetUploadUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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 => { + makeExtension(customDashboardUploadUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Extension deleted successfully.') + 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() + }) + }) +}) + +function makeExtension (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).extension(uid) +} 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/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/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/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/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 13843af7..af0acaa7 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -3,11 +3,20 @@ 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/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/branch-test') -require('./api/branchAlias-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') 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, {