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')