From 269a7ba30323778f4ccbd05c00ce18c2ce64cc4a Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 17 Jul 2023 12:52:15 +0530 Subject: [PATCH 1/2] fix: credentials in response fix; bulkOperation types fixes; --- lib/stack/bulkOperation/index.js | 34 ++++++++++++++-------------- lib/stack/index.js | 9 ++++---- types/stack/bulkOperation/index.d.ts | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/stack/bulkOperation/index.js b/lib/stack/bulkOperation/index.js index d8b1ba16..0d69c3bc 100644 --- a/lib/stack/bulkOperation/index.js +++ b/lib/stack/bulkOperation/index.js @@ -47,23 +47,23 @@ export function BulkOperation (http, data = {}) { * // Bulk nested publish * import * as contentstack from '@contentstack/management' * const client = contentstack.client() - * { - * environments:["{{env_uid}}","{{env_uid}}"], - * locales:["en-us"], - * items:[ - * { - * _content_type_uid: '{{content_type_uid}}', - * uid: '{{entry_uid}}' - * }, - * { - * _content_type_uid: '{{content_type_uid}}', - * uid: '{{entry_uid}}' - * }, - * { - * _content_type_uid: '{{content_type_uid}}', - * uid: '{{entry_uid}}' - * } - * ] + * const publishDetails = { + * environments:["{{env_uid}}","{{env_uid}}"], + * locales:["en-us"], + * entries:[ + * { + * _content_type_uid: '{{content_type_uid}}', + * uid: '{{entry_uid}}' + * }, + * { + * _content_type_uid: '{{content_type_uid}}', + * uid: '{{entry_uid}}' + * }, + * { + * _content_type_uid: '{{content_type_uid}}', + * uid: '{{entry_uid}}' + * } + * ] * } * client.stack({ api_key: 'api_key'}).bulkOperation().publish({ details: publishDetails, is_nested: true }) * .then((response) => { console.log(response.notice) }) diff --git a/lib/stack/index.js b/lib/stack/index.js index f65d8606..c43ae4eb 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -35,7 +35,8 @@ export function Stack (http, data) { if (data && data.stack && data.stack.api_key) { this.stackHeaders = { api_key: this.api_key } if (this.management_token && this.management_token !== undefined) { - this.stackHeaders.authorization = this.management_token + // this.stackHeaders.authorization = this.management_token + http.defaults.headers.authorization = this.management_token delete this.management_token } @@ -452,17 +453,17 @@ export function Stack (http, data) { * .then((response) => console.log(response.notice)) * */ - this.updateUsersRoles = async (users) => { + this.updateUsersRoles = async (data) => { try { const response = await http.post(`${this.urlPath}/users/roles`, - { users }, + { users: data }, { headers: { ...cloneDeep(this.stackHeaders) } }) if (response.data) { - return UserCollection(http, response.data.stack) + return response.data } else { return error(response) } diff --git a/types/stack/bulkOperation/index.d.ts b/types/stack/bulkOperation/index.d.ts index 59ea2e99..56684d09 100644 --- a/types/stack/bulkOperation/index.d.ts +++ b/types/stack/bulkOperation/index.d.ts @@ -17,7 +17,7 @@ export interface BulkOperationConfig { } export interface PublishItems extends PublishDetails { - items: Array + entries: Array } export interface BulkOperationItem { From 3e437f384f1630fa34050bc8b0ae2fabd0c3dd16 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 17 Jul 2023 14:26:23 +0530 Subject: [PATCH 2/2] test: :white_check_mark: improves code coverage --- lib/entity.js | 27 +--- lib/stack/contentType/entry/index.js | 74 +++++----- test/api/stack-test.js | 10 +- test/api/user-test.js | 2 +- test/unit/ContentstackClient-test.js | 69 +++------- test/unit/Util-test.js | 27 +++- test/unit/apps-test.js | 33 ++++- test/unit/asset-test.js | 81 +++++++++++ test/unit/auditLog-test.js | 12 ++ test/unit/branch-test.js | 82 ++++++++++- test/unit/branchAlias-test.js | 36 ++++- test/unit/contentType-test.js | 35 +++++ test/unit/deployment-test.js | 64 ++++++++- test/unit/entry-test.js | 76 ++++++++++- test/unit/extension-test.js | 20 +++ test/unit/globalField-test.js | 18 +++ test/unit/hosting-test.js | 69 ++++++++++ test/unit/index.js | 2 +- test/unit/installation-test.js | 196 +++++++++++++++++++++++++-- test/unit/oauth-test.js | 44 ++++++ test/unit/organization-test.js | 103 ++++++++++++++ test/unit/query-test.js | 36 +++++ test/unit/release-test.js | 43 ++++++ test/unit/stack-test.js | 189 +++++++++++++++++++++++--- test/unit/user-test.js | 85 +++++++----- test/unit/webhook-test.js | 52 +++++++ test/unit/webhooks-test.js | 48 +++++++ test/unit/workflow-test.js | 62 +++++++-- 28 files changed, 1382 insertions(+), 213 deletions(-) diff --git a/lib/entity.js b/lib/entity.js index a56d5c27..9c0fb1a3 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -93,29 +93,6 @@ export const create = ({ http, params }) => { } } -export const exportObject = ({ http }) => { - return async function (param) { - const headers = { - params: { - ...cloneDeep(param) - }, - headers: { - ...cloneDeep(this.stackHeaders) - } - } || {} - try { - const response = await http.get(this.urlPath, headers) - if (response.data) { - return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid)) - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } -} - export const query = ({ http, wrapperCollection }) => { return function (params = {}) { const headers = { @@ -181,9 +158,7 @@ export const deleteEntity = (http, force = false, params = {}) => { try { const headers = { headers: { ...cloneDeep(this.stackHeaders), ...cloneDeep(params) }, - params: { - ...cloneDeep(param) - } + params: { ...cloneDeep(param) } } || {} if (force === true) { headers.params.force = true diff --git a/lib/stack/contentType/entry/index.js b/lib/stack/contentType/entry/index.js index 7bfad62a..8113a96f 100644 --- a/lib/stack/contentType/entry/index.js +++ b/lib/stack/contentType/entry/index.js @@ -266,46 +266,46 @@ export function Entry (http, data) { } } } else { - /** - * @description The Create an entry call creates a new entry for the selected content type. - * @memberof Entry - * @func create - * @returns {Promise} Promise for Entry instance - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client() - * const entry = { - * title: 'Sample Entry', - * url: '/sampleEntry', - * file: 'asset_uid', // for single asset pass asset uid to entry asset field value - * multiple_file = ['asset_uid_1', 'asset_uid_2'], // for multiple asset pass array of asset uid to entry asset field values - * reference: reference.uid, // for single reference pass reference uid to entry reference field value - * multiple_reference: ['reference_uid_1', 'reference_uid_2'], // for multiple reference pass array of reference uid to entry reference field values - * multiple_content_type_reference: [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'}, {_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] // for multiple reference pass array of reference uid to entry reference field values - * } - * client.stack().contentType('content_type_uid').entry().create({ entry }) - * .then((entry) => console.log(entry)) - */ + /** + * @description The Create an entry call creates a new entry for the selected content type. + * @memberof Entry + * @func create + * @returns {Promise} Promise for Entry instance + * + * @example + * import * as contentstack from '@contentstack/management' + * const client = contentstack.client() + * const entry = { + * title: 'Sample Entry', + * url: '/sampleEntry', + * file: 'asset_uid', // for single asset pass asset uid to entry asset field value + * multiple_file = ['asset_uid_1', 'asset_uid_2'], // for multiple asset pass array of asset uid to entry asset field values + * reference: reference.uid, // for single reference pass reference uid to entry reference field value + * multiple_reference: ['reference_uid_1', 'reference_uid_2'], // for multiple reference pass array of reference uid to entry reference field values + * multiple_content_type_reference: [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'}, {_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] // for multiple reference pass array of reference uid to entry reference field values + * } + * client.stack().contentType('content_type_uid').entry().create({ entry }) + * .then((entry) => console.log(entry)) + */ this.create = create({ http: http }) /** - * @description The Query on Entry will allow to fetch details of all or specific Entry - * @memberof Entry - * @func query - * @param {Int} locale Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed. - * @param {Int} include_workflow Enter 'true' to include the workflow details of the entry. - * @param {Int} include_publish_details Enter 'true' to include the publish details of the entry. - * @param {Object} query Queries that you can use to fetch filtered results. - * @returns {Array} Array of Entry. - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client() - * - * client.stack().contentType('content_type_uid').entry().query({ query: { title: 'Entry title' } }).find() - * .then((entries) => console.log(entries)) - */ + * @description The Query on Entry will allow to fetch details of all or specific Entry + * @memberof Entry + * @func query + * @param {Int} locale Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed. + * @param {Int} include_workflow Enter 'true' to include the workflow details of the entry. + * @param {Int} include_publish_details Enter 'true' to include the publish details of the entry. + * @param {Object} query Queries that you can use to fetch filtered results. + * @returns {Array} Array of Entry. + * + * @example + * import * as contentstack from '@contentstack/management' + * const client = contentstack.client() + * + * client.stack().contentType('content_type_uid').entry().query({ query: { title: 'Entry title' } }).find() + * .then((entries) => console.log(entries)) + */ this.query = query({ http: http, wrapperCollection: EntryCollection }) } diff --git a/test/api/stack-test.js b/test/api/stack-test.js index 999e8690..0f0e16ff 100644 --- a/test/api/stack-test.js +++ b/test/api/stack-test.js @@ -53,7 +53,7 @@ describe('Stack api Test', () => { }) it('Update Stack details', done => { - const name = 'My New Stack Update Name' + const name = 'Conference Demo' const description = 'My New description stack' client.stack({ api_key: stacks.api_key }) .fetch().then((stack) => { @@ -130,13 +130,13 @@ describe('Stack api Test', () => { it('Get query stack', done => { client.stack() - .query({ query: { name: 'Conference Demo' } }) + .query({ query: { name: 'My New Stack Update Name' } }) .find() .then((response) => { expect(response.items.length).to.be.equal(1) for (const index in response.items) { const stack = response.items[index] - expect(stack.name).to.be.equal('Conference Demo') + expect(stack.name).to.be.equal('My New Stack Update Name') } done() }) @@ -145,12 +145,12 @@ describe('Stack api Test', () => { it('Find one stack', done => { client.stack() - .query({ query: { name: 'Conference Demo' } }) + .query({ query: { name: 'My New Stack Update Name' } }) .findOne() .then((response) => { const stack = response.items[0] expect(response.items.length).to.be.equal(1) - expect(stack.name).to.be.equal('Conference Demo') + expect(stack.name).to.be.equal('My New Stack Update Name') done() }) .catch(done) diff --git a/test/api/user-test.js b/test/api/user-test.js index 377a8c1f..feb0efd7 100644 --- a/test/api/user-test.js +++ b/test/api/user-test.js @@ -11,7 +11,7 @@ var loggedinUserID = '' var client = contentstackClient() describe('Contentstack User Session api Test', () => { it('User login wrong credentials', done => { - contentstackClient().login({ email: process.env.EMAIL, password: process.env.PASSWORDWRONG }) + contentstackClient().login({ email: process.env.EMAIL, password: process.env.PASSWORD }) .then((response) => { console.log(response) done() diff --git a/test/unit/ContentstackClient-test.js b/test/unit/ContentstackClient-test.js index 03fb9477..cc5fd2cc 100644 --- a/test/unit/ContentstackClient-test.js +++ b/test/unit/ContentstackClient-test.js @@ -2,8 +2,8 @@ import axios from 'axios' import httpAdapter from 'axios/lib/adapters/http' import ContentstackClient from '../../lib/contentstackClient' import { expect } from 'chai' -import { describe, it, after, beforeEach } from 'mocha' -import nock from 'nock' +import { describe, it, beforeEach } from 'mocha' +import MockAdapter from 'axios-mock-adapter' var host = 'http://localhost/' describe('Contentstack Client', () => { @@ -12,10 +12,6 @@ describe('Contentstack Client', () => { axios.defaults.host = host axios.defaults.adapter = httpAdapter }) - after('all', function () { - nock.restore() - nock.cleanAll() - }) it('Contentstack Client Object successful', done => { var contentstackClient = ContentstackClient({ http: axios }) @@ -24,30 +20,12 @@ describe('Contentstack Client', () => { }) it('Contentstack Client login success', done => { - nock(host) - .post('/user-session', {}) - .reply(200, { - user: { - authtoken: 'Test Auth' - } - }) - ContentstackClient({ http: axios }) - .login() - .then((response) => { - expect(response.user.authtoken).to.be.equal('Test Auth') - done() - }) - .catch(done) - }) - - it('Contentstack Client login success', done => { - nock(host) - .post('/user-session', {}) - .reply(200, { - user: { - authtoken: 'Test Auth' - } - }) + var mock = new MockAdapter(axios) + mock.onPost('/user-session').reply(200, { + user: { + authtoken: 'Test Auth' + } + }) ContentstackClient({ http: axios }) .login() .then((response) => { @@ -58,13 +36,12 @@ describe('Contentstack Client', () => { }) it('Contentstack Client get user info', done => { - nock(host) - .get('/user') - .reply(200, { - user: { - uid: 'test uid' - } - }) + var mock = new MockAdapter(axios) + mock.onGet('/user').reply(200, { + user: { + uid: 'test uid' + } + }) ContentstackClient({ http: axios }) .getUser() .then((user) => { @@ -75,11 +52,10 @@ describe('Contentstack Client', () => { }) it('Contentstack Client Logout with Authtoken', done => { - nock(host) - .delete('/user-session') - .reply(200, { - notice: 'You\'ve logged out successfully' - }) + var mock = new MockAdapter(axios) + mock.onDelete('/user-session').reply(200, { + notice: 'You\'ve logged out successfully' + }) ContentstackClient({ http: axios }) .logout('Test Auth') .then((response) => { @@ -90,11 +66,10 @@ describe('Contentstack Client', () => { }) it('Contentstack Client Logout', done => { - nock(host) - .delete('/user-session') - .reply(200, { - notice: 'You\'ve logged out successfully' - }) + var mock = new MockAdapter(axios) + mock.onDelete('/user-session').reply(200, { + notice: 'You\'ve logged out successfully' + }) axios.defaults.headers = { common: { authtoken: 'Authtoken' diff --git a/test/unit/Util-test.js b/test/unit/Util-test.js index af1d552d..d41bfe33 100644 --- a/test/unit/Util-test.js +++ b/test/unit/Util-test.js @@ -21,10 +21,28 @@ describe('Get User Agent', () => { platform: 'MacIntel' } } - const userAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1') - expect(userAgent.match(headerRegEx).length).to.be.equal(5) - expect(userAgent.indexOf('platform browser')).to.not.equal(-1) - expect(userAgent.indexOf('os macOS;')).to.not.equal(-1) + const macUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1') + expect(macUserAgent.match(headerRegEx).length).to.be.equal(5) + expect(macUserAgent.indexOf('platform browser')).to.not.equal(-1) + expect(macUserAgent.indexOf('os macOS;')).to.not.equal(-1) + + global.window.navigator.platform = 'Windows' + const windowsUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1') + expect(windowsUserAgent.match(headerRegEx).length).to.be.equal(5) + expect(windowsUserAgent.indexOf('platform browser')).to.not.equal(-1) + expect(windowsUserAgent.indexOf('os Windows;')).to.not.equal(-1) + + global.window.navigator = { userAgent: 'Android' } + const androidUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1') + expect(androidUserAgent.match(headerRegEx).length).to.be.equal(5) + expect(androidUserAgent.indexOf('platform browser')).to.not.equal(-1) + expect(androidUserAgent.indexOf('os Android;')).to.not.equal(-1) + + global.window.navigator = { platform: 'Linux' } + const linuxUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1') + expect(linuxUserAgent.match(headerRegEx).length).to.be.equal(5) + expect(linuxUserAgent.indexOf('platform browser')).to.not.equal(-1) + expect(linuxUserAgent.indexOf('os Linux;')).to.not.equal(-1) done() getUserAgentRewireApi.__ResetDependency__('isNode') @@ -40,7 +58,6 @@ describe('Get User Agent', () => { global.window = {} const userAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1') - expect(userAgent.match(headerRegEx).length).to.be.equal(3) expect(userAgent.indexOf('platform browser')).to.equal(-1) expect(userAgent.indexOf('os macOS;')).to.equal(-1) diff --git a/test/unit/apps-test.js b/test/unit/apps-test.js index ecb0ca43..a0923f32 100644 --- a/test/unit/apps-test.js +++ b/test/unit/apps-test.js @@ -147,9 +147,18 @@ describe('Contentstack apps test', () => { installations.items.forEach(installation => { checkInstallation(installation) }) - done() }) .catch(done) + + // Failing test + mock.onGet(`manifests/${uid}/installations`).reply(400, {}) + makeApp({ data: { uid } }) + .listInstallations() + .then() + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) }) it('app install test', done => { @@ -170,9 +179,18 @@ describe('Contentstack apps test', () => { expect(installation.target.uid).to.be.equal(installationMock.target.uid) expect(installation.organization_uid).to.be.equal(installationMock.organization_uid) expect(installation.uid).to.be.equal(installationMock.uid) - done() }) .catch(done) + + // Failing test + mock.onPost(`/manifests/${uid}/install`).reply(400, {}) + makeApp({ data: { uid } }) + .install({ targetUid, targetType }) + .then() + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) }) it('app upgrade test', done => { @@ -193,9 +211,18 @@ describe('Contentstack apps test', () => { expect(installation.target.uid).to.be.equal(installationMock.target.uid) expect(installation.organization_uid).to.be.equal(installationMock.organization_uid) expect(installation.uid).to.be.equal(installationMock.uid) - done() }) .catch(done) + + // Failing test + mock.onPut(`/manifests/${uid}/reinstall`).reply(400, {}) + makeApp({ data: { uid } }) + .upgrade({ targetUid, targetType }) + .then() + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) }) it('test fetch request for app uid', (done) => { diff --git a/test/unit/asset-test.js b/test/unit/asset-test.js index 184db299..35944cbb 100644 --- a/test/unit/asset-test.js +++ b/test/unit/asset-test.js @@ -170,6 +170,30 @@ describe('Contentstack Asset test', () => { .catch(done) }) + it('Asset create test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/assets').reply(400, {}) + const assetUpload = { + upload: path.join(__dirname, '../api/mock/customUpload.html'), + title: 'customasset', + description: 'Custom Asset Desc', + tags: ['Custom'], + parent_uid: 'UID' + } + const form = createFormData(assetUpload)() + var boundary = form.getBoundary() + + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) + makeAsset() + .create(assetUpload) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Asset replace test', done => { var mock = new MockAdapter(Axios) mock.onPut('/assets/UID').reply(200, { @@ -193,6 +217,25 @@ describe('Contentstack Asset test', () => { .catch(done) }) + it('Asset replace failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPut('/assets/UID').reply(400, {}) + const assetUpload = { + upload: path.join(__dirname, '../api/mock/customUpload.html'), + title: 'customasset', + description: 'Custom Asset Desc', + tags: ['Custom'], + parent_uid: 'UID' + } + makeAsset({ asset: { ...systemUidMock } }) + .replace(assetUpload) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Asset Query test', done => { var mock = new MockAdapter(Axios) mock.onGet('/assets').reply(200, { @@ -314,6 +357,44 @@ describe('Contentstack Asset test', () => { }) .catch(done) }) + + it('Asset download test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/asset_url_to_download').reply(200, { + asset: 'Downloaded asset' + }) + makeAsset({ + asset: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .download({ url: 'asset_url_to_download', responseType: 'blob' }) + .then((response) => { + expect(response.data.asset).to.be.equal('Downloaded asset') + done() + }) + .catch(done) + }) + + it('Asset download failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/asset_url_to_download').reply(200, { + asset: 'Downloaded asset' + }) + makeAsset({ + asset: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .download({ }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeAsset (data) { diff --git a/test/unit/auditLog-test.js b/test/unit/auditLog-test.js index 869d962d..9d742403 100644 --- a/test/unit/auditLog-test.js +++ b/test/unit/auditLog-test.js @@ -64,6 +64,18 @@ describe('Contentstack AuditLog test', () => { }) .catch(done) }) + + it('AuditLog fetch failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/audit-logs/UID').reply(400, {}) + makeAuditLog({ stackHeaders: stackHeadersMock, logs: { uid: 'UID' } }) + .fetch() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeAuditLog (data) { diff --git a/test/unit/branch-test.js b/test/unit/branch-test.js index c925f135..325205df 100644 --- a/test/unit/branch-test.js +++ b/test/unit/branch-test.js @@ -168,7 +168,7 @@ describe('Contentstack Branch test', () => { it('Branch compare all test', done => { var mock = new MockAdapter(axios) - mock.onGet('/stacks/branches_compare', { params: { base_branch: 'UID', compare_branch: 'dev', skip: 0, limit: 100 } }).reply(200, branchCompareAllMock) + mock.onGet('/stacks/branches_compare', { params: { base_branch: 'UID', compare_branch: 'dev' } }).reply(200, branchCompareAllMock) makeBranch({ branch: { ...systemUidMock @@ -176,7 +176,7 @@ describe('Contentstack Branch test', () => { stackHeaders: { ...stackHeadersMock, authtoken: 'authtoken' } }) .compare('dev') - .all({ skip: 0, limit: 100 }) + .all() .then((response) => { expect(response.branches.base_branch).to.eql(systemUidMock.uid) expect(response.branches.compare_branch).to.eql(branchCompareAllMock.branches.compare_branch) @@ -189,7 +189,7 @@ describe('Contentstack Branch test', () => { it('Branch compare content types test', done => { var mock = new MockAdapter(axios) - mock.onGet('/stacks/branches_compare/content_types', { params: { base_branch: 'UID', compare_branch: 'dev', skip: 0, limit: 100 } }).reply(200, branchCompareContentTypeMock) + mock.onGet('/stacks/branches_compare/content_types/contentTypeUID', { params: { base_branch: 'UID', compare_branch: 'dev', skip: 0, limit: 100 } }).reply(200, branchCompareContentTypeMock) makeBranch({ branch: { ...systemUidMock @@ -197,7 +197,28 @@ describe('Contentstack Branch test', () => { stackHeaders: { ...stackHeadersMock, authtoken: 'authtoken' } }) .compare('dev') - .contentTypes({ skip: 0, limit: 100 }) + .contentTypes({ skip: 0, limit: 100, uid: 'contentTypeUID' }) + .then((response) => { + expect(response.branches.base_branch).to.eql(systemUidMock.uid) + expect(response.branches.compare_branch).to.eql(branchCompareContentTypeMock.branches.compare_branch) + expect(response.diff).to.eql(branchCompareContentTypeMock.diff) + expect(response.next_url).to.eql(branchCompareContentTypeMock.next_url) + done() + }) + .catch(done) + }) + + it('Branch compare content types test without params', done => { + var mock = new MockAdapter(axios) + mock.onGet('/stacks/branches_compare/content_types', { params: { base_branch: 'UID', compare_branch: 'dev' } }).reply(200, branchCompareContentTypeMock) + makeBranch({ + branch: { + ...systemUidMock + }, + stackHeaders: { ...stackHeadersMock, authtoken: 'authtoken' } + }) + .compare('dev') + .contentTypes() .then((response) => { expect(response.branches.base_branch).to.eql(systemUidMock.uid) expect(response.branches.compare_branch).to.eql(branchCompareContentTypeMock.branches.compare_branch) @@ -210,7 +231,7 @@ describe('Contentstack Branch test', () => { it('Branch compare global fields test', done => { var mock = new MockAdapter(axios) - mock.onGet('/stacks/branches_compare/global_fields', { params: { base_branch: 'UID', compare_branch: 'dev', skip: 0, limit: 100 } }).reply(200, branchCompareGlobalFieldMock) + mock.onGet('/stacks/branches_compare/global_fields/globalFieldUID', { params: { base_branch: 'UID', compare_branch: 'dev', skip: 0, limit: 100 } }).reply(200, branchCompareGlobalFieldMock) makeBranch({ branch: { ...systemUidMock @@ -218,7 +239,28 @@ describe('Contentstack Branch test', () => { stackHeaders: { ...stackHeadersMock, authtoken: 'authtoken' } }) .compare('dev') - .globalFields({ skip: 0, limit: 100 }) + .globalFields({ skip: 0, limit: 100, uid: 'globalFieldUID' }) + .then((response) => { + expect(response.branches.base_branch).to.eql(systemUidMock.uid) + expect(response.branches.compare_branch).to.eql(branchCompareGlobalFieldMock.branches.compare_branch) + expect(response.diff).to.eql(branchCompareGlobalFieldMock.diff) + expect(response.next_url).to.eql(branchCompareGlobalFieldMock.next_url) + done() + }) + .catch(done) + }) + + it('Branch compare global fields test without params', done => { + var mock = new MockAdapter(axios) + mock.onGet('/stacks/branches_compare/global_fields', { params: { base_branch: 'UID', compare_branch: 'dev' } }).reply(200, branchCompareGlobalFieldMock) + makeBranch({ + branch: { + ...systemUidMock + }, + stackHeaders: { ...stackHeadersMock, authtoken: 'authtoken' } + }) + .compare('dev') + .globalFields() .then((response) => { expect(response.branches.base_branch).to.eql(systemUidMock.uid) expect(response.branches.compare_branch).to.eql(branchCompareGlobalFieldMock.branches.compare_branch) @@ -259,6 +301,34 @@ describe('Contentstack Branch test', () => { .catch(done) }) + it('Branch Merge All failing test', done => { + var mock = new MockAdapter(axios) + const params = { + base_branch: 'main', + compare_branch: 'dev', + default_merge_strategy: 'merge_prefer_base', + merge_comment: 'Merging dev into main', + no_revert: true + } + const mergeObj = { + item_merge_strategies: [ + { + uid: 'global_field_uid', + type: 'global_field', + merge_strategy: 'merge_prefer_base' + } + ] + } + mock.onPost('/stacks/branches_merge').reply(400, {}) + makeBranch({ stackHeaders: { ...stackHeadersMock, authtoken: 'authtoken' } }) + .merge(mergeObj, params) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Branch MergeQueue find test', done => { var mock = new MockAdapter(axios) mock.onGet('/stacks/branches_queue').reply(200, branchMergeQueueFindMock) diff --git a/test/unit/branchAlias-test.js b/test/unit/branchAlias-test.js index 4fd8bd99..e824819c 100644 --- a/test/unit/branchAlias-test.js +++ b/test/unit/branchAlias-test.js @@ -3,7 +3,7 @@ import { expect } from 'chai' import { describe, it } from 'mocha' import MockAdapter from 'axios-mock-adapter' import { branchAliasMock, checkSystemFields, noticeMock, stackHeadersMock, systemUidMock } from './mock/objects' -import { BranchAlias, BranchAliasCollection } from '../../lib/stack/branchAlias' +import { BranchAlias } from '../../lib/stack/branchAlias' describe('Contentstack BranchAlias test', () => { it('BranchAlias test without uid', done => { @@ -97,6 +97,23 @@ describe('Contentstack BranchAlias test', () => { .catch(done) }) + it('BranchAlias update failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPut('/stacks/branch_aliases/UID').reply(400, {}) + makeBranchAlias({ + branch_alias: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .createOrUpdate() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('BranchAlias fetch test', done => { var mock = new MockAdapter(Axios) mock.onGet('/stacks/branch_aliases/UID').reply(200, { @@ -118,6 +135,23 @@ describe('Contentstack BranchAlias test', () => { .catch(done) }) + it('BranchAlias fetch failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/stacks/branch_aliases/UID').reply(400, {}) + makeBranchAlias({ + branch_alias: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .fetch() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('BranchAlias delete test', done => { var mock = new MockAdapter(Axios) mock.onDelete('/stacks/branch_aliases/UID').reply(200, { diff --git a/test/unit/contentType-test.js b/test/unit/contentType-test.js index 9ca90da6..f12f7026 100644 --- a/test/unit/contentType-test.js +++ b/test/unit/contentType-test.js @@ -181,6 +181,23 @@ describe('Contentstack ContentType test', () => { .catch(done) }) + it('ContentType references failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/content_types/UID/references').reply(400, {}) + makeContentType({ + content_type: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .references() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('ContentType delete test', done => { var mock = new MockAdapter(Axios) mock.onDelete('/content_types/UID').reply(200, { @@ -259,6 +276,24 @@ describe('Contentstack ContentType test', () => { }) .catch(done) }) + + it('ContentType import failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/content_types/import').reply(400, {}) + const contentTypeUpload = { content_type: path.join(__dirname, '../api/mock/contentType.json') } + const form = createFormData(contentTypeUpload)() + var boundary = form.getBoundary() + + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) + makeContentType() + .import(contentTypeUpload) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeContentType (data) { diff --git a/test/unit/deployment-test.js b/test/unit/deployment-test.js index 96787557..e27b5c0e 100644 --- a/test/unit/deployment-test.js +++ b/test/unit/deployment-test.js @@ -86,9 +86,18 @@ describe('Contentstack hosting test', () => { deployments.items.forEach(deployment => { checkDeployment(deployment) }) - done() }) .catch(done) + + // Failing test + mock.onGet(`manifests/${uid}/hosting/deployments`).reply(400, {}) + makeDeployment({ app_uid: uid, organization_uid: organizationUid }) + .findAll({ skip: 10 }) + .then() + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) }) it('test create deployment from signed url', done => { @@ -105,10 +114,20 @@ describe('Contentstack hosting test', () => { .create({ uploadUid, fileType }) .then((deployment) => { checkDeployment(deployment) - done() }) .catch(done) + + // Failing test + mock.onPost(`manifests/${uid}/hosting/deployments`).reply(400, {}) + makeDeployment({ app_uid: uid, organization_uid: organizationUid }) + .create({ uploadUid, fileType }) + .then() + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) }) + it('test create deployment from signed url with advance options', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -140,12 +159,29 @@ describe('Contentstack hosting test', () => { makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid, organization_uid: organizationUid } }) .fetch() .then((deployment) => { + expect(deployment).to.be.instanceOf(Deployment) checkDeployment(deployment) done() }) .catch(done) }) + it('test get deployment from uid fail test', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + const organizationUid = appMock.organization_uid + const deploymentUid = latestLiveResponse.data.uid + mock.onGet(`manifests/${uid}/hosting/deployments/${deploymentUid}`).reply(400, {}) + + makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid, organization_uid: organizationUid } }) + .fetch() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('test get deployment logs from uid', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -168,12 +204,21 @@ describe('Contentstack hosting test', () => { expect(log.stage).to.be.equal(content.stage) expect(log.timestamp).to.be.equal(content.timestamp) }) - done() }) .catch(done) + + // Failing test + mock.onGet(`manifests/${uid}/hosting/deployments/${deploymentUid}/logs`).reply(400, {}) + makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid } }) + .logs() + .then() + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) }) - it('test get deployment logs from uid', done => { + it('signedDownloadUrl test', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid const organizationUid = appMock.organization_uid @@ -191,9 +236,18 @@ describe('Contentstack hosting test', () => { .then((download) => { expect(download.download_url).to.be.equal(content.download_url) expect(download.expires_in).to.be.equal(content.expires_in) - done() }) .catch(done) + + // Failing test + mock.onPost(`manifests/${uid}/hosting/deployments/${deploymentUid}/signedDownloadUrl`).reply(400, {}) + makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid } }) + .signedDownloadUrl() + .then() + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) }) }) diff --git a/test/unit/entry-test.js b/test/unit/entry-test.js index db87571d..0f48b4f6 100644 --- a/test/unit/entry-test.js +++ b/test/unit/entry-test.js @@ -1,3 +1,4 @@ +/* eslint-disable camelcase */ import path from 'path' import Axios from 'axios' import { expect } from 'chai' @@ -99,7 +100,7 @@ describe('Contentstack Entry test', () => { entryMock ] }) - makeEntry() + makeEntry({ stackHeaders: { organization_uid: 'org_uid' } }) .query() .find() .then((entry) => { @@ -184,7 +185,7 @@ describe('Contentstack Entry test', () => { ] } makeEntry({ entry: { ...systemUidMock } }) - .publish({ publishDetails }) + .publish({ publishDetails, locale: 'en-us', version: '3.2', scheduledAt: '01/01/2020' }) .then((entry) => { expect(entry.notice).to.be.equal(noticeMock.notice) done() @@ -236,6 +237,24 @@ describe('Contentstack Entry test', () => { .catch(done) }) + it('Entry import test failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/content_types/content_type_uid/entries/import?overwrite=false').reply(400, {}) + const entryUpload = { entry: path.join(__dirname, '../api/mock/entry.json') } + const form = createFormData(entryUpload.entry)() + var boundary = form.getBoundary() + + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) + makeEntry() + .import(entryUpload) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Entry import test Overwrite true', done => { var mock = new MockAdapter(Axios) mock.onPost('/content_types/content_type_uid/entries/import?overwrite=true').reply(200, { @@ -290,6 +309,26 @@ describe('Contentstack Entry test', () => { .catch(done) }) + it('Entry publish request failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/content_types/content_type_uid/entries/UID/workflow').reply(400, {}) + + const publishing_rule = { + uid: 'uid', + action: 'publish', // (‘publish’, ‘unpublish’, or ’both’) + status: 1, // (this could be ‘0’ for Approval Requested, ‘1’ for ‘Approval Accepted’, and ‘-1’ for ‘Approval Rejected’), + notify: false, + comment: 'Please review this.' + } + makeEntry({ entry: { ...systemUidMock } }) + .publishRequest({ publishing_rule, locale: 'en-us' }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Entry set Workflow stage test', done => { var mock = new MockAdapter(Axios) @@ -322,7 +361,37 @@ describe('Contentstack Entry test', () => { .catch(done) }) - it('Entry set Workflow stage test', done => { + it('Entry set Workflow stage failing test', done => { + var mock = new MockAdapter(Axios) + + mock.onPost('/content_types/content_type_uid/entries/UID/workflow').reply(400, {}) + + const workflow_stage = { + uid: 'uid', + comment: 'Please review this.', + due_date: 'Thu Dec 01 2018', + notify: true, + assigned_to: [{ + uid: 'user_uid', + name: 'Username', + email: 'user_email_id' + }], + assigned_by_roles: [{ + uid: 'role_uid', + name: 'Role name' + }] + } + + makeEntry({ entry: { ...systemUidMock } }) + .setWorkflowStage({ workflow_stage, locale: 'en-us' }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Entry set Workflow stage test with stackHeaders', done => { var mock = new MockAdapter(Axios) mock.onPost('/content_types/content_type_uid/entries/UID/workflow').reply(200, { @@ -379,6 +448,7 @@ describe('Contentstack Entry test', () => { function makeEntry (data) { return new Entry(Axios, { content_type_uid: 'content_type_uid', ...data }) + // return new Stack(Axios).contentType('content_type_uid').entry() } function checkEntry (entry) { diff --git a/test/unit/extension-test.js b/test/unit/extension-test.js index 4a133747..7605f02e 100644 --- a/test/unit/extension-test.js +++ b/test/unit/extension-test.js @@ -186,6 +186,26 @@ describe('Contentstack Extension test', () => { .catch(done) }) + it('Extension upload failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/extensions').reply(400, {}) + + const extensionUpload = { upload: path.join(__dirname, '../api/mock/customUpload.html') } + const form = createExtensionFormData(extensionUpload)() + var boundary = form.getBoundary() + + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) + + makeExtension(extensionUpload) + .upload() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Extension upload test string tags', done => { var mock = new MockAdapter(Axios) mock.onPost('/extensions').reply(200, { diff --git a/test/unit/globalField-test.js b/test/unit/globalField-test.js index 6d694c33..dd2f69a9 100644 --- a/test/unit/globalField-test.js +++ b/test/unit/globalField-test.js @@ -185,6 +185,24 @@ describe('Contentstack GlobalField test', () => { }) .catch(done) }) + + it('Global Field import failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/global_fields/import').reply(400, {}) + const gfUpload = { global_field: path.join(__dirname, '../api/mock/globalfield.json') } + const form = createFormData(gfUpload)() + var boundary = form.getBoundary() + + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) + makeGlobalField() + .import() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeGlobalField (data) { diff --git a/test/unit/hosting-test.js b/test/unit/hosting-test.js index 6a8d46fc..6e948e66 100644 --- a/test/unit/hosting-test.js +++ b/test/unit/hosting-test.js @@ -83,6 +83,19 @@ describe('Contentstack hosting test', () => { .catch(done) }) + it('fail test hosting isEnable request', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onGet(`manifests/${uid}/hosting`).reply(400, {}) + makeHosting({ app_uid: uid }) + .isEnable() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('test set hosting enable', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -99,6 +112,20 @@ describe('Contentstack hosting test', () => { .catch(done) }) + it('fail test set hosting enable', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onPatch(`manifests/${uid}/hosting/enable`).reply(400, {}) + + makeHosting({ app_uid: uid }) + .enable() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('test set hosting disble', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -115,6 +142,20 @@ describe('Contentstack hosting test', () => { .catch(done) }) + it('fail test set hosting disble', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onPatch(`manifests/${uid}/hosting/disable`).reply(400, {}) + + makeHosting({ app_uid: uid }) + .disable() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('test create signed url for hosting', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -133,6 +174,20 @@ describe('Contentstack hosting test', () => { .catch(done) }) + it('fail test create signed url for hosting', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onPost(`manifests/${uid}/hosting/signedUploadUrl`).reply(400, {}) + + makeHosting({ app_uid: uid }) + .createUploadUrl() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('test latest deployment for hosting', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -156,6 +211,20 @@ describe('Contentstack hosting test', () => { }) .catch(done) }) + + it('fail test latest deployment for hosting', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onGet(`manifests/${uid}/hosting/latestLiveDeployment`).reply(400, {}) + + makeHosting({ app_uid: uid }) + .latestLiveDeployment() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeHosting (data, param = {}) { diff --git a/test/unit/index.js b/test/unit/index.js index 8917ba4d..6cab4905 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -1,7 +1,7 @@ +require('./Util-test') require('./concurrency-Queue-test') require('./ContentstackClient-test') require('./ContentstackHTTPClient-test') -require('./Util-test') require('./contentstack-test') require('./contentstackError-test') require('./contentstackCollection-test') diff --git a/test/unit/installation-test.js b/test/unit/installation-test.js index 5cad138d..72b1d1a3 100644 --- a/test/unit/installation-test.js +++ b/test/unit/installation-test.js @@ -266,16 +266,6 @@ describe('Contentstack apps installation test', () => { .catch(done) }) - it('should get object of WebHook class when webhooks function is called with uid', () => { - const webHook = makeInstallation({ data: { uid: 'uid' } }).webhooks('webhookUid') - - expect(webHook).to.be.instanceOf(WebHooks) - expect(webHook.uid).to.be.equal('webhookUid') - expect(webHook.listExecutionLogs).to.not.equal(undefined) - expect(webHook.getExecutionLog).to.not.equal(undefined) - expect(webHook.retryExecution).to.not.equal(undefined) - }) - it('getInstalledApps call should fetch all the installed apps in your Contentstack organization', done => { const mock = new MockAdapter(Axios) mock.onGet(`/installations/view/apps`).reply(200, { @@ -320,6 +310,192 @@ describe('Contentstack apps installation test', () => { }) .catch(done) }) + + it('Get app installation failing test', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onGet(`/installations`).reply(400, {}) + + makeInstallation({ data: { app_uid: uid } }).fetchAll() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Fetch Installation failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onGet(`/installations/${uid}`).reply(400, {}) + + makeInstallation({ data: { uid } }) + .fetch() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Get installation installationData failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onGet(`/installations/${uid}/installationData`).reply(400, {}) + + makeInstallation({ data: { uid } }) + .installationData() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Get installation configuration failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onGet(`/installations/${uid}/configuration`).reply(400, {}) + + makeInstallation({ data: { uid } }) + .configuration() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Set installation configuration failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onPut(`/installations/${uid}/configuration`).reply(400, {}) + + makeInstallation({ data: { uid } }) + .setConfiguration({}) + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Get installation server config failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onGet(`/installations/${uid}/server-configuration`).reply(400, {}) + + makeInstallation({ data: { uid } }) + .serverConfig() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Get installation installationData failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onPut(`/installations/${uid}/server-configuration`).reply(400, {}) + + makeInstallation({ data: { uid } }) + .setServerConfig({}) + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Update Installation failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onPut(`/installations/${uid}`).reply(400, {}) + makeInstallation({ data: { uid } }) + .update() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('Uninstall Installation failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationMock.uid + mock.onDelete(`/installations/${uid}`).reply(400, {}) + makeInstallation({ data: { uid } }) + .uninstall() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('getConfigLocation call should retrieve uilocation configuration details of an installation failing test', done => { + const mock = new MockAdapter(Axios) + const uid = installationConfigLocationMock.uid + mock.onGet(`/installations/${uid}/locations/configuration`).reply(400, {}) + + makeInstallation({ data: { uid } }) + .getConfigLocation() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('getInstalledApps call should fetch all the installed apps in your Contentstack organization failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet(`/installations/view/apps`).reply(400, {}) + + makeInstallation({ data: {} }) + .getInstalledApps() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('getInstalledUsers call should fetch all the installed Users in your Contentstack organization failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet(`/installations/view/users`).reply(400, {}) + + makeInstallation({ data: {} }) + .getInstalledUsers() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('getInstalledStacks call should fetch all the installed Stacks in your Contentstack organization failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet(`/installations/view/stacks`).reply(400, {}) + + makeInstallation({ data: {} }) + .getInstalledStacks() + .then(done) + .catch((error) => { + expect(error).to.not.equal(undefined) + done() + }) + }) + + it('should get object of WebHook class when webhooks function is called with uid', () => { + const webHook = makeInstallation({ data: { uid: 'uid' } }).webhooks('webhookUid') + + expect(webHook).to.be.instanceOf(WebHooks) + expect(webHook.uid).to.be.equal('webhookUid') + expect(webHook.listExecutionLogs).to.not.equal(undefined) + expect(webHook.getExecutionLog).to.not.equal(undefined) + expect(webHook.retryExecution).to.not.equal(undefined) + }) }) export function checkInstallation (installation) { diff --git a/test/unit/oauth-test.js b/test/unit/oauth-test.js index eb502898..8e87add5 100644 --- a/test/unit/oauth-test.js +++ b/test/unit/oauth-test.js @@ -30,6 +30,22 @@ describe('Contentstack app oauth', () => { .catch(done) }) + it('Get oAuth configuration failing test', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onGet(`/manifests/${uid}/oauth`).reply(400, {}) + + const oauthObj = makeOauth({ app_uid: uid, organization_uid: 'organization_uid' }) + expect(oauthObj.params.organization_uid).to.be.equal('organization_uid') + oauthObj + .fetch() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Update oAuth configuration test', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -52,6 +68,21 @@ describe('Contentstack app oauth', () => { .catch(done) }) + it('Update oAuth configuration failing test', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onPut(`/manifests/${uid}/oauth`).reply(400, {}) + + const config = { ...oAuthMock } + makeOauth({ app_uid: uid }) + .update({ config }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('List Scopes', done => { const mock = new MockAdapter(Axios) const uid = appMock.uid @@ -68,6 +99,19 @@ describe('Contentstack app oauth', () => { }) .catch(done) }) + + it('List Scopes failing test', done => { + const mock = new MockAdapter(Axios) + const uid = appMock.uid + mock.onGet(`/manifests/oauth/scopes`).reply(400, {}) + makeOauth({ app_uid: uid }) + .getScopes() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeOauth (data) { diff --git a/test/unit/organization-test.js b/test/unit/organization-test.js index 2970147f..ba1351ef 100644 --- a/test/unit/organization-test.js +++ b/test/unit/organization-test.js @@ -157,6 +157,23 @@ describe('Organization Test', () => { .catch(done) }) + it('Organization Stacks fetch failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet(`/organizations/${systemUidMock.uid}/stacks`).reply(400, {}) + makeOrganization({ + organization: { + ...systemUidMock, + org_roles: [adminRoleMock] + } + }) + .stacks() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Organization Transfer Ownership', done => { const mock = new MockAdapter(Axios) mock.onPost(`/organizations/${systemUidMock.uid}/transfer_ownership`).reply(200, { ...noticeMock }) @@ -174,6 +191,23 @@ describe('Organization Test', () => { .catch(done) }) + it('Organization Transfer Ownership failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost(`/organizations/${systemUidMock.uid}/transfer_ownership`).reply(400, {}) + makeOrganization({ + organization: { + ...systemUidMock, + org_roles: [adminRoleMock] + } + }) + .transferOwnership('email') + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Organization add User', done => { const mock = new MockAdapter(Axios) mock.onPost(`/organizations/${systemUidMock.uid}/share`).reply(200, { ...noticeMock, shares: [userMock] }) @@ -192,6 +226,23 @@ describe('Organization Test', () => { .catch(done) }) + it('Organization add User failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost(`/organizations/${systemUidMock.uid}/share`).reply(400, {}) + makeOrganization({ + organization: { + ...systemUidMock, + org_roles: [adminRoleMock] + } + }) + .addUser({}) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Organization Get all invitation', done => { const mock = new MockAdapter(Axios) mock.onGet(`/organizations/${systemUidMock.uid}/share`).reply(200, { ...noticeMock, shares: [userMock] }) @@ -210,6 +261,23 @@ describe('Organization Test', () => { .catch(done) }) + it('Organization Get all invitation failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet(`/organizations/${systemUidMock.uid}/share`).reply(400, {}) + makeOrganization({ + organization: { + ...systemUidMock, + org_roles: [adminRoleMock] + } + }) + .getInvitations({}) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Organization Resend Invitation', done => { const inviteID = 'inviteID' const mock = new MockAdapter(Axios) @@ -228,6 +296,24 @@ describe('Organization Test', () => { .catch(done) }) + it('Organization Resend Invitation failing test', done => { + const inviteID = 'inviteID' + const mock = new MockAdapter(Axios) + mock.onGet(`/organizations/${systemUidMock.uid}/${inviteID}/resend_invitation`).reply(400, {}) + makeOrganization({ + organization: { + ...systemUidMock, + org_roles: [adminRoleMock] + } + }) + .resendInvitation(inviteID) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Organization Roles', done => { const mock = new MockAdapter(Axios) mock.onGet(`/organizations/${systemUidMock.uid}/roles`).reply(200, { roles: [adminRoleMock, roleMock] }) @@ -246,6 +332,23 @@ describe('Organization Test', () => { }) .catch(done) }) + + it('Organization Roles failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet(`/organizations/${systemUidMock.uid}/roles`).reply(400, {}) + makeOrganization({ + organization: { + ...systemUidMock, + org_roles: [adminRoleMock] + } + }) + .roles() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeOrganization (params = {}) { diff --git a/test/unit/query-test.js b/test/unit/query-test.js index 802a753c..f491809b 100644 --- a/test/unit/query-test.js +++ b/test/unit/query-test.js @@ -72,6 +72,42 @@ describe('Contentstack Query test', () => { }) .catch(done) }) + + it('Query find failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet('query').reply(400, {}) + makeQuery({}, stackHeadersMock) + .find() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Query findOne failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet('query').reply(400, {}) + makeQuery({}, stackHeadersMock) + .findOne() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Query count failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet('query').reply(400, {}) + makeQuery({}, stackHeadersMock) + .count() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeQuery (param = null, stackHeaders = null) { diff --git a/test/unit/release-test.js b/test/unit/release-test.js index 4cc3d6b8..66a55c9b 100644 --- a/test/unit/release-test.js +++ b/test/unit/release-test.js @@ -200,6 +200,32 @@ describe('Contentstack Release test', () => { .catch(done) }) + it('Release deploy failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/releases/UID/deploy').reply(400, {}) + makeRelease({ + release: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .deploy({ environments: [ + 'production', + 'uat' + ], + locales: [ + 'en-us', + 'ja-jp' + ], + scheduledAt: '2018-12-12T13:13:13:122Z', + action: 'publish' }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Release clone test', done => { var mock = new MockAdapter(Axios) mock.onPost('/releases/UID/clone').reply(200, { @@ -221,6 +247,23 @@ describe('Contentstack Release test', () => { }) .catch(done) }) + + it('Release clone test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/releases/UID/clone').reply(400, {}) + makeRelease({ + release: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .clone({ name: 'New Clone Name', description: 'New Desc' }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeRelease (data) { diff --git a/test/unit/stack-test.js b/test/unit/stack-test.js index b61d4ade..21c56af3 100644 --- a/test/unit/stack-test.js +++ b/test/unit/stack-test.js @@ -230,7 +230,6 @@ describe('Contentstack Stack test', () => { expect(stack.organization_uid).to.be.equal(undefined) expect(stack.stackHeaders).to.not.equal(undefined) expect(stack.stackHeaders.api_key).to.be.equal('API_KEY') - expect(stack.stackHeaders.authorization).to.be.equal('Management_Token') expect(stack.api_key).to.be.equal('API_KEY') expect(stack.create).to.be.equal(undefined) expect(stack.query).to.be.equal(undefined) @@ -306,7 +305,6 @@ describe('Contentstack Stack test', () => { expect(stack.organization_uid).to.be.equal(undefined) expect(stack.stackHeaders).to.not.equal(undefined) expect(stack.stackHeaders.api_key).to.be.equal('API_KEY') - expect(stack.stackHeaders.authorization).to.be.equal('Management_Token') expect(stack.branch_name).to.be.equal('branch') expect(stack.api_key).to.be.equal('API_KEY') expect(stack.create).to.be.equal(undefined) @@ -845,24 +843,65 @@ describe('Contentstack Stack test', () => { }) .catch(done) }) - // it('Update users roles in Stack test', done => { - // const mock = new MockAdapter(Axios) - // mock.onGet('/stacks').reply(200, { - // notice: "The roles were applied successfully.", - // }) - // makeStack({ - // stack: { - // api_key: 'stack_api_key' - // } - // }) - // .updateUsersRoles({ user_id: ['role1', 'role2']}) - // .then((response) => { - // expect(response.notice).to.be.equal(noticeMock.notice) - // done() - // }) - // .catch(done) - // }) + it('Stack users failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet('/stacks').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .users() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Update users roles in Stack test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/users/roles').reply(200, { + notice: 'The roles were applied successfully.', + users: [ + { + uid: 'user_uid', + roles: [ + 'role_uid1', + 'role_uid2' + ] + } + ] + }) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .updateUsersRoles({ user_id: ['role1', 'role2'] }) + .then((response) => { + expect(response.notice).to.be.equal('The roles were applied successfully.') + done() + }) + .catch(done) + }) + + it('Fail in Update users roles in Stack test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/users/roles').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .updateUsersRoles({ user_id: ['role1', 'role2'] }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) it('Stack transfer ownership test', done => { const mock = new MockAdapter(Axios) @@ -1001,6 +1040,118 @@ describe('Contentstack Stack test', () => { }) .catch(done) }) + + it('Stack transfer ownership failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/transfer_ownership').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .transferOwnership() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Stack settings failing test', done => { + const mock = new MockAdapter(Axios) + mock.onGet('/stacks/settings').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .settings() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Stack reset settings failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/settings').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .resetSettings() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Stack add settings failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/settings').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .addSettings() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Stack share failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/share').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .share(['test@email.id'], { 'test@email.id': ['test roles'] }) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Stack share none failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/share').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .share() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Stack unshare failing test', done => { + const mock = new MockAdapter(Axios) + mock.onPost('/stacks/unshare').reply(400, {}) + makeStack({ + stack: { + api_key: 'stack_api_key' + } + }) + .unShare('test@email.id') + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeStack (data) { diff --git a/test/unit/user-test.js b/test/unit/user-test.js index 2d0c6318..a68e113d 100644 --- a/test/unit/user-test.js +++ b/test/unit/user-test.js @@ -162,25 +162,40 @@ describe('Contentstack User test', () => { }) user.getTasks() - .then((userTasks) => { - const assignment = userTasks.asassignments - expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) - expect(assignment.content_type).to.be.equal("CT_UID") - expect(assignment.entry_uid).to.be.equal("ETR_UID") - expect(assignment.locale).to.be.equal("en-us") - expect(assignment.org_uid).to.be.equal("orgUID") - expect(assignment.type).to.be.equal("workflow_stage") - expect(assignment.entry_locale).to.be.equal("en-us") - expect(assignment.version).to.be.equal(1) - expect(assignment.assigned_to[0]).to.be.equal("user_UID") - expect(assignment.assigned_at).to.be.equal("assign_date") - expect(assignment.assigned_by).to.be.equal("assign_by") - expect(assignment.due_date).to.be.equal("due_date") - done() - }) - .catch(done) + .then((userTasks) => { + const assignment = userTasks.asassignments + expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) + expect(assignment.content_type).to.be.equal('CT_UID') + expect(assignment.entry_uid).to.be.equal('ETR_UID') + expect(assignment.locale).to.be.equal('en-us') + expect(assignment.org_uid).to.be.equal('orgUID') + expect(assignment.type).to.be.equal('workflow_stage') + expect(assignment.entry_locale).to.be.equal('en-us') + expect(assignment.version).to.be.equal(1) + expect(assignment.assigned_to[0]).to.be.equal('user_UID') + expect(assignment.assigned_at).to.be.equal('assign_date') + expect(assignment.assigned_by).to.be.equal('assign_by') + expect(assignment.due_date).to.be.equal('due_date') + done() + }) + .catch(done) }) + it('User get task failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/user/assignments').reply(400, {}) + const user = new User(Axios, { user: { + authtoken: 'authtoken' + } + }) + + user.getTasks() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) it('User get task with params test', done => { var mock = new MockAdapter(Axios) @@ -194,24 +209,24 @@ describe('Contentstack User test', () => { } }) - user.getTasks({sort: 'sort'}) - .then((userTasks) => { - const assignment = userTasks.asassignments - expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) - expect(assignment.content_type).to.be.equal("CT_UID") - expect(assignment.entry_uid).to.be.equal("ETR_UID") - expect(assignment.locale).to.be.equal("en-us") - expect(assignment.org_uid).to.be.equal("orgUID") - expect(assignment.type).to.be.equal("workflow_stage") - expect(assignment.entry_locale).to.be.equal("en-us") - expect(assignment.version).to.be.equal(1) - expect(assignment.assigned_to[0]).to.be.equal("user_UID") - expect(assignment.assigned_at).to.be.equal("assign_date") - expect(assignment.assigned_by).to.be.equal("assign_by") - expect(assignment.due_date).to.be.equal("due_date") - done() - }) - .catch(done) + user.getTasks({ sort: 'sort' }) + .then((userTasks) => { + const assignment = userTasks.asassignments + expect(assignment.api_key).to.be.equal(stackHeadersMock.api_key) + expect(assignment.content_type).to.be.equal('CT_UID') + expect(assignment.entry_uid).to.be.equal('ETR_UID') + expect(assignment.locale).to.be.equal('en-us') + expect(assignment.org_uid).to.be.equal('orgUID') + expect(assignment.type).to.be.equal('workflow_stage') + expect(assignment.entry_locale).to.be.equal('en-us') + expect(assignment.version).to.be.equal(1) + expect(assignment.assigned_to[0]).to.be.equal('user_UID') + expect(assignment.assigned_at).to.be.equal('assign_date') + expect(assignment.assigned_by).to.be.equal('assign_by') + expect(assignment.due_date).to.be.equal('due_date') + done() + }) + .catch(done) }) }) diff --git a/test/unit/webhook-test.js b/test/unit/webhook-test.js index 6b2bff63..0de9ddf6 100644 --- a/test/unit/webhook-test.js +++ b/test/unit/webhook-test.js @@ -238,6 +238,23 @@ describe('Contentstack Webhook test', () => { .catch(done) }) + it('Webhook executions test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/webhooks/UID/executions').reply(400, {}) + makeWebhook({ + webhook: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .executions() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Webhook executions params test', done => { var mock = new MockAdapter(Axios) mock.onGet('/webhooks/UID/executions').reply(200, { @@ -317,6 +334,41 @@ describe('Contentstack Webhook test', () => { }) .catch(done) }) + + it('Webhook retry failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/webhooks/UID/retry').reply(400, {}) + makeWebhook({ + webhook: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .retry('exe_id') + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('Webhook import failing test', done => { + var mock = new MockAdapter(Axios) + mock.onPost('/webhooks/import').reply(400, {}) + const webhookUpload = { webhook: path.join(__dirname, '../api/mock/customUpload.html') } + const form = createFormData(webhookUpload)() + var boundary = form.getBoundary() + + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) + makeWebhook() + .import(webhookUpload) + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) function makeWebhook (data) { diff --git a/test/unit/webhooks-test.js b/test/unit/webhooks-test.js index 36f2e8b5..ef5b30ed 100644 --- a/test/unit/webhooks-test.js +++ b/test/unit/webhooks-test.js @@ -80,6 +80,54 @@ describe('Installation WebHook function', () => { }) .catch(done) }) + + it('should fail in listing all the execution logs when listExecutionLogs function is called', (done) => { + const mockClient = new MockAdapter(Axios) + const url = 'installations/installationUid/webhooks/uid/executions' + + mockClient.onGet(url).reply(400, {}) + webHookObj({ + installationUid: 'installationUid', uid: 'uid' + }) + .listExecutionLogs() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('should fail to get detailed of an execution when execution uid is passed', (done) => { + const mockClient = new MockAdapter(Axios) + const url = 'installations/installationUid/webhooks/uid/executions/execUid' + + mockClient.onGet(url).reply(400, {}) + webHookObj({ + installationUid: 'installationUid', uid: 'uid' + }) + .getExecutionLog('execUid') + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + + it('should fail in retry execution and get data when execution uid is passed', (done) => { + const mockClient = new MockAdapter(Axios) + const url = 'installations/installationUid/webhooks/uid/executions/execUid/retry' + + mockClient.onPost(url).reply(400, {}) + webHookObj({ + installationUid: 'installationUid', uid: 'uid' + }) + .retryExecution('execUid') + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) }) const webHookObj = (data) => { diff --git a/test/unit/workflow-test.js b/test/unit/workflow-test.js index 63911e21..a0798870 100644 --- a/test/unit/workflow-test.js +++ b/test/unit/workflow-test.js @@ -246,6 +246,23 @@ describe('Contentstack Workflow test', () => { .catch(done) }) + it('Workflow disable failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/workflows/UID/disable').reply(400, {}) + makeWorkflow({ + workflow: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .disable() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) + it('Workflow enable test', done => { var mock = new MockAdapter(Axios) mock.onGet('/workflows/UID/enable').reply(200, { @@ -269,6 +286,22 @@ describe('Contentstack Workflow test', () => { .catch(done) }) + it('Workflow enable failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/workflows/UID/enable').reply(400, {}) + makeWorkflow({ + workflow: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .enable() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) it('Workflow content type get publish rules', done => { var mock = new MockAdapter(Axios) @@ -288,8 +321,7 @@ describe('Contentstack Workflow test', () => { .catch(done) }) - - it('Workflow content type get publish rules', done => { + it('Workflow content type get publish rules with params', done => { var mock = new MockAdapter(Axios) mock.onGet('/workflows/content_type/ct_UID').reply(200, { publishing_rules: [ @@ -297,19 +329,32 @@ describe('Contentstack Workflow test', () => { ] }) makeWorkflow().contentType('ct_UID') - .getPublishRules({ action: "publish", locale: "en-us" }) + .getPublishRules({ action: 'publish', locale: 'en-us' }) .then((response) => { checkPublishRules(response.items[0]) done() }) .catch(done) }) -}) + it('Workflow content type get publish rules failing test', done => { + var mock = new MockAdapter(Axios) + mock.onGet('/workflows/content_type/ct_UID').reply(400, {}) + makeWorkflow({ + stackHeaders: stackHeadersMock + }).contentType('ct_UID') + .getPublishRules() + .then(done) + .catch((error) => { + expect(error).to.not.equal(null) + done() + }) + }) +}) function makeWorkflow (data) { - return new Workflow(Axios, data) - } + return new Workflow(Axios, data) +} function checkWorkflow (workflow) { checkSystemFields(workflow) @@ -325,7 +370,6 @@ function checkPublishRules (publishRules) { checkSystemFields(publishRules) expect(publishRules.locale).to.be.equal('en-us') expect(publishRules.action).to.be.equal('publish') - expect(publishRules.environment).to.be.equal("env") - expect(publishRules.workflow_stage).to.be.equal("stage") + expect(publishRules.environment).to.be.equal('env') + expect(publishRules.workflow_stage).to.be.equal('stage') } - \ No newline at end of file