From 08e79f6762fd94982d2b11ed7eacfe26211077b1 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 24 Jan 2024 11:29:40 +0530 Subject: [PATCH 1/4] 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 a1f186644215e7ce2d2e5514cb3b07bd2bc2751d Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 24 Jan 2024 12:06:00 +0530 Subject: [PATCH 2/4] 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 942770807ff6911f3759f8d5aaf2cadf970d272a Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 24 Jan 2024 15:47:18 +0530 Subject: [PATCH 3/4] 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 90984845cc5ab470135ed2334936bd33c2fbdca6 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 25 Jan 2024 12:17:29 +0530 Subject: [PATCH 4/4] 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() + }) }) })