From d80f1a49b1eba9deac2c7f0618ce06e6a8d5da96 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 12 Mar 2025 11:44:38 +0530 Subject: [PATCH 1/4] fix: linting errors --- .eslintrc.js | 8 +- .github/workflows/lint-check.yml | 25 + lib/app/installation/index.js | 2 +- lib/contentstackCollection.js | 4 +- lib/core/concurrency-queue.js | 2 +- lib/entity.js | 42 +- lib/stack/bulkOperation/index.js | 79 ++- lib/stack/contentType/entry/index.js | 44 +- lib/stack/contentType/entry/variants/index.js | 132 ++-- lib/stack/contentType/index.js | 8 +- lib/stack/globalField/index.js | 86 ++- lib/stack/index.js | 23 +- lib/stack/release/index.js | 2 +- lib/stack/release/items/index.js | 39 +- lib/stack/variantGroup/index.js | 12 +- lib/stack/variantGroup/variants/index.js | 13 +- lib/stack/variants/index.js | 10 +- lib/stack/workflow/publishRules/index.js | 11 +- package-lock.json | 59 ++ package.json | 1 + sanity-report-dev11.js | 76 +-- test/api/app-test.js | 2 - test/api/branch-test.js | 22 +- test/api/branchAlias-test.js | 5 +- test/api/bulkOperation-test.js | 42 +- test/api/contentType-test.js | 2 +- test/api/entry-test.js | 34 +- test/api/mock/managementToken.js | 133 ++-- test/api/mock/role.js | 8 +- test/api/mock/variantGroup.js | 152 ++--- test/api/mock/variants.js | 84 +-- test/api/mock/workflow.js | 12 +- test/api/taxonomy-test.js | 1 - test/api/terms-test.js | 32 +- test/api/ungroupedVariants-test.js | 19 +- test/api/variantGroup-test.js | 2 +- test/api/variants-test.js | 4 +- test/sanity-check/api/branch-test.js | 20 +- test/sanity-check/api/contentType-test.js | 2 - test/sanity-check/api/entry-test.js | 2 +- test/sanity-check/api/entryVariants-test.js | 246 ++++--- test/sanity-check/api/globalfield-test.js | 161 +++-- test/sanity-check/api/organization-test.js | 4 +- test/sanity-check/api/release-test.js | 520 +++++++-------- test/sanity-check/api/role-test.js | 20 - test/sanity-check/api/team-test.js | 10 +- test/sanity-check/api/terms-test.js | 24 +- .../api/ungroupedVariants-test.js | 20 +- test/sanity-check/api/variantGroup-test.js | 9 +- test/sanity-check/api/variants-test.js | 14 +- test/sanity-check/mock/globalfield.js | 98 +-- test/sanity-check/mock/variantEntry.js | 54 +- test/sanity-check/mock/variantGroup.js | 152 ++--- test/sanity-check/mock/variants.js | 84 +-- test/unit/asset-test.js | 3 +- test/unit/branchAlias-test.js | 2 +- test/unit/bulkOperation-test.js | 226 +++---- test/unit/concurrency-Queue-test.js | 31 +- test/unit/entry-test.js | 80 +-- test/unit/globalField-test.js | 620 +++++++++--------- test/unit/mock/objects.js | 399 ++++++----- test/unit/publishRules-test.js | 45 +- test/unit/release-test.js | 36 +- test/unit/role-test.js | 2 +- test/unit/stack-test.js | 50 +- test/unit/taxonomy-test.js | 3 +- test/unit/ungroupedVariants-test.js | 4 +- test/unit/variantGroup-test.js | 21 +- test/unit/variants-entry-test.js | 293 +++++---- test/unit/variantsWithVariantsGroup-test.js | 39 +- webpack/webpack.web.js | 2 +- 71 files changed, 2285 insertions(+), 2243 deletions(-) create mode 100644 .github/workflows/lint-check.yml diff --git a/.eslintrc.js b/.eslintrc.js index f6a61a11..3c97ec47 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,8 +1,7 @@ module.exports = { - // "env": { - // "browser": true, - // "amd": true - // }, + env: { + "es2020": true + }, extends: 'standard', // "globals": { // "Atomics": "readonly", @@ -15,6 +14,7 @@ module.exports = { // "ecmaVersion": 2015, // "sourceType": "module" // }, + parser: "@babel/eslint-parser", // Use Babel parser to handle modern JS syntax plugins: [ 'standard', 'promise' diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml new file mode 100644 index 00000000..08a58777 --- /dev/null +++ b/.github/workflows/lint-check.yml @@ -0,0 +1,25 @@ +name: Lint Check on PR + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '22.x' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm install + + - name: Run ESLint + run: npm run lint diff --git a/lib/app/installation/index.js b/lib/app/installation/index.js index 20798310..b84453cf 100644 --- a/lib/app/installation/index.js +++ b/lib/app/installation/index.js @@ -250,4 +250,4 @@ export function InstallationCollection (http, data) { return obj.map((installationData) => { return new Installation(http, { data: installationData }) }) -} \ No newline at end of file +} diff --git a/lib/contentstackCollection.js b/lib/contentstackCollection.js index b03fd7be..f61a8645 100644 --- a/lib/contentstackCollection.js +++ b/lib/contentstackCollection.js @@ -10,8 +10,8 @@ export default class ContentstackCollection { if (http?.httpClientParams?.headers?.includeResHeaders === true) { data.stackHeaders = { ...data.stackHeaders, - responseHeaders: response.headers, - }; + responseHeaders: response.headers + } } if (wrapperCollection) { this.items = wrapperCollection(http, data) diff --git a/lib/core/concurrency-queue.js b/lib/core/concurrency-queue.js index e27c5fd1..be36c2b7 100644 --- a/lib/core/concurrency-queue.js +++ b/lib/core/concurrency-queue.js @@ -156,7 +156,7 @@ export function ConcurrencyQueue ({ axios, config }) { message: 'Unable to refresh token', name: 'Token Error', config: queueItem.request, - stack: (error instanceof Error) ? error.stack : null, + stack: (error instanceof Error) ? error.stack : null }) }) this.queue = [] diff --git a/lib/entity.js b/lib/entity.js index 47d1a81b..bece8aba 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -46,13 +46,13 @@ export const publishUnpublish = async (http, url, httpBody, headers, locale = nu if (response.data) { const data = response.data || {} if (headers) { - data.stackHeaders = headers; + data.stackHeaders = headers } if (http?.httpClientParams?.headers?.includeResHeaders === true) { data.stackHeaders = { ...data.stackHeaders, - responseHeaders: response.headers, - }; + responseHeaders: response.headers + } } return data } else { @@ -81,10 +81,10 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me export const create = ({ http, params }) => { return async function (data, param) { - this.stackHeaders = { - ...this.stackHeaders, + this.stackHeaders = { + ...this.stackHeaders, ...(http.httpClientParams.headers?.api_version && { api_version: http.httpClientParams.headers.api_version }) - }; + } const headers = { headers: { ...cloneDeep(params), @@ -152,8 +152,8 @@ export const update = (http, type, params = {}) => { delete json.updated_by delete json.updated_at if (type) { - updateData[type] = json; - if (type === "entry") updateData[type] = cleanAssets(updateData[type]); + updateData[type] = json + if (type === 'entry') updateData[type] = cleanAssets(updateData[type]) } else { updateData = json } @@ -257,7 +257,7 @@ export const fetchAll = (http, wrapperCollection, params = {}) => { } } -export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid, http) { +export function parseData (response, stackHeaders, contentTypeUID, taxonomyUid, http) { const data = response.data || {} if (stackHeaders) { data.stackHeaders = stackHeaders @@ -265,14 +265,14 @@ export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid, if (contentTypeUID) { data.content_type_uid = contentTypeUID } - if (taxonomy_uid) { - data.taxonomy_uid = taxonomy_uid + if (taxonomyUid) { + data.taxonomy_uid = taxonomyUid } if (http?.httpClientParams?.headers?.includeResHeaders === true) { data.stackHeaders = { ...data.stackHeaders, - responseHeaders: response.headers, - }; + responseHeaders: response.headers + } } return data } @@ -332,22 +332,22 @@ export const move = (http, type, force = false, params = {}) => { } function isAsset (data) { - const element = (Array.isArray(data) && data.length > 0) ? data[0] : data; - return (!!element.file_size || !!element.content_type) && !!element.uid; + const element = (Array.isArray(data) && data.length > 0) ? data[0] : data + return (!!element.file_size || !!element.content_type) && !!element.uid } export function cleanAssets (data) { - if (data && typeof data === "object") { - const keys = Object.keys(data); + if (data && typeof data === 'object') { + const keys = Object.keys(data) for (const key of keys) { - if (data[key] !== null && data[key] !== undefined && typeof data[key] === "object") { + if (data[key] !== null && data[key] !== undefined && typeof data[key] === 'object') { if (isAsset(data[key])) { - data[key] = (Array.isArray(data[key])) ? data[key].map(element => element.uid) : data[key].uid; + data[key] = (Array.isArray(data[key])) ? data[key].map(element => element.uid) : data[key].uid } else { - cleanAssets(data[key]); + cleanAssets(data[key]) } } } } - return data; + return data } diff --git a/lib/stack/bulkOperation/index.js b/lib/stack/bulkOperation/index.js index 615b22e3..89bdcca9 100644 --- a/lib/stack/bulkOperation/index.js +++ b/lib/stack/bulkOperation/index.js @@ -28,23 +28,25 @@ export function BulkOperation (http, data = {}) { * client.stack({ api_key: 'api_key'}).bulkOperation().addItems({ data: itemsData }) * .then((response) => { console.log(response) }) */ - this.addItems = async ({ data, bulk_version = "" }) => { - this.urlPath = `/bulk/release/items`; + // eslint-disable-next-line camelcase + this.addItems = async ({ data, bulk_version = '' }) => { + this.urlPath = `/bulk/release/items` const headers = { headers: { - ...cloneDeep(this.stackHeaders), - }, - }; - if (bulk_version) headers.headers.bulk_version = bulk_version; + ...cloneDeep(this.stackHeaders) + } + } + // eslint-disable-next-line camelcase + if (bulk_version) headers.headers.bulk_version = bulk_version try { - const response = await http.post(this.urlPath, data, headers); + const response = await http.post(this.urlPath, data, headers) if (response.data) { - return response.data; + return response.data } } catch (error) { - console.error(error); + console.error(error) } - }; + } /** * The updateItems request allows you to update multiple items in a release in bulk. @@ -65,23 +67,25 @@ export function BulkOperation (http, data = {}) { * client.stack({ api_key: 'api_key'}).bulkOperation().updateItems({ data: itemsData }) * .then((response) => { console.log(response) }) */ - this.updateItems = async ({ data, bulk_version = "" }) => { - this.urlPath = `/bulk/release/update_items`; + // eslint-disable-next-line camelcase + this.updateItems = async ({ data, bulk_version = '' }) => { + this.urlPath = `/bulk/release/update_items` const headers = { headers: { - ...cloneDeep(this.stackHeaders), - }, - }; - if (bulk_version) headers.headers.bulk_version = bulk_version; + ...cloneDeep(this.stackHeaders) + } + } + // eslint-disable-next-line camelcase + if (bulk_version) headers.headers.bulk_version = bulk_version try { - const response = await http.put(this.urlPath, data, headers); + const response = await http.put(this.urlPath, data, headers) if (response.data) { - return response.data; + return response.data } } catch (error) { - console.error(error); + console.error(error) } - }; + } /** * The jobStatus request allows you to check the status of a bulk job. @@ -94,23 +98,26 @@ export function BulkOperation (http, data = {}) { * client.stack({ api_key: 'api_key'}).bulkOperation().jobStatus({ job_id: 'job_id' }) * .then((response) => { console.log(response) }) */ - this.jobStatus = async ({ job_id, bulk_version = "" }) => { - this.urlPath = `/bulk/jobs/${job_id}`; + // eslint-disable-next-line camelcase + this.jobStatus = async ({ job_id, bulk_version = '' }) => { + // eslint-disable-next-line camelcase + this.urlPath = `/bulk/jobs/${job_id}` const headers = { headers: { - ...cloneDeep(this.stackHeaders), - }, - }; - if (bulk_version) headers.headers.bulk_version = bulk_version; + ...cloneDeep(this.stackHeaders) + } + } + // eslint-disable-next-line camelcase + if (bulk_version) headers.headers.bulk_version = bulk_version try { - const response = await http.get(this.urlPath, headers); + const response = await http.get(this.urlPath, headers) if (response.data) { - return response.data; + return response.data } } catch (error) { - console.error(error); + console.error(error) } - }; + } /** * The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time. @@ -172,6 +179,7 @@ export function BulkOperation (http, data = {}) { * .then((response) => { console.log(response.notice) }) * */ + // eslint-disable-next-line camelcase this.publish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => { var httpBody = {} if (details) { @@ -182,19 +190,23 @@ export function BulkOperation (http, data = {}) { ...cloneDeep(this.stackHeaders) } } + // eslint-disable-next-line camelcase if (is_nested) { headers.params = { nested: true, event_type: 'bulk' } } + // eslint-disable-next-line camelcase if (skip_workflow_stage) { + // eslint-disable-next-line camelcase headers.headers.skip_workflow_stage_check = skip_workflow_stage } if (approvals) { headers.headers.approvals = approvals } + // eslint-disable-next-line camelcase if (api_version) headers.headers.api_version = api_version return publishUnpublish(http, '/bulk/publish', httpBody, headers) @@ -259,7 +271,8 @@ export function BulkOperation (http, data = {}) { * client.stack({ api_key: 'api_key'}).bulkOperation().unpublish({ details: publishDetails, is_nested: true }) * .then((response) => { console.log(response.notice) }) */ - this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = ''}) => { + // eslint-disable-next-line camelcase + this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => { var httpBody = {} if (details) { httpBody = cloneDeep(details) @@ -269,18 +282,22 @@ export function BulkOperation (http, data = {}) { ...cloneDeep(this.stackHeaders) } } + // eslint-disable-next-line camelcase if (is_nested) { headers.params = { nested: true, event_type: 'bulk' } } + // eslint-disable-next-line camelcase if (skip_workflow_stage) { + // eslint-disable-next-line camelcase headers.headers.skip_workflow_stage_check = skip_workflow_stage } if (approvals) { headers.headers.approvals = approvals } + // eslint-disable-next-line camelcase if (api_version) headers.headers.api_version = api_version return publishUnpublish(http, '/bulk/unpublish', httpBody, headers) } diff --git a/lib/stack/contentType/entry/index.js b/lib/stack/contentType/entry/index.js index c1c41b85..4beec04a 100644 --- a/lib/stack/contentType/entry/index.js +++ b/lib/stack/contentType/entry/index.js @@ -25,11 +25,11 @@ export function Entry (http, data) { this.urlPath = `/content_types/${this.content_type_uid}/entries` if (data && data.entry) { - this.apiVersion = data.api_version || undefined; + this.apiVersion = data.api_version || undefined if (this.apiVersion && !this.stackHeaders.api_version) { - this.stackHeaders.api_version = this.apiVersion; + this.stackHeaders.api_version = this.apiVersion } - const { stackHeaders, ...entryData } = data.entry; + const { stackHeaders, ...entryData } = data.entry Object.assign(this, cloneDeep(entryData)) this.urlPath = `/content_types/${this.content_type_uid}/entries/${this.uid}` @@ -197,8 +197,10 @@ export function Entry (http, data) { * client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').publishRequest({ publishing_rule, locale: 'en-us'}) * .then((response) => console.log(response.notice)) */ - this.publishRequest = async ({publishing_rule, locale}) => { + // eslint-disable-next-line camelcase + this.publishRequest = async ({ publishing_rule, locale }) => { const publishDetails = { + // eslint-disable-next-line camelcase workflow: { publishing_rule } } const headers = {} @@ -249,9 +251,10 @@ export function Entry (http, data) { * client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').setWorkflowStage({ workflow_stage, locale: 'en-us'}) * .then((response) => console.log(response.notice)); */ - + // eslint-disable-next-line camelcase this.setWorkflowStage = async ({ workflow_stage, locale }) => { const publishDetails = { + // eslint-disable-next-line camelcase workflow: { workflow_stage } } const headers = {} @@ -307,32 +310,34 @@ export function Entry (http, data) { * client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').includeVariants('true','variants_uid') * .then((response) => console.log(response)) */ - + // eslint-disable-next-line camelcase this.includeVariants = async (include_variant, variants_uid) => { try { const headers = { ...cloneDeep(this.stackHeaders) // Clone existing headers - }; - + } + // Add custom header - headers['x-cs-variant-uid'] = variants_uid; // add variant UID - let params = {}; + // eslint-disable-next-line camelcase + headers['x-cs-variant-uid'] = variants_uid // add variant UID + const params = {} + // eslint-disable-next-line camelcase if (include_variant) { - params.include_variant = include_variant; // if include_variant present + // eslint-disable-next-line camelcase + params.include_variant = include_variant // if include_variant present } - const response = await http.get(this.urlPath, { headers, params }); + const response = await http.get(this.urlPath, { headers, params }) if (response.data) { - return response.data; + return response.data } else { - throw error(response); + throw error(response) } } catch (err) { - error(err); + error(err) } - }; - + } - /** + /** * @description The get locales request allows to get the languages of an entry. * @memberof Entry * @func locales @@ -375,7 +380,7 @@ export function Entry (http, data) { headers.headers = this.stackHeaders } try { - const response = await http.get(`${this.urlPath}/references`, {...headers, params: param,}) + const response = await http.get(`${this.urlPath}/references`, { ...headers, params: param }) if (response.data) { return response.data } else { @@ -385,7 +390,6 @@ export function Entry (http, data) { throw error(err) } } - } else { /** * @description The Create an entry call creates a new entry for the selected content type. diff --git a/lib/stack/contentType/entry/variants/index.js b/lib/stack/contentType/entry/variants/index.js index 097f2fa8..ae6eb29a 100644 --- a/lib/stack/contentType/entry/variants/index.js +++ b/lib/stack/contentType/entry/variants/index.js @@ -1,28 +1,21 @@ import cloneDeep from 'lodash/cloneDeep' import { - update, - deleteEntity, - fetch, - upload, - query, - parseData + deleteEntity, + fetch, + query } -from '../../../../entity' -import FormData from 'form-data' -import { - createReadStream -} from 'fs' + from '../../../../entity' import error from '../../../../core/contentstackError' /** * An variants is the actual piece of content created using one of the defined content types. Read more about Entries. * @namespace Variants */ -export function Variants(http, data) { - Object.assign(this, cloneDeep(data)) - this.urlPath = `/content_types/${this.content_type_uid}/entries/${this.entry_uid}/variants` - if (data && data.variants_uid) { - this.urlPath += `/${this.variants_uid}` - /** +export function Variants (http, data) { + Object.assign(this, cloneDeep(data)) + this.urlPath = `/content_types/${this.content_type_uid}/entries/${this.entry_uid}/variants` + if (data && data.variants_uid) { + this.urlPath += `/${this.variants_uid}` + /** * @description The Create an variants call creates a new variants for the selected content type. * @memberof Variants * @func update @@ -45,26 +38,26 @@ export function Variants(http, data) { * client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('entry_uid').variants('uid').update(data) * .then((variants) => console.log(variants)) */ - this.update = async (data) => { - try { - const response = await http.put(this.urlPath, - data, - { - headers: { - ...cloneDeep(this.stackHeaders) - } - }) - if (response.data) { - return response.data - } else { - return error(response) - } - } catch (err) { - return error(err) + this.update = async (data) => { + try { + const response = await http.put(this.urlPath, + data, + { + headers: { + ...cloneDeep(this.stackHeaders) } - } + }) + if (response.data) { + return response.data + } else { + return error(response) + } + } catch (err) { + return error(err) + } + } - /** + /** * @description The Delete an variants call is used to delete a specific variants from a content type. * @memberof Variants * @func delete @@ -76,9 +69,9 @@ export function Variants(http, data) { * client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('entry_uid').variants('uid').delete() * .then((response) => console.log(response.notice)) */ - this.delete = deleteEntity(http) + this.delete = deleteEntity(http) - /** + /** * @description The fetch Variants call fetches Variants details. * @memberof Variants * @func fetch @@ -91,9 +84,9 @@ export function Variants(http, data) { * .then((variants) => console.log(variants)) * */ - this.fetch = fetch(http, 'variants') + this.fetch = fetch(http, 'variants') - /** + /** * @description The version Variants call fetches Variants version details. * @memberof Variants * @func versions @@ -106,25 +99,24 @@ export function Variants(http, data) { * .then((variants) => console.log(variants)) * */ - this.versions = async () => { - try { - const response = await http.get(`${this.urlPath}/versions`, { - headers: { - ...cloneDeep(this.stackHeaders) - } - }) - if (response.data) { - return response.data - } else { - return error(response) - } - } catch (err) { - return error(err) - } + this.versions = async () => { + try { + const response = await http.get(`${this.urlPath}/versions`, { + headers: { + ...cloneDeep(this.stackHeaders) } - - } else { - /** + }) + if (response.data) { + return response.data + } else { + return error(response) + } + } catch (err) { + return error(err) + } + } + } else { + /** * @description The Query on Variants will allow to fetch details of all or specific Variants * @memberof Variants * @func query @@ -139,19 +131,19 @@ export function Variants(http, data) { * client.stack().contentType('content_type_uid').entry('entry_uid').variants().query({ query: { title: 'Variants title' } }).find() * .then((entries) => console.log(entries)) */ - this.query = query({ http: http, wrapperCollection: VariantsCollection }) - } + this.query = query({ http: http, wrapperCollection: VariantsCollection }) + } } -export function VariantsCollection(http, data) { - const obj = cloneDeep(data.entries) || [] - const variantCollection = obj.map((variant) => { - return new Variants(http, { - content_type_uid: data.content_type_uid, - entry_uid: variant.uid, - variants_uid: variant._variant._uid, - stackHeaders: data.stackHeaders, - variants: variant - }) +export function VariantsCollection (http, data) { + const obj = cloneDeep(data.entries) || [] + const variantCollection = obj.map((variant) => { + return new Variants(http, { + content_type_uid: data.content_type_uid, + entry_uid: variant.uid, + variants_uid: variant._variant._uid, + stackHeaders: data.stackHeaders, + variants: variant }) - return variantCollection + }) + return variantCollection } diff --git a/lib/stack/contentType/index.js b/lib/stack/contentType/index.js index db101705..3f9e9c1c 100644 --- a/lib/stack/contentType/index.js +++ b/lib/stack/contentType/index.js @@ -26,7 +26,7 @@ export function ContentType (http, data = {}) { Object.assign(this, cloneDeep(data.content_type)) this.urlPath = `/content_types/${this.uid}` /** - * @description The Update ContentType call lets you update the name and description of an existing ContentType. + * @description The Update ContentType call lets you update the name and description of an existing ContentType. * You can also update the JSON schema of a content type, including fields and different features associated with the content type. * @memberof ContentType * @func update @@ -47,7 +47,7 @@ export function ContentType (http, data = {}) { this.update = update(http, 'content_type') /** - * @description The Update ContentType call lets you update the name and description of an existing ContentType. + * @description The Update ContentType call lets you update the name and description of an existing ContentType. * You can also update the JSON schema of a content type, including fields and different features associated with the content type. * @memberof ContentType * @func update @@ -153,9 +153,9 @@ export function ContentType (http, data = {}) { if (uid) { data.entry = { uid: uid } } - options = options || {}; // Ensure `options` is always an object + options = options || {} // Ensure `options` is always an object if (options && typeof options === 'object' && options.api_version) { - data.api_version = options.api_version; + data.api_version = options.api_version } return new Entry(http, data) } diff --git a/lib/stack/globalField/index.js b/lib/stack/globalField/index.js index 12d00ac1..682902ff 100644 --- a/lib/stack/globalField/index.js +++ b/lib/stack/globalField/index.js @@ -1,5 +1,5 @@ import cloneDeep from 'lodash/cloneDeep' -import { create, update, deleteEntity, fetch, query, upload, parseData } from '../../entity' +import { query, upload, parseData } from '../../entity' import error from '../../core/contentstackError' import FormData from 'form-data' import { createReadStream } from 'fs' @@ -11,10 +11,10 @@ import { createReadStream } from 'fs' export function GlobalField (http, data = {}) { this.stackHeaders = data.stackHeaders - this.apiVersion = data.api_version || undefined; + this.apiVersion = data.api_version || undefined if (this.apiVersion) { - this.stackHeaders.api_version = this.apiVersion; + this.stackHeaders.api_version = this.apiVersion } this.urlPath = `/global_fields` @@ -43,28 +43,27 @@ export function GlobalField (http, data = {}) { try { // Add `api_version` to headers if `this.apiVersion` is defined if (this.apiVersion) { - this.stackHeaders.api_version = this.apiVersion; + this.stackHeaders.api_version = this.apiVersion } const headers = { - headers: { + headers: { ...cloneDeep(this.stackHeaders) } } - const response = await http.put(`${this.urlPath}`, config, headers); + const response = await http.put(`${this.urlPath}`, config, headers) // Remove `api_version` from headers after fetching data if (this.apiVersion) { - delete this.stackHeaders.api_version; + delete this.stackHeaders.api_version } if (response.data) { - return response.data; + return response.data } else { - throw error(response); + throw error(response) } } catch (err) { - throw error(err); + throw error(err) } } - /** * @description The Update GlobalField call lets you update the name and description of an existing GlobalField. @@ -98,9 +97,9 @@ export function GlobalField (http, data = {}) { console.log(globalField) * }) */ - this.updateNestedGlobalField = async (config, headers={}) => { - const apiVersion = {api_version: '3.2' } - this.stackHeaders = {...this.stackHeaders, ...apiVersion, ...headers} + this.updateNestedGlobalField = async (config, headers = {}) => { + const apiVersion = { api_version: '3.2' } + this.stackHeaders = { ...this.stackHeaders, ...apiVersion, ...headers } try { const headers = { headers: { ...cloneDeep(this.stackHeaders) } @@ -129,34 +128,33 @@ export function GlobalField (http, data = {}) { * .then((response) => console.log(response.notice)) */ this.delete = async () => { - let param = {}; + const param = {} try { // Add `api_version` to headers if `this.apiVersion` is defined if (this.apiVersion) { - this.stackHeaders.api_version = this.apiVersion; + this.stackHeaders.api_version = this.apiVersion } const headers = { - headers: { - ...cloneDeep(this.stackHeaders) + headers: { + ...cloneDeep(this.stackHeaders) }, params: { ...cloneDeep(param) } - }; - const response = await http.delete(this.urlPath, headers); + } + const response = await http.delete(this.urlPath, headers) if (this.apiVersion) { - delete this.stackHeaders.api_version; + delete this.stackHeaders.api_version } if (response.data) { - return response.data; + return response.data } else { - throw error(response); + throw error(response) } } catch (err) { - throw error(err); + throw error(err) } - }; - + } /** * @description The fetch GlobalField call fetches GlobalField details. @@ -174,27 +172,26 @@ export function GlobalField (http, data = {}) { this.fetch = async function (param = {}) { try { if (this.apiVersion) { - this.stackHeaders.api_version = this.apiVersion; + this.stackHeaders.api_version = this.apiVersion } const headers = { - headers: { - ...cloneDeep(this.stackHeaders) + headers: { + ...cloneDeep(this.stackHeaders) }, params: { ...cloneDeep(param) } - }; - const response = await http.get(this.urlPath, headers); + } + const response = await http.get(this.urlPath, headers) if (response.data) { - return response.data; + return response.data } else { - throw error(response); + throw error(response) } } catch (err) { - throw error(err); + throw error(err) } - }; - + } } else { /** * @description The Create a GlobalField call creates a new globalField in a particular stack of your Contentstack account. @@ -220,24 +217,23 @@ export function GlobalField (http, data = {}) { this.create = async (data) => { try { if (this.apiVersion) { - this.stackHeaders.api_version = this.apiVersion; + this.stackHeaders.api_version = this.apiVersion } const headers = { headers: { ...cloneDeep(this.stackHeaders) } - }; - const response = await http.post(`${this.urlPath}`, data, headers); + } + const response = await http.post(`${this.urlPath}`, data, headers) if (response.data) { - return response.data; + return response.data } else { - return error(response); + return error(response) } } catch (err) { - return error(err); + return error(err) } - }; - + } /** * @description The Query on GlobalField will allow to fetch details of all or specific GlobalField @@ -272,7 +268,7 @@ export function GlobalField (http, data = {}) { */ this.import = async function (data, params = {}, headers = {}) { try { - this.stackHeaders = { ...this.stackHeaders, ...headers }; + this.stackHeaders = { ...this.stackHeaders, ...headers } const response = await upload({ http: http, urlPath: `${this.urlPath}/import`, diff --git a/lib/stack/index.js b/lib/stack/index.js index b8e1f5ca..c29e2ce0 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -159,30 +159,30 @@ export function Stack (http, data) { * * client.stack({ api_key: 'api_key'}).globalField('globalField_uid').fetch() * .then((globalField) => console.log(globalField)) - * + * * client.stack({ api_key: 'api_key'}).globalField('globalField_uid', { api_version: '3.2' }).fetch() * .then((globalField) => console.log(globalField)) - * + * */ this.globalField = (globalFieldUidOrOptions = null, options = {}) => { - let data = { - stackHeaders: this.stackHeaders, - }; + const data = { + stackHeaders: this.stackHeaders + } if (typeof globalFieldUidOrOptions === 'object' && globalFieldUidOrOptions !== null) { - options = globalFieldUidOrOptions; + options = globalFieldUidOrOptions } else if (globalFieldUidOrOptions) { - data.global_field = { uid: globalFieldUidOrOptions }; + data.global_field = { uid: globalFieldUidOrOptions } } // Safely handle `options` and check for `api_version` - options = options || {}; // Ensure `options` is always an object + options = options || {} // Ensure `options` is always an object if (options && typeof options === 'object' && options.api_version) { - data.api_version = options.api_version; + data.api_version = options.api_version if (options.api_version === '3.2') { - data.nested_global_fields = true; + data.nested_global_fields = true } } - + return new GlobalField(http, data) } @@ -410,7 +410,6 @@ export function Stack (http, data) { return new Variants(http, data) } - /** * @description You can pin a set of entries and assets (along with the deploy action, i.e., publish/unpublish) to a ‘release’, and then deploy this release to an environment. * @param {String} releaseUid The UID of the Releases you want to get details. diff --git a/lib/stack/release/index.js b/lib/stack/release/index.js index 19abb9d7..7bac8ac6 100644 --- a/lib/stack/release/index.js +++ b/lib/stack/release/index.js @@ -109,7 +109,7 @@ export function Release (http, data = {}) { * .then((items) => console.log(items)) */ this.item = () => { - return new ReleaseItem(http, { releaseUid: this.uid , stackHeaders: this.stackHeaders }) + return new ReleaseItem(http, { releaseUid: this.uid, stackHeaders: this.stackHeaders }) } /** * @description The Deploy a Release request deploys a specific Release to specific environment(s) and locale(s). diff --git a/lib/stack/release/items/index.js b/lib/stack/release/items/index.js index dca8e75e..abfa34c9 100644 --- a/lib/stack/release/items/index.js +++ b/lib/stack/release/items/index.js @@ -27,12 +27,12 @@ export function ReleaseItem (http, data = {}) { * // To delete all the items from release * client.stack({ api_key: 'api_key'}).release('release_uid').delete() * .then((response) => console.log(response.notice)) - * + * * @example * // Delete specific items from delete * import * as contentstack from '@contentstack/management' - * const client = contentstack.client() - * + * const client = contentstack.client() + * * const items = [ * { * uid: "entry_or_asset_uid1", @@ -55,7 +55,7 @@ export function ReleaseItem (http, data = {}) { this.delete = async (params) => { let param = {} if (params.items === undefined && params.item === undefined) { - param = {all: true} + param = { all: true } params.items = [] } try { @@ -68,16 +68,15 @@ export function ReleaseItem (http, data = {}) { ...cloneDeep(param) } } || {} - + if (params.release_version) { - headers.headers['release_version'] = params.release_version; + headers.headers['release_version'] = params.release_version } - + if (params.item) { this.urlPath = `releases/${data.releaseUid}/item` headers.data['item'] = params.item - } else - headers.data['items'] = params.items + } else { headers.data['items'] = params.items } const response = await http.delete(this.urlPath, headers) if (response.data) { @@ -140,15 +139,14 @@ export function ReleaseItem (http, data = {}) { ...cloneDeep(this.stackHeaders) } } || {} - - if (param.release_version) { - headers.headers['release_version'] = param.release_version; + + if (param.release_version) { + headers.headers['release_version'] = param.release_version } if (param.item) { this.urlPath = `releases/${data.releaseUid}/item` - param['item'] = param.item - } else - param['items'] = param.items + headers.data['item'] = param.item + } else { headers.data['items'] = param.items } try { const response = await http.post(this.urlPath, param, headers) @@ -187,8 +185,8 @@ export function ReleaseItem (http, data = {}) { } } || {} if (param.release_version) { - headers.headers['release_version'] = param.release_version; - delete headers.params.release_version; + headers.headers['release_version'] = param.release_version + delete headers.params.release_version } const response = await http.get(this.urlPath, headers) if (response.data) { @@ -197,7 +195,7 @@ export function ReleaseItem (http, data = {}) { throw error(response) } } catch (err) { - error(err) + error(err) } } @@ -220,14 +218,17 @@ export function ReleaseItem (http, data = {}) { * client.stack({ api_key: 'api_key'}).release('release_uid').item().move({ param: moveData, release_version: '1.0' }) * .then((response) => { console.log(response) }) */ + // eslint-disable-next-line camelcase this.move = async ({ param, release_version = '' }) => { const headers = { headers: { ...cloneDeep(this.stackHeaders) } } || {} + // eslint-disable-next-line camelcase if (release_version) { - headers.headers['release_version'] = release_version; + // eslint-disable-next-line camelcase + headers.headers['release_version'] = release_version } try { const response = await http.put(`${this.urlPath}/move`, param, headers) diff --git a/lib/stack/variantGroup/index.js b/lib/stack/variantGroup/index.js index 8f3b535b..36e0f5be 100644 --- a/lib/stack/variantGroup/index.js +++ b/lib/stack/variantGroup/index.js @@ -1,6 +1,7 @@ import cloneDeep from 'lodash/cloneDeep' -import { create, update, deleteEntity, fetch, query } from '../../entity' +import { deleteEntity, query } from '../../entity' import { Variants } from './variants/index' +import error from '../../core/contentstackError' /** * Contentstack has a sophisticated multilingual capability. It allows you to create and publish entries in any language. This feature allows you to set up multilingual websites and cater to a wide variety of audience by serving content in their local language(s). Read more about VariantGroups. @@ -30,7 +31,7 @@ export function VariantGroup (http, data = {}) { this.update = async (data) => { try { const response = await http.put(this.urlPath, - data, + data, { headers: { ...cloneDeep(this.stackHeaders) @@ -78,7 +79,6 @@ export function VariantGroup (http, data = {}) { } return new Variants(http, data) } - } else { /** * @description The Create a variant group call creates a new variant group in a particular stack of your Contentstack account. @@ -102,7 +102,7 @@ export function VariantGroup (http, data = {}) { this.create = async (data) => { try { const response = await http.post(`${this.urlPath}`, - data , + data, { headers: { ...cloneDeep(this.stackHeaders) @@ -139,8 +139,8 @@ export function VariantGroup (http, data = {}) { export function VariantGroupCollection (http, data) { const obj = cloneDeep(data.variant_groups) || [] - const variant_groupCollection = obj.map((userdata) => { + const variantGroupCollection = obj.map((userdata) => { return new VariantGroup(http, { variant_group: userdata, stackHeaders: data.stackHeaders }) }) - return variant_groupCollection + return variantGroupCollection } diff --git a/lib/stack/variantGroup/variants/index.js b/lib/stack/variantGroup/variants/index.js index cfbb2a74..31cd2871 100644 --- a/lib/stack/variantGroup/variants/index.js +++ b/lib/stack/variantGroup/variants/index.js @@ -1,12 +1,13 @@ import cloneDeep from 'lodash/cloneDeep' -import { create, fetch, query, deleteEntity } from '../../../entity' +import { query, deleteEntity } from '../../../entity' +import error from '../../../core/contentstackError' /** * Contentstack has a sophisticated multilingual capability. It allows you to create and publish entries in any language. This feature allows you to set up multilingual websites and cater to a wide variety of audience by serving content in their local language(s). Read more about VariantGroups. * @namespace Variants */ -export function Variants(http, data = {}) { +export function Variants (http, data = {}) { Object.assign(this, cloneDeep(data.variants)) this.stackHeaders = data.stackHeaders this.variant_group_uid = data.variant_group_uid @@ -76,7 +77,7 @@ export function Variants(http, data = {}) { throw error(response) } } catch (err) { - error(err) + error(err) } } @@ -119,7 +120,7 @@ export function Variants(http, data = {}) { this.create = async (data) => { try { const response = await http.post(`${this.urlPath}`, - data , + data, { headers: { ...cloneDeep(this.stackHeaders) @@ -145,7 +146,7 @@ export function Variants(http, data = {}) { * @example * import * as contentstack from '@contentstack/management' * const client = contentstack.client() - + * client.stack(api_key).VariantGroup('variant_group_uid').variants().query({ query: { name: 'white' } }).find() * .then((variant_groups) => console.log(variant_groups)) */ @@ -154,7 +155,7 @@ export function Variants(http, data = {}) { return this } -export function VariantsCollection(http, data) { +export function VariantsCollection (http, data) { const obj = cloneDeep(data.variants) || [] const variantsCollection = obj.map((userdata) => { return new Variants(http, { variants: userdata, variant_group_uid: data.uid, stackHeaders: data.stackHeaders }) diff --git a/lib/stack/variants/index.js b/lib/stack/variants/index.js index 7df5e02a..f0171724 100644 --- a/lib/stack/variants/index.js +++ b/lib/stack/variants/index.js @@ -1,10 +1,9 @@ import cloneDeep from 'lodash/cloneDeep' import { deleteEntity, - fetch, - query, - create + query } from '../../entity' +import error from '../../core/contentstackError' /** * Variantss allow you to group a collection of content within a stack. Using variants you can group content types that need to work together. Read more about Variantss. * @namespace Variants @@ -60,7 +59,7 @@ export function Variants (http, data) { throw error(response) } } catch (err) { - error(err) + error(err) } } } else { @@ -89,7 +88,7 @@ export function Variants (http, data) { this.create = async (data) => { try { const response = await http.post(`${this.urlPath}`, - data , + data, { headers: { ...cloneDeep(this.stackHeaders) @@ -138,7 +137,6 @@ export function Variants (http, data) { * .then((variants) => console.log(variants)) */ this.fetchByUIDs = async (variantUids) => { - try { const response = await http.get(this.urlPath, { params: { diff --git a/lib/stack/workflow/publishRules/index.js b/lib/stack/workflow/publishRules/index.js index f0000cea..4bc2341e 100644 --- a/lib/stack/workflow/publishRules/index.js +++ b/lib/stack/workflow/publishRules/index.js @@ -79,17 +79,16 @@ export function PublishRules (http, data = {}) { * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * const publishing_rule = { - * "publish rules": "publish rules_uid", + * "publish rules": "publish rules_uid", * "actions": [], * "content_types": ["$all"], * "locales": ["en-us"], * "environment": "environment_uid", - * "approvers": { - * "users": ["user_uid"], - * "roles": ["role_uid"] - * }, + * "approvers": { + * "users": ["user_uid"], + * "roles": ["role_uid"] * "publish rules_stage": "publish rules_stage_uid", - * "disable_approver_publishing": false + * "disable_approver_publishing": false * } * client.stack().publishRules().create({ publishing_rule }) * .then((publishRules) => console.log(publishRules)) diff --git a/package-lock.json b/package-lock.json index 30fa2dea..e91b72ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "devDependencies": { "@babel/cli": "^7.26.4", "@babel/core": "^7.26.9", + "@babel/eslint-parser": "^7.26.8", "@babel/plugin-transform-runtime": "^7.26.9", "@babel/preset-env": "^7.26.9", "@babel/register": "^7.25.9", @@ -164,6 +165,33 @@ "url": "https://opencollective.com/babel" } }, + "node_modules/@babel/eslint-parser": { + "version": "7.26.8", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.26.8.tgz", + "integrity": "sha512-3tBctaHRW6xSub26z7n8uyOTwwUsCdvIug/oxBH9n6yCO5hMj2vwDJAo7RbBMKrM7P+W2j61zLKviJQFGOYKMg==", + "dev": true, + "dependencies": { + "@nicolo-ribaudo/eslint-scope-5-internals": "5.1.1-v1", + "eslint-visitor-keys": "^2.1.0", + "semver": "^6.3.1" + }, + "engines": { + "node": "^10.13.0 || ^12.13.0 || >=14.0.0" + }, + "peerDependencies": { + "@babel/core": "^7.11.0", + "eslint": "^7.5.0 || ^8.0.0 || ^9.0.0" + } + }, + "node_modules/@babel/eslint-parser/node_modules/eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/@babel/generator": { "version": "7.26.9", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.9.tgz", @@ -2962,6 +2990,37 @@ "license": "MIT", "optional": true }, + "node_modules/@nicolo-ribaudo/eslint-scope-5-internals": { + "version": "5.1.1-v1", + "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", + "integrity": "sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==", + "dev": true, + "dependencies": { + "eslint-scope": "5.1.1" + } + }, + "node_modules/@nicolo-ribaudo/eslint-scope-5-internals/node_modules/eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@nicolo-ribaudo/eslint-scope-5-internals/node_modules/estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index 484a9bb0..fec48219 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "devDependencies": { "@babel/cli": "^7.26.4", "@babel/core": "^7.26.9", + "@babel/eslint-parser": "^7.26.8", "@babel/plugin-transform-runtime": "^7.26.9", "@babel/preset-env": "^7.26.9", "@babel/register": "^7.25.9", diff --git a/sanity-report-dev11.js b/sanity-report-dev11.js index ee5ba94c..7ce4843e 100644 --- a/sanity-report-dev11.js +++ b/sanity-report-dev11.js @@ -1,41 +1,41 @@ -const dotenv = require("dotenv"); -const fs = require("fs"); +const dotenv = require('dotenv') +const fs = require('fs') -dotenv.config(); +dotenv.config() -const user1 = process.env.USER1; -const user2 = process.env.USER2; -const user3 = process.env.USER3; -const user4 = process.env.USER4; +const user1 = process.env.USER1 +const user2 = process.env.USER2 +const user3 = process.env.USER3 +const user4 = process.env.USER4 const mochawesomeJsonOutput = fs.readFileSync( - "./mochawesome-report/mochawesome.json", - "utf-8" -); -const mochawesomeReport = JSON.parse(mochawesomeJsonOutput); + './mochawesome-report/mochawesome.json', + 'utf-8' +) +const mochawesomeReport = JSON.parse(mochawesomeJsonOutput) -const totalTests = mochawesomeReport.stats.tests; -const passedTests = mochawesomeReport.stats.passes; -const failedTests = mochawesomeReport.stats.failures; +const totalTests = mochawesomeReport.stats.tests +const passedTests = mochawesomeReport.stats.passes +const failedTests = mochawesomeReport.stats.failures -let durationInSeconds = Math.floor(mochawesomeReport.stats.duration / 1000); -const durationInMinutes = Math.floor(durationInSeconds / 60); -durationInSeconds %= 60; +let durationInSeconds = Math.floor(mochawesomeReport.stats.duration / 1000) +const durationInMinutes = Math.floor(durationInSeconds / 60) +durationInSeconds %= 60 const resultMessage = passedTests === totalTests ? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)` - : `:x: Failure (${passedTests} / ${totalTests} Passed)`; + : `:x: Failure (${passedTests} / ${totalTests} Passed)` -const pipelineName = process.env.GO_PIPELINE_NAME; -const pipelineCounter = process.env.GO_PIPELINE_COUNTER; -const goCdServer = process.env.GOCD_SERVER; +const pipelineName = process.env.GO_PIPELINE_NAME +const pipelineCounter = process.env.GO_PIPELINE_COUNTER +const goCdServer = process.env.GOCD_SERVER -const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${pipelineCounter}/sanity/1/sanity/test-results/mochawesome-report/sanity-report.html`; +const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${pipelineCounter}/sanity/1/sanity/test-results/mochawesome-report/sanity-report.html` -let tagUsers = ``; +let tagUsers = `` if (failedTests > 0) { - tagUsers = `<@${user1}> <@${user2}> <@${user3}> <@${user4}>`; + tagUsers = `<@${user1}> <@${user2}> <@${user3}> <@${user4}>` } const slackMessage = { @@ -43,32 +43,32 @@ const slackMessage = { *Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s *Failed Tests:* ${failedTests} <${reportUrl}|View Report> -${tagUsers}`, -}; +${tagUsers}` +} -const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; +const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL const sendSlackMessage = async (message) => { const payload = { - text: message, - }; + text: message + } try { const response = await fetch(slackWebhookUrl, { - method: "POST", + method: 'POST', headers: { - "Content-Type": "application/json", + 'Content-Type': 'application/json' }, - body: JSON.stringify(payload), - }); + body: JSON.stringify(payload) + }) if (!response.ok) { - throw new Error(`Error sending message to Slack: ${response.statusText}`); + throw new Error(`Error sending message to Slack: ${response.statusText}`) } - console.log("Message sent to Slack successfully"); + console.log('Message sent to Slack successfully') } catch (error) { - console.error("Error:", error); + console.error('Error:', error) } -}; -sendSlackMessage(slackMessage.text); +} +sendSlackMessage(slackMessage.text) diff --git a/test/api/app-test.js b/test/api/app-test.js index 04081dee..b77c6885 100644 --- a/test/api/app-test.js +++ b/test/api/app-test.js @@ -6,7 +6,6 @@ import * as contentstack from '../../lib/contentstack.js' dotenv.config() -let stack = {} const orgID = process.env.ORGANIZATION let client = {} let appUid = '' @@ -22,7 +21,6 @@ describe('Apps api Test', () => { setup(() => { const user = jsonReader('loggedinuser.json') client = contentstack.client({ host: process.env.APP_HOST, defaultHostName: process.env.DEFAULTHOST, authtoken: user.authtoken }) - stack = jsonReader('stack.json') }) it('Fetch all apps test', done => { diff --git a/test/api/branch-test.js b/test/api/branch-test.js index 3b2ea184..69237d6e 100644 --- a/test/api/branch-test.js +++ b/test/api/branch-test.js @@ -157,25 +157,25 @@ describe('Branch api Test', () => { const params = { base_branch: branch.uid, compare_branch: devBranch.uid, - default_merge_strategy: "ignore", - merge_comment: "Merging dev into main", + default_merge_strategy: 'ignore', + merge_comment: 'Merging dev into main' } const mergeObj = { item_merge_strategies: [ { - "uid": "global_field_uid", - "type": "global_field", - "merge_strategy": "merge_prefer_base" + uid: 'global_field_uid', + type: 'global_field', + merge_strategy: 'merge_prefer_base' }, { - "uid": "ct5", - "type": "content_type", - "merge_strategy": "merge_prefer_compare" + uid: 'ct5', + type: 'content_type', + merge_strategy: 'merge_prefer_compare' }, { - "uid": "bot_all", - "type": "content_type", - "merge_strategy": "merge_prefer_base" + uid: 'bot_all', + type: 'content_type', + merge_strategy: 'merge_prefer_base' } ] } diff --git a/test/api/branchAlias-test.js b/test/api/branchAlias-test.js index 850a1d97..688058c9 100644 --- a/test/api/branchAlias-test.js +++ b/test/api/branchAlias-test.js @@ -1,4 +1,4 @@ -import { expect, use } from 'chai' +import { expect } from 'chai' import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite' import { contentstackClient } from '../utility/ContentstackClient.js' @@ -67,8 +67,7 @@ describe('Branch Alias api Test', () => { done() }) .catch(done) - } - catch (e) { + } catch (e) { done() } }) diff --git a/test/api/bulkOperation-test.js b/test/api/bulkOperation-test.js index c334fe19..7fc2ff2d 100644 --- a/test/api/bulkOperation-test.js +++ b/test/api/bulkOperation-test.js @@ -17,21 +17,21 @@ describe('BulkOperation api test', () => { const publishDetails = { entries: [ { - uid: "blte6542a9aac484405", - content_type: "bye", + uid: 'blte6542a9aac484405', + content_type: 'bye', version: 1, - locale: "en-us" + locale: 'en-us' } ], locales: [ - "en-us" + 'en-us' ], environments: [ - "dev" + 'dev' ] } doBulkOperation() - .publish({details:publishDetails, api_version:'3.2'}) + .publish({ details: publishDetails, api_version: '3.2' }) .then((response) => { expect(response.notice).to.not.equal(undefined) expect(response.job_id).to.not.equal(undefined) @@ -44,18 +44,18 @@ describe('BulkOperation api test', () => { const publishDetails = { assets: [ { - uid: "blt9f8e5aa45ac36455" + uid: 'blt9f8e5aa45ac36455' } ], locales: [ - "en-us" + 'en-us' ], environments: [ - "dev" + 'dev' ] } doBulkOperation() - .publish({details:publishDetails, api_version:'3.2'}) + .publish({ details: publishDetails, api_version: '3.2' }) .then((response) => { expect(response.notice).to.not.equal(undefined) expect(response.job_id).to.not.equal(undefined) @@ -68,33 +68,33 @@ describe('BulkOperation api test', () => { const publishDetails = { entries: [ { - uid: "blt077157784a170bab", - content_type: "bye", + uid: 'blt077157784a170bab', + content_type: 'bye', version: 1, - locale: "en-us" + locale: 'en-us' }, { - uid: "blta519039712ca2b8a", - content_type: "bye", + uid: 'blta519039712ca2b8a', + content_type: 'bye', version: 1, - locale: "en-us" + locale: 'en-us' } ], assets: [ { - uid: "blt9f8e5aa45ac36455" + uid: 'blt9f8e5aa45ac36455' }, { - uid: "blt3b097cc58475b0a3" + uid: 'blt3b097cc58475b0a3' } ], locales: [ - "en-us" + 'en-us' ], environments: [ - "dev" + 'dev' ] } doBulkOperation() - .publish({details:publishDetails, api_version:'3.2'}) + .publish({ details: publishDetails, api_version: '3.2' }) .then((response) => { expect(response.notice).to.not.equal(undefined) expect(response.job_id).to.not.equal(undefined) diff --git a/test/api/contentType-test.js b/test/api/contentType-test.js index a8e49030..6f104234 100644 --- a/test/api/contentType-test.js +++ b/test/api/contentType-test.js @@ -96,7 +96,7 @@ describe('Content Type api Test', () => { it('Update ContentType schema without fetch', done => { makeContentType(multiPageCT.content_type.uid) - .updateCT({content_type: {schema: schema}}) + .updateCT({ content_type: { schema: schema } }) .then((contentType) => { expect(contentType.schema.length).to.be.equal(6) done() diff --git a/test/api/entry-test.js b/test/api/entry-test.js index 73ed20ae..af97ad76 100644 --- a/test/api/entry-test.js +++ b/test/api/entry-test.js @@ -193,16 +193,16 @@ describe('Entry api Test', () => { it('Create and update an entry with asset', done => { // get asset - let asset; + let asset makeAsset() - .query() - .find() - .then((collection) => { - asset = collection.items[0]; + .query() + .find() + .then((collection) => { + asset = collection.items[0] // create entry - let entry = { + const entry = { ...entryFirst, - title: "uniqueTitle45", + title: 'uniqueTitle45', modular_blocks: [ { block1: { @@ -210,19 +210,19 @@ describe('Entry api Test', () => { } } ] - }; + } makeEntry(multiPageCT.content_type.uid) - .create({entry: entry}) - .then(entry => { - const newTitle = "updated title"; - entry.title = newTitle; - entry.update().then(updatedEntry => { - expect(updatedEntry.title).to.be.equal(newTitle); - done(); + .create({ entry: entry }) + .then(entry => { + const newTitle = 'updated title' + entry.title = newTitle + entry.update().then(updatedEntry => { + expect(updatedEntry.title).to.be.equal(newTitle) + done() + }) }) - }) }) - }); + }) }) function makeEntry (contentType, uid = null) { diff --git a/test/api/mock/managementToken.js b/test/api/mock/managementToken.js index bd08d49e..bf399d6f 100644 --- a/test/api/mock/managementToken.js +++ b/test/api/mock/managementToken.js @@ -1,73 +1,72 @@ const createManagementToken = { - "token":{ - "name":"Test Token", - "description":"This is a sample management token.", - "scope":[ - { - "module":"content_type", - "acl":{ - "read":true, - "write":true - } - }, - { - "module":"branch", - "branches":[ - "main" - ], - "acl":{ - "read":true - } - }, - { - "module":"branch_alias", - "branch_aliases":[ - "tst" - ], - "acl":{ - "read":true - } - } - ], - "expires_on":"2024-12-10", - "is_email_notification_enabled":true + token: { + name: 'Test Token', + description: 'This is a sample management token.', + scope: [ + { + module: 'content_type', + acl: { + read: true, + write: true + } + }, + { + module: 'branch', + branches: [ + 'main' + ], + acl: { + read: true + } + }, + { + module: 'branch_alias', + branch_aliases: [ + 'tst' + ], + acl: { + read: true + } + } + ], + expires_on: '2024-12-10', + is_email_notification_enabled: true } } const createManagementToken2 = { - "token":{ - "name":"Test Token", - "description":"This is a sample management token.", - "scope":[ - { - "module":"content_type", - "acl":{ - "read":true, - "write":true - } - }, - { - "module":"branch", - "branches":[ - "main" - ], - "acl":{ - "read":true - } - }, - { - "module":"branch_alias", - "branch_aliases":[ - "tst" - ], - "acl":{ - "read":true - } - } - ], - "expires_on":"2024-12-10", - "is_email_notification_enabled":true + token: { + name: 'Test Token', + description: 'This is a sample management token.', + scope: [ + { + module: 'content_type', + acl: { + read: true, + write: true + } + }, + { + module: 'branch', + branches: [ + 'main' + ], + acl: { + read: true + } + }, + { + module: 'branch_alias', + branch_aliases: [ + 'tst' + ], + acl: { + read: true + } + } + ], + expires_on: '2024-12-10', + is_email_notification_enabled: true } } - - export { createManagementToken, createManagementToken2 } - \ No newline at end of file + +export { createManagementToken, createManagementToken2 } diff --git a/test/api/mock/role.js b/test/api/mock/role.js index ce81f195..c0d299df 100644 --- a/test/api/mock/role.js +++ b/test/api/mock/role.js @@ -16,12 +16,12 @@ const role = { acl: { read: true } }, { - module: "taxonomy", - taxonomies: ["taxonomy_testing1"], - terms: ["taxonomy_testing1.term_test1"], + module: 'taxonomy', + taxonomies: ['taxonomy_testing1'], + terms: ['taxonomy_testing1.term_test1'], content_types: [ { - uid: "$all", + uid: '$all', acl: { read: true, sub_acl: { diff --git a/test/api/mock/variantGroup.js b/test/api/mock/variantGroup.js index 269d476a..8081e4a5 100644 --- a/test/api/mock/variantGroup.js +++ b/test/api/mock/variantGroup.js @@ -1,82 +1,82 @@ const createVariantGroup = { - "name": "Colors", - "content_types": [ - "iphone_product_page" - ], - "uid": "iphone_color_white", - } + name: 'Colors', + content_types: [ + 'iphone_product_page' + ], + uid: 'iphone_color_white' +} const createVariantGroup1 = { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "uid", - "name": "iPhone Colors", - "content_types": [ - "iphone_product_page" - ], - "source" : "Personalize" - } + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'uid', + name: 'iPhone Colors', + content_types: [ + 'iphone_product_page' + ], + source: 'Personalize' +} const createVariantGroup2 = { - count: 2, - variant_groups: [ - { - "uid": "uid", - "name": "iPhone Colors", - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "content_types": [ - "iphone_product_page" - ], - "variant_count": 1, - "variants": [ - { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_white", - "name": "White" - } - ] - }, - { - "uid": "uid", - "name": "iPhone", - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "content_types": [ - "iphone_prod_desc" - ], - "variant_count": 1, - "variants": [ - { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_white", - "name": "White" - } - ] - } - ], - ungrouped_variants: [ - { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_red", - "name": "Red" - } - ], - ungrouped_variant_count: 1 - } + count: 2, + variant_groups: [ + { + uid: 'uid', + name: 'iPhone Colors', + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + content_types: [ + 'iphone_product_page' + ], + variant_count: 1, + variants: [ + { + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_white', + name: 'White' + } + ] + }, + { + uid: 'uid', + name: 'iPhone', + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + content_types: [ + 'iphone_prod_desc' + ], + variant_count: 1, + variants: [ + { + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_white', + name: 'White' + } + ] + } + ], + ungrouped_variants: [ + { + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_red', + name: 'Red' + } + ], + ungrouped_variant_count: 1 +} export { createVariantGroup, createVariantGroup1, createVariantGroup2 } diff --git a/test/api/mock/variants.js b/test/api/mock/variants.js index 9e590226..178c7cc3 100644 --- a/test/api/mock/variants.js +++ b/test/api/mock/variants.js @@ -1,50 +1,50 @@ const variant = { - "uid": "iphone_color_white", // optional - "name": "White", - "personalize_metadata": { // optional sent from personalize while creating variant - "experience_uid": "exp1", - "experience_short_uid": "expShortUid1", - "project_uid": "project_uid1", - "variant_short_uid": "variantShort_uid1" - }, + uid: 'iphone_color_white', // optional + name: 'White', + personalize_metadata: { // optional sent from personalize while creating variant + experience_uid: 'exp1', + experience_short_uid: 'expShortUid1', + project_uid: 'project_uid1', + variant_short_uid: 'variantShort_uid1' } +} const variant1 = { - "created_by": "blt6cdf4e0b02b1c446", - "updated_by": "blt303b74fa96e1082a", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_white", - "name": "White", - } + created_by: 'blt6cdf4e0b02b1c446', + updated_by: 'blt303b74fa96e1082a', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_white', + name: 'White' +} const variant2 = { - "uid": "variant_group_1", - "name": "Variant Group 1", - "content_types": [ - "CTSTAET123" - ], - "personalize_metadata": { - "experience_uid": "variant_group_ex_uid", - "experience_short_uid": "variant_group_short_uid", - "project_uid": "variant_group_project_uid" - }, - "variants": [ // variants inside the group - { - "uid": "variant1", - "created_by": "user_id", - "updated_by": "user_id", - "name": "Variant 1", - "personalize_metadata": { - "experience_uid": "exp1", - "experience_short_uid": "expShortUid1", - "project_uid": "project_uid1", - "variant_short_uid": "variantShort_uid1" - }, - "created_at": "2024-04-16T05:53:50.547Z", - "updated_at": "2024-04-16T05:53:50.547Z" - } - ], - "count": 1 + uid: 'variant_group_1', + name: 'Variant Group 1', + content_types: [ + 'CTSTAET123' + ], + personalize_metadata: { + experience_uid: 'variant_group_ex_uid', + experience_short_uid: 'variant_group_short_uid', + project_uid: 'variant_group_project_uid' + }, + variants: [ // variants inside the group + { + uid: 'variant1', + created_by: 'user_id', + updated_by: 'user_id', + name: 'Variant 1', + personalize_metadata: { + experience_uid: 'exp1', + experience_short_uid: 'expShortUid1', + project_uid: 'project_uid1', + variant_short_uid: 'variantShort_uid1' + }, + created_at: '2024-04-16T05:53:50.547Z', + updated_at: '2024-04-16T05:53:50.547Z' + } + ], + count: 1 } export { variant, variant1, variant2 } diff --git a/test/api/mock/workflow.js b/test/api/mock/workflow.js index d0baf113..198cacbd 100644 --- a/test/api/mock/workflow.js +++ b/test/api/mock/workflow.js @@ -1,8 +1,8 @@ -const firstWorkflow = {"workflow_stages":[{"color":"#2196f3","SYS_ACL":{"roles":{"uids":[]},"users":{"uids":["$all"]},"others":{}},"next_available_stages":["$all"],"allStages":true,"allUsers":true,"specificStages":false,"specificUsers":false,"entry_lock":"$none","name":"First stage"},{"color":"#e53935","SYS_ACL":{"roles":{"uids":[]},"users":{"uids":["$all"]},"others":{}},"allStages":true,"allUsers":true,"specificStages":false,"specificUsers":false,"next_available_stages":["$all"],"entry_lock":"$none","name":"Second stage"}],"admin_users":{"users":[]},"name":"First Workflow","content_types":["multi_page_from_json"]} -const secondWorkflow = {"workflow_stages":[{"color":"#2196f3","SYS_ACL":{"roles":{"uids":[]},"users":{"uids":["$all"]},"others":{}},"next_available_stages":["$all"],"allStages":true,"allUsers":true,"specificStages":false,"specificUsers":false,"entry_lock":"$none","name":"first stage"},{"isNew":true,"color":"#e53935","SYS_ACL":{"roles":{"uids":[]},"users":{"uids":["$all"]},"others":{}},"allStages":true,"allUsers":true,"specificStages":false,"specificUsers":false,"next_available_stages":["$all"],"entry_lock":"$none","name":"stage 2"}],"admin_users":{"users":[]},"name":"Second workflow","enabled":true,"content_types":["multi_page"]} -const finalWorkflow = {"workflow_stages":[{"color":"#2196f3","SYS_ACL":{"roles":{"uids":[]},"users":{"uids":["$all"]},"others":{}},"next_available_stages":["$all"],"allStages":true,"allUsers":true,"specificStages":false,"specificUsers":false,"entry_lock":"$none","name":"Review"},{"color":"#74ba76","SYS_ACL":{"roles":{"uids":[]},"users":{"uids":["$all"]},"others":{}},"allStages":true,"allUsers":true,"specificStages":false,"specificUsers":false,"next_available_stages":["$all"],"entry_lock":"$none","name":"Complet"}],"admin_users":{"users":[]},"name":"Workflow","enabled":true,"content_types":["single_page"]} +const firstWorkflow = { workflow_stages: [{ color: '#2196f3', SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, next_available_stages: ['$all'], allStages: true, allUsers: true, specificStages: false, specificUsers: false, entry_lock: '$none', name: 'First stage' }, { color: '#e53935', SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, allStages: true, allUsers: true, specificStages: false, specificUsers: false, next_available_stages: ['$all'], entry_lock: '$none', name: 'Second stage' }], admin_users: { users: [] }, name: 'First Workflow', content_types: ['multi_page_from_json'] } +const secondWorkflow = { workflow_stages: [{ color: '#2196f3', SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, next_available_stages: ['$all'], allStages: true, allUsers: true, specificStages: false, specificUsers: false, entry_lock: '$none', name: 'first stage' }, { isNew: true, color: '#e53935', SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, allStages: true, allUsers: true, specificStages: false, specificUsers: false, next_available_stages: ['$all'], entry_lock: '$none', name: 'stage 2' }], admin_users: { users: [] }, name: 'Second workflow', enabled: true, content_types: ['multi_page'] } +const finalWorkflow = { workflow_stages: [{ color: '#2196f3', SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, next_available_stages: ['$all'], allStages: true, allUsers: true, specificStages: false, specificUsers: false, entry_lock: '$none', name: 'Review' }, { color: '#74ba76', SYS_ACL: { roles: { uids: [] }, users: { uids: ['$all'] }, others: {} }, allStages: true, allUsers: true, specificStages: false, specificUsers: false, next_available_stages: ['$all'], entry_lock: '$none', name: 'Complet' }], admin_users: { users: [] }, name: 'Workflow', enabled: true, content_types: ['single_page'] } -const firstPublishRules = {"isNew":true,"actions":["publish"],"content_types":["multi_page_from_json"],"locales":["en-at"],"environment":"environment_name","workflow_stage":"","approvers":{"users":["user_id"],"roles":["role_uid"]}} -const secondPublishRules = {"isNew":true,"actions":["publish"],"content_types":["multi_page"],"locales":["en-at"],"environment":"environment_name","workflow_stage":"","approvers":{"users":["user_id"],"roles":["role_uid"]}} +const firstPublishRules = { isNew: true, actions: ['publish'], content_types: ['multi_page_from_json'], locales: ['en-at'], environment: 'environment_name', workflow_stage: '', approvers: { users: ['user_id'], roles: ['role_uid'] } } +const secondPublishRules = { isNew: true, actions: ['publish'], content_types: ['multi_page'], locales: ['en-at'], environment: 'environment_name', workflow_stage: '', approvers: { users: ['user_id'], roles: ['role_uid'] } } -export {firstWorkflow, secondWorkflow, finalWorkflow, firstPublishRules, secondPublishRules} \ No newline at end of file +export { firstWorkflow, secondWorkflow, finalWorkflow, firstPublishRules, secondPublishRules } diff --git a/test/api/taxonomy-test.js b/test/api/taxonomy-test.js index e31c715b..86bbe597 100644 --- a/test/api/taxonomy-test.js +++ b/test/api/taxonomy-test.js @@ -56,7 +56,6 @@ describe('taxonomy api Test', () => { .catch(done) }) - it('Fetch taxonomy from uid', done => { makeTaxonomy(taxonomyUID) .fetch() diff --git a/test/api/terms-test.js b/test/api/terms-test.js index 7d10a9bd..79aab144 100644 --- a/test/api/terms-test.js +++ b/test/api/terms-test.js @@ -6,8 +6,8 @@ import { contentstackClient } from '../utility/ContentstackClient.js' var client = {} var stack = {} -const taxonomy_uid = '' -const term_uid = '' +const taxonomyUid = '' +const termUid = '' const term = { term: { uid: 'term_test', @@ -25,7 +25,7 @@ describe('Terms API Test', () => { it('Create term', async () => { try { - const response = await makeTerms(taxonomy_uid).create(term) + const response = await makeTerms(taxonomyUid).create(term) expect(response.notice).to.be.equal('Term created successfully.') expect(response.uid).to.be.equal(term.term.uid) } catch (err) { @@ -35,7 +35,7 @@ describe('Terms API Test', () => { it('Query and get all terms', async () => { try { - const response = await makeTerms(taxonomy_uid).query().find() + const response = await makeTerms(taxonomyUid).query().find() expect(response.items).to.be.an('array') expect(response.items[0].uid).not.to.be.equal(null) expect(response.items[0].name).not.to.be.equal(null) @@ -46,8 +46,8 @@ describe('Terms API Test', () => { it('Fetch term from UID', async () => { try { - const response = await makeTerms(taxonomy_uid, term_uid).fetch() - expect(response.uid).to.be.equal(term_uid) + const response = await makeTerms(taxonomyUid, termUid).fetch() + expect(response.uid).to.be.equal(termUid) expect(response.name).not.to.be.equal(null) expect(response.created_by).not.to.be.equal(null) expect(response.updated_by).not.to.be.equal(null) @@ -58,13 +58,13 @@ describe('Terms API Test', () => { it('Update term', async () => { try { - const response = await makeTerms(taxonomy_uid, term_uid).fetch() + const response = await makeTerms(taxonomyUid, termUid).fetch() .then((term) => { term.name = 'fashion' return term.update() }) expect(response.notice).to.be.equal('Term updated successfully.') - expect(response.uid).to.be.equal(term_uid) + expect(response.uid).to.be.equal(termUid) expect(response.name).to.be.equal('fashion') expect(response.created_by).not.to.be.equal(null) expect(response.updated_by).not.to.be.equal(null) @@ -75,7 +75,7 @@ describe('Terms API Test', () => { it('Delete term from UID', async () => { try { - const response = await makeTerms(term_uid).delete() + const response = await makeTerms(termUid).delete() expect(response.notice).to.be.equal('') } catch (err) { console.log(err) @@ -84,7 +84,7 @@ describe('Terms API Test', () => { it('Ancestors of the term given', async () => { try { - const response = await makeTerms(taxonomy_uid, term_uid).ancestors() + const response = await makeTerms(taxonomyUid, termUid).ancestors() expect(response.terms[0].uid).not.to.be.equal(null) expect(response.terms[0].name).not.to.be.equal(null) expect(response.terms[0].created_by).not.to.be.equal(null) @@ -96,7 +96,7 @@ describe('Terms API Test', () => { it('Descendants of the term given', async () => { try { - const response = await makeTerms(taxonomy_uid, term_uid).descendants() + const response = await makeTerms(taxonomyUid, termUid).descendants() expect(response.terms.uid).not.to.be.equal(null) expect(response.terms.name).not.to.be.equal(null) expect(response.terms.created_by).not.to.be.equal(null) @@ -106,9 +106,9 @@ describe('Terms API Test', () => { } }) it('search term', async () => { - term_string = '' + const termString = '' try { - const response = await makeTerms(taxonomy_uid).search(term_string) + const response = await makeTerms(taxonomyUid).search(termString) expect(response.terms).to.be.an('array') } catch (err) { console.log(err) @@ -120,7 +120,7 @@ describe('Terms API Test', () => { parent_uid: 'parent_uid', order: 2 } - await makeTerms(taxonomy_uid, term_uid).move({ term }) + await makeTerms(taxonomyUid, termUid).move({ term }) .then((term) => { term.parent_uid = 'parent_uid' console.log(term.move()) @@ -132,6 +132,6 @@ describe('Terms API Test', () => { }) }) -function makeTerms (taxonomy_uid, term_uid = null) { - return client.stack({ api_key: stack.api_key }).taxonomy(taxonomy_uid).terms(term_uid) +function makeTerms (taxonomyUid, termUid = null) { + return client.stack({ api_key: stack.api_key }).taxonomy(taxonomyUid).terms(termUid) } diff --git a/test/api/ungroupedVariants-test.js b/test/api/ungroupedVariants-test.js index a42ab83a..94b46404 100644 --- a/test/api/ungroupedVariants-test.js +++ b/test/api/ungroupedVariants-test.js @@ -6,16 +6,16 @@ import { contentstackClient } from '../utility/ContentstackClient.js' var client = {} var stack = {} -const variants ={ - "uid": "iphone_color_white", // optional - "name": "White", - "personalize_metadata": { - "experience_uid": "exp1", - "experience_short_uid": "expShortUid1", - "project_uid": "project_uid1", - "variant_short_uid": "variantShort_uid1" - }, +const variants = { + uid: 'iphone_color_white', // optional + name: 'White', + personalize_metadata: { + experience_uid: 'exp1', + experience_short_uid: 'expShortUid1', + project_uid: 'project_uid1', + variant_short_uid: 'variantShort_uid1' } +} var variantsUID = '' var deleteVariantsUID = '' @@ -90,7 +90,6 @@ describe('Variants api Test', () => { .catch(done) }) - it('Delete variants from uid', done => { makeVariants(deleteVariantsUID) .delete() diff --git a/test/api/variantGroup-test.js b/test/api/variantGroup-test.js index 1c7fa13e..695953f9 100644 --- a/test/api/variantGroup-test.js +++ b/test/api/variantGroup-test.js @@ -133,4 +133,4 @@ describe('Variant Group api Test', () => { function makeVariantGroup (uid = null) { return client.stack({ api_key: stack.api_key }).variantGroup(uid) -} \ No newline at end of file +} diff --git a/test/api/variants-test.js b/test/api/variants-test.js index b01968de..bebc332d 100644 --- a/test/api/variants-test.js +++ b/test/api/variants-test.js @@ -1,7 +1,7 @@ import { expect } from 'chai' import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite' -import { variant, variant1, variant2 } from './mock/variants.js' +import { variant, variant2 } from './mock/variants.js' import { contentstackClient } from '../utility/ContentstackClient.js' var client = {} @@ -109,4 +109,4 @@ describe('Variants api Test', () => { function makeVariants (uid = null) { return client.stack({ api_key: stack.api_key }).variantGroup('uid').variants(uid) -} \ No newline at end of file +} diff --git a/test/sanity-check/api/branch-test.js b/test/sanity-check/api/branch-test.js index 96e0539f..34723a9f 100644 --- a/test/sanity-check/api/branch-test.js +++ b/test/sanity-check/api/branch-test.js @@ -12,15 +12,15 @@ describe('Branch api Test', () => { client = contentstackClient(user.authtoken) }) - it('should create a dev branch from stage branch',async () => { - const response = await makeBranch().create({ branch: devBranch }); - expect(response.uid).to.be.equal(devBranch.uid); - expect(response.source).to.be.equal(devBranch.source); - expect(response.alias).to.not.equal(undefined); - expect(response.delete).to.not.equal(undefined); - expect(response.fetch).to.not.equal(undefined); - await new Promise(resolve => setTimeout(resolve, 15000)); - }); + it('should create a dev branch from stage branch', async () => { + const response = await makeBranch().create({ branch: devBranch }) + expect(response.uid).to.be.equal(devBranch.uid) + expect(response.source).to.be.equal(devBranch.source) + expect(response.alias).to.not.equal(undefined) + expect(response.delete).to.not.equal(undefined) + expect(response.fetch).to.not.equal(undefined) + await new Promise(resolve => setTimeout(resolve, 15000)) + }) it('should return main branch when query is called', done => { makeBranch() @@ -162,7 +162,7 @@ describe('Branch api Test', () => { mergeJobUid = response.uid expect(response.merge_details.base_branch).to.be.equal(branch.uid) expect(response.merge_details.compare_branch).to.be.equal(stageBranch.uid) - await new Promise(resolve => setTimeout(resolve, 15000)); + await new Promise(resolve => setTimeout(resolve, 15000)) }) it('should list all recent merge jobs', done => { diff --git a/test/sanity-check/api/contentType-test.js b/test/sanity-check/api/contentType-test.js index 2a743360..2ba90009 100644 --- a/test/sanity-check/api/contentType-test.js +++ b/test/sanity-check/api/contentType-test.js @@ -7,7 +7,6 @@ import { contentstackClient } from '../utility/ContentstackClient.js' let client = {} let multiPageCTUid = '' -let multiPageUpdateCTUid = 'multi_page' describe('Content Type api Test', () => { setup(() => { @@ -115,7 +114,6 @@ describe('Content Type api Test', () => { .catch(done) }) - it('should import content type', done => { makeContentType().import({ content_type: path.join(__dirname, '../mock/contentType.json') diff --git a/test/sanity-check/api/entry-test.js b/test/sanity-check/api/entry-test.js index 62e378fa..ca3428eb 100644 --- a/test/sanity-check/api/entry-test.js +++ b/test/sanity-check/api/entry-test.js @@ -223,6 +223,6 @@ describe('Entry api Test', () => { }) }) -function makeEntry(contentType, uid = null) { +function makeEntry (contentType, uid = null) { return client.stack({ api_key: process.env.API_KEY }).contentType(contentType).entry(uid) } diff --git a/test/sanity-check/api/entryVariants-test.js b/test/sanity-check/api/entryVariants-test.js index aa2a5267..719f5539 100644 --- a/test/sanity-check/api/entryVariants-test.js +++ b/test/sanity-check/api/entryVariants-test.js @@ -1,228 +1,226 @@ -import { expect } from "chai"; -import { describe, it, setup } from "mocha"; -import { jsonReader } from "../utility/fileOperations/readwrite"; -import { createVariantGroup } from "../mock/variantGroup.js"; -import { variant } from "../mock/variants.js"; +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite' +import { createVariantGroup } from '../mock/variantGroup.js' +import { variant } from '../mock/variants.js' import { variantEntryFirst, publishVariantEntryFirst, - unpublishVariantEntryFirst, -} from "../mock/variantEntry.js"; -import { contentstackClient } from "../utility/ContentstackClient.js"; + unpublishVariantEntryFirst +} from '../mock/variantEntry.js' +import { contentstackClient } from '../utility/ContentstackClient.js' -var client = {}; +var client = {} -var stack = {}; -var variantUid = ""; -var variantGroupUid = ""; -var contentTypeUid = ""; -var entryUid = ""; +var variantUid = '' +var variantGroupUid = '' +var contentTypeUid = '' +var entryUid = '' -describe("Entry Variants api Test", () => { +describe('Entry Variants api Test', () => { setup(() => { - const user = jsonReader("loggedinuser.json"); - stack = jsonReader("stack.json"); - client = contentstackClient(user.authtoken); - const entry = jsonReader("entry.json"); - entryUid = entry[2].uid; - contentTypeUid = entry[2].content_type_uid; - }); - - it("should create a Variant Group", (done) => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + const entry = jsonReader('entry.json') + entryUid = entry[2].uid + contentTypeUid = entry[2].content_type_uid + }) + + it('should create a Variant Group', (done) => { makeVariantGroup() .create(createVariantGroup) .then((variantGroup) => { - variantGroupUid = variantGroup.uid; - expect(variantGroup.name).to.be.equal(createVariantGroup.name); - expect(variantGroup.uid).to.be.equal(createVariantGroup.uid); - done(); + variantGroupUid = variantGroup.uid + expect(variantGroup.name).to.be.equal(createVariantGroup.name) + expect(variantGroup.uid).to.be.equal(createVariantGroup.uid) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should create a Variants", (done) => { + it('should create a Variants', (done) => { makeVariants() .create(variant) .then((variants) => { - variantUid = variants.uid; - expect(variants.name).to.be.equal(variant.name); - expect(variants.uid).to.be.not.equal(null); - done(); + variantUid = variants.uid + expect(variants.name).to.be.equal(variant.name) + expect(variants.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should update/create variant of an entry", (done) => { + it('should update/create variant of an entry', (done) => { makeEntryVariants(variantUid) .update(variantEntryFirst) .then((variantEntry) => { - expect(variantEntry.entry.title).to.be.equal("First page variant"); - expect(variantEntry.entry._variant._uid).to.be.not.equal(null); + expect(variantEntry.entry.title).to.be.equal('First page variant') + expect(variantEntry.entry._variant._uid).to.be.not.equal(null) expect(variantEntry.notice).to.be.equal( - "Entry variant created successfully." - ); - done(); + 'Entry variant created successfully.' + ) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should get an entry variant", (done) => { + it('should get an entry variant', (done) => { makeEntryVariants(variantUid) .fetch(variantUid) .then((variantEntry) => { - expect(variantEntry.entry.title).to.be.equal("First page variant"); - expect(variantEntry.entry._variant._uid).to.be.not.equal(null); - done(); + expect(variantEntry.entry.title).to.be.equal('First page variant') + expect(variantEntry.entry._variant._uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should publish entry variant", (done) => { - publishVariantEntryFirst.entry.variants[0].uid = variantUid; + it('should publish entry variant', (done) => { + publishVariantEntryFirst.entry.variants[0].uid = variantUid makeEntry() .entry(entryUid) .publish({ publishDetails: publishVariantEntryFirst.entry, - locale: publishVariantEntryFirst.locale, + locale: publishVariantEntryFirst.locale }) .then((data) => { expect(data.notice).to.be.equal( - "The requested action has been performed." - ); - expect(data.job_id).to.be.not.equal(null); - done(); + 'The requested action has been performed.' + ) + expect(data.job_id).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should unpublish entry variant", (done) => { - unpublishVariantEntryFirst.entry.variants[0].uid = variantUid; + it('should unpublish entry variant', (done) => { + unpublishVariantEntryFirst.entry.variants[0].uid = variantUid makeEntry() .entry(entryUid) .unpublish({ publishDetails: publishVariantEntryFirst.entry, - locale: publishVariantEntryFirst.locale, + locale: publishVariantEntryFirst.locale }) .then((data) => { expect(data.notice).to.be.equal( - "The requested action has been performed." - ); - expect(data.job_id).to.be.not.equal(null); - done(); + 'The requested action has been performed.' + ) + expect(data.job_id).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should publish entry variant using api_version", (done) => { - publishVariantEntryFirst.entry.variants[0].uid = variantUid; + it('should publish entry variant using api_version', (done) => { + publishVariantEntryFirst.entry.variants[0].uid = variantUid makeEntry() - .entry(entryUid, { api_version: "3.2" }) + .entry(entryUid, { api_version: '3.2' }) .publish({ publishDetails: publishVariantEntryFirst.entry, - locale: publishVariantEntryFirst.locale, + locale: publishVariantEntryFirst.locale }) .then((data) => { expect(data.notice).to.be.equal( - "The requested action has been performed." - ); - expect(data.job_id).to.be.not.equal(null); - done(); + 'The requested action has been performed.' + ) + expect(data.job_id).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should unpublish entry variant using api_version", (done) => { - unpublishVariantEntryFirst.entry.variants[0].uid = variantUid; + it('should unpublish entry variant using api_version', (done) => { + unpublishVariantEntryFirst.entry.variants[0].uid = variantUid makeEntry() - .entry(entryUid, { api_version: "3.2" }) + .entry(entryUid, { api_version: '3.2' }) .unpublish({ publishDetails: unpublishVariantEntryFirst.entry, - locale: unpublishVariantEntryFirst.locale, + locale: unpublishVariantEntryFirst.locale }) .then((data) => { expect(data.notice).to.be.equal( - "The requested action has been performed." - ); - expect(data.job_id).to.be.not.equal(null); - done(); - }) - .catch(done); - }); - it("should get all entry variants", (done) => { + 'The requested action has been performed.' + ) + expect(data.job_id).to.be.not.equal(null) + done() + }) + .catch(done) + }) + it('should get all entry variants', (done) => { makeEntryVariants() .query({}) .find() .then((variantEntries) => { - expect(variantEntries.items).to.be.an("array"); + expect(variantEntries.items).to.be.an('array') expect(variantEntries.items[0].variants.title).to.be.equal( - "First page variant" - ); + 'First page variant' + ) expect(variantEntries.items[0].variants._variant._uid).to.be.not.equal( null - ); - done(); + ) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete entry variant from uid", (done) => { + it('should delete entry variant from uid', (done) => { makeEntryVariants(variantUid) .delete(variantUid) .then((variantEntry) => { expect(variantEntry.notice).to.be.equal( - "Entry variant deleted successfully." - ); - done(); + 'Entry variant deleted successfully.' + ) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Delete a Variant from uid", (done) => { + it('Delete a Variant from uid', (done) => { makeVariantGroup(variantGroupUid) .variants(variantUid) .delete() .then((data) => { - expect(data.message).to.be.equal("Variant deleted successfully"); - done(); + expect(data.message).to.be.equal('Variant deleted successfully') + done() }) - .catch(done); - }); + .catch(done) + }) - it("Delete a Variant Group from uid", (done) => { + it('Delete a Variant Group from uid', (done) => { makeVariantGroup(variantGroupUid) .delete() .then((data) => { expect(data.message).to.be.equal( - "Variant Group and Variants deleted successfully" - ); - done(); + 'Variant Group and Variants deleted successfully' + ) + done() }) - .catch(done); - }); -}); + .catch(done) + }) +}) -function makeVariants(uid = null) { +function makeVariants (uid = null) { return client .stack({ api_key: process.env.API_KEY }) .variantGroup(variantGroupUid) - .variants(uid); + .variants(uid) } -function makeVariantGroup(uid = null) { - return client.stack({ api_key: process.env.API_KEY }).variantGroup(uid); +function makeVariantGroup (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).variantGroup(uid) } -function makeEntryVariants(uid = null) { +function makeEntryVariants (uid = null) { return client .stack({ api_key: process.env.API_KEY }) .contentType(contentTypeUid) .entry(entryUid) - .variants(uid); + .variants(uid) } -function makeEntry() { +function makeEntry () { return client .stack({ api_key: process.env.API_KEY }) - .contentType(contentTypeUid); + .contentType(contentTypeUid) } diff --git a/test/sanity-check/api/globalfield-test.js b/test/sanity-check/api/globalfield-test.js index 9dd35c08..789224fc 100644 --- a/test/sanity-check/api/globalfield-test.js +++ b/test/sanity-check/api/globalfield-test.js @@ -1,134 +1,132 @@ import path from 'path' import { expect } from 'chai' -import { cloneDeep } from 'lodash' import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite' -import { createGlobalField, createNestedGlobalField, createNestedGlobalFieldForReference } from '../mock/globalfield' +import { createGlobalField } from '../mock/globalfield' import { contentstackClient } from '../utility/ContentstackClient.js' import dotenv from 'dotenv' dotenv.config() let client = {} let createGlobalFieldUid = '' -describe("Global Field api Test", () => { +describe('Global Field api Test', () => { setup(() => { - const user = jsonReader("loggedinuser.json"); - client = contentstackClient(user.authtoken); - }); + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) - it("should create global field", (done) => { + it('should create global field', (done) => { makeGlobalField() .create(createGlobalField) .then((globalField) => { - globalField = globalField.global_field; - expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid); + globalField = globalField.global_field + expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid) expect(globalField.title).to.be.equal( createGlobalField.global_field.title - ); + ) expect(globalField.schema[0].uid).to.be.equal( createGlobalField.global_field.schema[0].uid - ); + ) expect(globalField.schema[0].data_type).to.be.equal( createGlobalField.global_field.schema[0].data_type - ); + ) expect(globalField.schema[0].display_name).to.be.equal( createGlobalField.global_field.schema[0].display_name - ); - done(); + ) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should fetch global Field", (done) => { + it('should fetch global Field', (done) => { makeGlobalField(createGlobalField.global_field.uid) .fetch() .then((globalField) => { - globalField = globalField.global_field; - expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid); + globalField = globalField.global_field + expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid) expect(globalField.title).to.be.equal( createGlobalField.global_field.title - ); + ) expect(globalField.schema[0].uid).to.be.equal( createGlobalField.global_field.schema[0].uid - ); + ) expect(globalField.schema[0].data_type).to.be.equal( createGlobalField.global_field.schema[0].data_type - ); + ) expect(globalField.schema[0].display_name).to.be.equal( createGlobalField.global_field.schema[0].display_name - ); - done(); + ) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should update global Field", (done) => { + it('should update global Field', (done) => { makeGlobalField(createGlobalField.global_field.uid) .update(createGlobalField) .then((updateGlobal) => { - updateGlobal = updateGlobal.global_field; + updateGlobal = updateGlobal.global_field expect(updateGlobal.uid).to.be.equal( createGlobalField.global_field.uid - ); + ) expect(updateGlobal.title).to.be.equal( createGlobalField.global_field.title - ); + ) expect(updateGlobal.schema[0].uid).to.be.equal( createGlobalField.global_field.schema[0].uid - ); + ) expect(updateGlobal.schema[0].data_type).to.be.equal( createGlobalField.global_field.schema[0].data_type - ); + ) expect(updateGlobal.schema[0].display_name).to.be.equal( createGlobalField.global_field.schema[0].display_name - ); - done(); + ) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should import global Field", (done) => { + it('should import global Field', (done) => { makeGlobalField() .import({ - global_field: path.join(__dirname, "../mock/globalfield.json"), + global_field: path.join(__dirname, '../mock/globalfield.json') }) .then((response) => { - createGlobalFieldUid = response.uid; - expect(response.uid).to.be.not.equal(null); - done(); + createGlobalFieldUid = response.uid + expect(response.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should get all global field from Query", (done) => { + it('should get all global field from Query', (done) => { makeGlobalField() .query() .find() .then((collection) => { collection.items.forEach((globalField) => { - expect(globalField.uid).to.be.not.equal(null); - expect(globalField.title).to.be.not.equal(null); - expect(globalField.schema).to.be.not.equal(null); - }); - done(); + expect(globalField.uid).to.be.not.equal(null) + expect(globalField.title).to.be.not.equal(null) + expect(globalField.schema).to.be.not.equal(null) + }) + done() }) - .catch(done); - }); + .catch(done) + }) - - it("should get global field title matching Upload", (done) => { + it('should get global field title matching Upload', (done) => { makeGlobalField() - .query({ query: { title: "Upload" } }) + .query({ query: { title: 'Upload' } }) .find() .then((collection) => { collection.items.forEach((globalField) => { - expect(globalField.uid).to.be.not.equal(null); - expect(globalField.title).to.be.equal("Upload"); - }); - done(); + expect(globalField.uid).to.be.not.equal(null) + expect(globalField.title).to.be.equal('Upload') + }) + done() }) - .catch(done); - }); + .catch(done) + }) // it("should get all nested global fields from Query", (done) => { // makeGlobalField({ api_version: '3.2' }) @@ -144,11 +142,10 @@ describe("Global Field api Test", () => { // .catch(done); // }); - // it('should create nested global field for reference', done => { // makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalFieldForReference) // .then(globalField => { - // expect(globalField.global_field.uid).to.be.equal(createNestedGlobalFieldForReference.global_field.uid); + // expect(globalField.global_field.uid).to.be.equal(createNestedGlobalFieldForReference.global_field.uid); // done(); // }) // .catch(err => { @@ -217,36 +214,36 @@ describe("Global Field api Test", () => { // }); // }); - it("should delete global Field", (done) => { + it('should delete global Field', (done) => { makeGlobalField(createGlobalField.global_field.uid) .delete() .then((data) => { - expect(data.notice).to.be.equal("Global Field deleted successfully."); - done(); + expect(data.notice).to.be.equal('Global Field deleted successfully.') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete imported global Field", (done) => { + it('should delete imported global Field', (done) => { makeGlobalField(createGlobalFieldUid) .delete() .then((data) => { - expect(data.notice).to.be.equal("Global Field deleted successfully."); - done(); + expect(data.notice).to.be.equal('Global Field deleted successfully.') + done() }) - .catch(done); - }); -}); - -function makeGlobalField(globalFieldUid = null, options = {}) { - let uid = null; - let finalOptions = options; - if (typeof globalFieldUid === "object") { - finalOptions = globalFieldUid; + .catch(done) + }) +}) + +function makeGlobalField (globalFieldUid = null, options = {}) { + let uid = null + let finalOptions = options + if (typeof globalFieldUid === 'object') { + finalOptions = globalFieldUid } else { - uid = globalFieldUid; + uid = globalFieldUid } - finalOptions = finalOptions || {}; + finalOptions = finalOptions || {} return client - .stack({ api_key: process.env.API_KEY }).globalField(uid, finalOptions); + .stack({ api_key: process.env.API_KEY }).globalField(uid, finalOptions) } diff --git a/test/sanity-check/api/organization-test.js b/test/sanity-check/api/organization-test.js index 4bb75aba..eecb2034 100644 --- a/test/sanity-check/api/organization-test.js +++ b/test/sanity-check/api/organization-test.js @@ -5,8 +5,7 @@ import { contentstackClient } from '../utility/ContentstackClient' var user = {} var client = {} -var organization = {} -let organizationUID = process.env.ORGANIZATION +const organizationUID = process.env.ORGANIZATION describe('Organization api test', () => { setup(() => { @@ -32,7 +31,6 @@ describe('Organization api test', () => { for (const index in user.organizations) { const organizations = user.organizations[index] if (organizations.org_roles && (organizations.org_roles.filter(function (role) { return role.admin === true }).length > 0)) { - organization = organizations break } } diff --git a/test/sanity-check/api/release-test.js b/test/sanity-check/api/release-test.js index 3fe3f266..1abea55f 100644 --- a/test/sanity-check/api/release-test.js +++ b/test/sanity-check/api/release-test.js @@ -1,483 +1,483 @@ -import { describe, it, setup } from "mocha"; -import { jsonReader } from "../utility/fileOperations/readwrite.js"; -import { releaseCreate, releaseCreate2 } from "../mock/release.js"; -import { expect } from "chai"; -import { cloneDeep } from "lodash"; -import { contentstackClient } from "../utility/ContentstackClient.js"; -import { multiPageCT } from "../mock/content-type.js"; -import dotenv from "dotenv"; +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite.js' +import { releaseCreate, releaseCreate2 } from '../mock/release.js' +import { expect } from 'chai' +import { cloneDeep } from 'lodash' +import { contentstackClient } from '../utility/ContentstackClient.js' +import { multiPageCT } from '../mock/content-type.js' +import dotenv from 'dotenv' -dotenv.config(); -let client = {}; -let releaseUID = ""; -let releaseUID2 = ""; -let releaseUID3 = ""; -let releaseUID4 = ""; -let entries = {}; -const itemToDelete = {}; -const jobId = ""; +dotenv.config() +let client = {} +let releaseUID = '' +let releaseUID2 = '' +let releaseUID3 = '' +let releaseUID4 = '' +let entries = {} +const itemToDelete = {} +let jobId = '' -describe("Relases api Test", () => { +describe('Relases api Test', () => { setup(() => { - const user = jsonReader("loggedinuser.json"); - entries = jsonReader("entry.json"); - client = contentstackClient(user.authtoken); - }); + const user = jsonReader('loggedinuser.json') + entries = jsonReader('entry.json') + client = contentstackClient(user.authtoken) + }) - it("should create a Release", (done) => { + it('should create a Release', (done) => { makeRelease() .create(releaseCreate) .then((release) => { - releaseUID = release.uid; - expect(release.name).to.be.equal(releaseCreate.release.name); + releaseUID = release.uid + expect(release.name).to.be.equal(releaseCreate.release.name) expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.not.equal(null); - done(); + ) + expect(release.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should create a Release 2", (done) => { + it('should create a Release 2', (done) => { makeRelease() .create(releaseCreate2) .then((release) => { - releaseUID2 = release.uid; - expect(release.name).to.be.equal(releaseCreate2.release.name); + releaseUID2 = release.uid + expect(release.name).to.be.equal(releaseCreate2.release.name) expect(release.description).to.be.equal( releaseCreate2.release.description - ); - expect(release.uid).to.be.not.equal(null); - done(); + ) + expect(release.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should fetch a Release from Uid", (done) => { + it('should fetch a Release from Uid', (done) => { makeRelease(releaseUID) .fetch() .then((release) => { - expect(release.name).to.be.equal(releaseCreate.release.name); + expect(release.name).to.be.equal(releaseCreate.release.name) expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.equal(releaseUID); - done(); + ) + expect(release.uid).to.be.equal(releaseUID) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should create release item", (done) => { + it('should create release item', (done) => { const item = { version: entries[0]._version, uid: entries[0].uid, content_type_uid: multiPageCT.content_type.uid, - action: "publish", - locale: "en-us", - }; + action: 'publish', + locale: 'en-us' + } makeRelease(releaseUID) .item() .create({ item }) .then((release) => { - expect(release.name).to.be.equal(releaseCreate.release.name); + expect(release.name).to.be.equal(releaseCreate.release.name) expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.equal(releaseUID); - expect(release.items.length).to.be.equal(1); - done(); + ) + expect(release.uid).to.be.equal(releaseUID) + expect(release.items.length).to.be.equal(1) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should create release items", (done) => { + it('should create release items', (done) => { const items = [ { version: entries[1]._version, uid: entries[1].uid, content_type_uid: multiPageCT.content_type.uid, - action: "publish", - locale: "en-us", + action: 'publish', + locale: 'en-us' }, { version: entries[2]._version, uid: entries[2].uid, content_type_uid: multiPageCT.content_type.uid, - action: "publish", - locale: "en-us", - }, - ]; + action: 'publish', + locale: 'en-us' + } + ] makeRelease(releaseUID) .item() .create({ items }) .then((release) => { - expect(release.name).to.be.equal(releaseCreate.release.name); + expect(release.name).to.be.equal(releaseCreate.release.name) expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.equal(releaseUID); - expect(release.items.length).to.be.equal(3); - done(); + ) + expect(release.uid).to.be.equal(releaseUID) + expect(release.items.length).to.be.equal(3) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should fetch a Release items from Uid", (done) => { + it('should fetch a Release items from Uid', (done) => { makeRelease(releaseUID) .item() - .findAll({ release_version: "2.0" }) + .findAll({ release_version: '2.0' }) .then((collection) => { - const itemdelete = collection.items[0]; - itemToDelete["version"] = itemdelete.version; - itemToDelete.action = itemdelete.action; - itemToDelete.uid = itemdelete.uid; - itemToDelete.locale = itemdelete.locale; - itemToDelete.content_type_uid = itemdelete.content_type_uid; - expect(collection.items.length).to.be.equal(3); - done(); + const itemdelete = collection.items[0] + itemToDelete['version'] = itemdelete.version + itemToDelete.action = itemdelete.action + itemToDelete.uid = itemdelete.uid + itemToDelete.locale = itemdelete.locale + itemToDelete.content_type_uid = itemdelete.content_type_uid + expect(collection.items.length).to.be.equal(3) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should move release items from release1 to release2", (done) => { + it('should move release items from release1 to release2', (done) => { const data = { release_uid: releaseUID2, items: [ { uid: entries[1].uid, - locale: "en-us", - }, - ], - }; + locale: 'en-us' + } + ] + } makeRelease(releaseUID) .item() - .move({ param: data, release_version: "2.0" }) + .move({ param: data, release_version: '2.0' }) .then((release) => { - expect(release.notice).to.contain('successful'); - done(); + expect(release.notice).to.contain('successful') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete specific item", (done) => { + it('should delete specific item', (done) => { makeRelease(releaseUID) .item() .delete({ items: [itemToDelete] }) .then((release) => { - expect(release.notice).to.be.equal('Item(s) send to remove from release successfully.'); - done(); + expect(release.notice).to.be.equal('Item(s) send to remove from release successfully.') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete all items", (done) => { + it('should delete all items', (done) => { makeRelease(releaseUID) .item() - .delete({ release_version: "2.0" }) + .delete({ release_version: '2.0' }) .then((release) => { - expect(release.notice).to.contain('successful'); - done(); + expect(release.notice).to.contain('successful') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should fetch and Update a Release from Uid", (done) => { + it('should fetch and Update a Release from Uid', (done) => { makeRelease(releaseUID) .fetch() .then((release) => { - release.name = "Update release name"; - return release.update(); + release.name = 'Update release name' + return release.update() }) .then((release) => { - expect(release.name).to.be.equal("Update release name"); + expect(release.name).to.be.equal('Update release name') expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.not.equal(null); - done(); + ) + expect(release.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should update a Release from Uid", (done) => { - const relaseObject = makeRelease(releaseUID); - Object.assign(relaseObject, cloneDeep(releaseCreate.release)); + it('should update a Release from Uid', (done) => { + const relaseObject = makeRelease(releaseUID) + Object.assign(relaseObject, cloneDeep(releaseCreate.release)) relaseObject .update() .then((release) => { - expect(release.name).to.be.equal(releaseCreate.release.name); + expect(release.name).to.be.equal(releaseCreate.release.name) expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.not.equal(null); - done(); + ) + expect(release.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should get all Releases", (done) => { + it('should get all Releases', (done) => { makeRelease() .query() .find() .then((releaseCollection) => { releaseCollection.items.forEach((release) => { - expect(release.name).to.be.not.equal(null); - expect(release.uid).to.be.not.equal(null); - }); - done(); + expect(release.name).to.be.not.equal(null) + expect(release.uid).to.be.not.equal(null) + }) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should get specific Releases with name ", (done) => { + it('should get specific Releases with name ', (done) => { makeRelease() .query({ query: { name: releaseCreate.release.name } }) .find() .then((releaseCollection) => { releaseCollection.items.forEach((release) => { - expect(release.name).to.be.equal(releaseCreate.release.name); - expect(release.uid).to.be.not.equal(null); - }); - done(); + expect(release.name).to.be.equal(releaseCreate.release.name) + expect(release.uid).to.be.not.equal(null) + }) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should clone specific Releases with Uid ", (done) => { + it('should clone specific Releases with Uid ', (done) => { makeRelease(releaseUID) - .clone({ name: "New Clone Name", description: "New Desc" }) + .clone({ name: 'New Clone Name', description: 'New Desc' }) .then((release) => { - releaseUID3 = release.uid; - expect(release.name).to.be.equal("New Clone Name"); - expect(release.description).to.be.equal("New Desc"); - expect(release.uid).to.be.not.equal(null); - done(); + releaseUID3 = release.uid + expect(release.name).to.be.equal('New Clone Name') + expect(release.description).to.be.equal('New Desc') + expect(release.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Bulk Operation: should add items to a release", (done) => { + it('Bulk Operation: should add items to a release', (done) => { const items = { release: releaseUID, - action: "publish", - locale: ["en-us"], + action: 'publish', + locale: ['en-us'], reference: true, items: [ { version: entries[1]._version, uid: entries[1].uid, content_type_uid: multiPageCT.content_type.uid, - locale: "en-us", - title: entries[1].title, + locale: 'en-us', + title: entries[1].title }, { version: entries[2]._version, uid: entries[2].uid, content_type_uid: multiPageCT.content_type.uid, - locale: "en-us", - title: entries[2].title, - }, - ], - }; + locale: 'en-us', + title: entries[2].title + } + ] + } doBulkOperation() - .addItems({ data: items, bulk_version: "2.0" }) + .addItems({ data: items, bulk_version: '2.0' }) .then((response) => { - jobId = response.job_id; + jobId = response.job_id expect(response.notice).to.equal( - "Your add to release request is in progress." - ); - expect(response.job_id).to.not.equal(undefined); - done(); + 'Your add to release request is in progress.' + ) + expect(response.job_id).to.not.equal(undefined) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Bulk Operation: should fetch job status details", (done) => { + it('Bulk Operation: should fetch job status details', (done) => { doBulkOperation() - .jobStatus({ job_id: jobId, bulk_version: "2.0" }) + .jobStatus({ job_id: jobId, bulk_version: '2.0' }) .then((response) => { - expect(response.job).to.not.equal(undefined); - expect(response.job._id).to.equal(jobId); - done(); + expect(response.job).to.not.equal(undefined) + expect(response.job._id).to.equal(jobId) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Bulk Operation: should update items to a release", (done) => { + it('Bulk Operation: should update items to a release', (done) => { const items = { release: releaseUID, - action: "publish", - locale: ["en-us"], + action: 'publish', + locale: ['en-us'], reference: true, - items: ["$all"], - }; + items: ['$all'] + } doBulkOperation() - .updateItems({ data: items, bulk_version: "2.0" }) + .updateItems({ data: items, bulk_version: '2.0' }) .then((response) => { expect(response.notice).to.equal( - "Your update release items to latest version request is in progress." - ); - expect(response.job_id).to.not.equal(undefined); - done(); + 'Your update release items to latest version request is in progress.' + ) + expect(response.job_id).to.not.equal(undefined) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete specific Releases with Uid ", (done) => { + it('should delete specific Releases with Uid ', (done) => { makeRelease(releaseUID) .delete() .then((data) => { - expect(data.notice).to.be.equal("Release deleted successfully."); - done(); + expect(data.notice).to.be.equal('Release deleted successfully.') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete specific Releases with Uid 2", (done) => { + it('should delete specific Releases with Uid 2', (done) => { makeRelease(releaseUID2) .delete() .then((data) => { - expect(data.notice).to.be.equal("Release deleted successfully."); - done(); + expect(data.notice).to.be.equal('Release deleted successfully.') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete cloned Release with Uid", (done) => { + it('should delete cloned Release with Uid', (done) => { makeRelease(releaseUID3) .delete() .then((data) => { - expect(data.notice).to.be.equal("Release deleted successfully."); - done(); + expect(data.notice).to.be.equal('Release deleted successfully.') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should create a Release v2", (done) => { + it('should create a Release v2', (done) => { makeRelease() .create(releaseCreate) .then((release) => { - releaseUID4 = release.uid; - expect(release.name).to.be.equal(releaseCreate.release.name); + releaseUID4 = release.uid + expect(release.name).to.be.equal(releaseCreate.release.name) expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.not.equal(null); - done(); + ) + expect(release.uid).to.be.not.equal(null) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should create release item fo v2", (done) => { + it('should create release item fo v2', (done) => { const item = { version: entries[0]._version, uid: entries[0].uid, content_type_uid: multiPageCT.content_type.uid, - action: "publish", - locale: "en-us", - title: entries[0].title, - }; + action: 'publish', + locale: 'en-us', + title: entries[0].title + } makeRelease(releaseUID4) .item() - .create({ item, release_version: "2.0" }) + .create({ item, release_version: '2.0' }) .then((release) => { - expect(release.name).to.be.equal(releaseCreate.release.name); + expect(release.name).to.be.equal(releaseCreate.release.name) expect(release.description).to.be.equal( releaseCreate.release.description - ); - expect(release.uid).to.be.equal(releaseUID4); - done(); + ) + expect(release.uid).to.be.equal(releaseUID4) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete specific item for v2", (done) => { + it('should delete specific item for v2', (done) => { makeRelease(releaseUID4) .item() .delete({ - item: { uid: entries[0].uid, locale: "en-us" }, - release_version: "2.0", + item: { uid: entries[0].uid, locale: 'en-us' }, + release_version: '2.0' }) .then((release) => { - expect(release.notice).to.contain('successful'); - done(); + expect(release.notice).to.contain('successful') + done() }) - .catch(done); - }); + .catch(done) + }) - it("Bulk Operation: should add items to a release 2", (done) => { + it('Bulk Operation: should add items to a release 2', (done) => { const items = { release: releaseUID4, - action: "publish", - locale: ["en-us"], + action: 'publish', + locale: ['en-us'], reference: true, items: [ { version: entries[1]._version, uid: entries[1].uid, content_type_uid: multiPageCT.content_type.uid, - locale: "en-us", - title: entries[1].title, + locale: 'en-us', + title: entries[1].title }, { version: entries[2]._version, uid: entries[2].uid, content_type_uid: multiPageCT.content_type.uid, - locale: "en-us", - title: entries[2].title, - }, - ], - }; + locale: 'en-us', + title: entries[2].title + } + ] + } doBulkOperation() - .addItems({ data: items, bulk_version: "2.0" }) + .addItems({ data: items, bulk_version: '2.0' }) .then((response) => { expect(response.notice).to.equal( - "Your add to release request is in progress." - ); - expect(response.job_id).to.not.equal(undefined); - done(); + 'Your add to release request is in progress.' + ) + expect(response.job_id).to.not.equal(undefined) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete specific items for v2", (done) => { + it('should delete specific items for v2', (done) => { makeRelease(releaseUID4) .item() .delete({ items: [ - { uid: entries[1].uid, - locale: "en-us" + { uid: entries[1].uid, + locale: 'en-us' }, { uid: entries[2].uid, - locale: "en-us", - }, + locale: 'en-us' + } ], - release_version: "2.0", + release_version: '2.0' }) .then((release) => { - expect(release.notice).to.contain('successful'); - done(); + expect(release.notice).to.contain('successful') + done() }) - .catch(done); - }); + .catch(done) + }) - it("should delete specific Releases with Uid ", (done) => { + it('should delete specific Releases with Uid ', (done) => { makeRelease(releaseUID4) .delete() .then((data) => { - expect(data.notice).to.be.equal("Release deleted successfully."); - done(); + expect(data.notice).to.be.equal('Release deleted successfully.') + done() }) - .catch(done); - }); -}); + .catch(done) + }) +}) -function makeRelease(uid = null) { - return client.stack({ api_key: process.env.API_KEY }).release(uid); +function makeRelease (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).release(uid) } -function doBulkOperation(uid = null) { - return client.stack({ api_key: process.env.API_KEY }).bulkOperation(); +function doBulkOperation (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).bulkOperation() } diff --git a/test/sanity-check/api/role-test.js b/test/sanity-check/api/role-test.js index 9f4f961f..fac992d6 100644 --- a/test/sanity-check/api/role-test.js +++ b/test/sanity-check/api/role-test.js @@ -9,19 +9,6 @@ dotenv.config() let client = {} let roleUID = '' -const taxonomy = { - uid: 'taxonomy_testing1', - name: 'taxonomy testing1', - description: 'Description for Taxonomy testing' -} -const term = { - term: { - uid: 'term_test1', - name: 'Term test1', - parent_uid: null - } -} - describe('Role api test', () => { setup(() => { const user = jsonReader('loggedinuser.json') @@ -180,15 +167,8 @@ describe('Role api test', () => { // const taxonomyResponse = await client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomy.uid).delete({ force: true }) // expect(taxonomyResponse.status).to.be.equal(204) // }) - }) function getRole (uid = null) { return client.stack({ api_key: process.env.API_KEY }).role(uid) } - - -function makeTerms (taxonomyUid, termUid = null) { - return client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomyUid).terms(termUid) -} - diff --git a/test/sanity-check/api/team-test.js b/test/sanity-check/api/team-test.js index 2f9de0b9..2ba28293 100644 --- a/test/sanity-check/api/team-test.js +++ b/test/sanity-check/api/team-test.js @@ -12,7 +12,7 @@ const stackApiKey = process.env.API_KEY let userId = '' let teamUid1 = '' let teamUid2 = '' -const orgAdminRole = '' +let orgAdminRole = '' let adminRole = '' let contentManagerRole = '' let developerRole = '' @@ -22,7 +22,7 @@ describe('Teams API Test', () => { const user = jsonReader('loggedinuser.json') client = contentstackClient(user.authtoken) const orgRoles = jsonReader('orgRoles.json') - orgAdminRole = orgRoles.find(role => role.name === 'admin').uid; + orgAdminRole = orgRoles.find(role => role.name === 'admin').uid }) it('should create new team 1 when required object is passed', async () => { @@ -98,9 +98,9 @@ describe('Teams Stack Role Mapping API Test', () => { const user = jsonReader('loggedinuser.json') client = contentstackClient(user.authtoken) const stackRoles = jsonReader('roles.json') - adminRole = stackRoles.find(role => role.name === 'Admin').uid; - contentManagerRole = stackRoles.find(role => role.name === 'Content Manager').uid; - developerRole = stackRoles.find(role => role.name === 'Developer').uid; + adminRole = stackRoles.find(role => role.name === 'Admin').uid + contentManagerRole = stackRoles.find(role => role.name === 'Content Manager').uid + developerRole = stackRoles.find(role => role.name === 'Developer').uid }) it('should add roles', done => { diff --git a/test/sanity-check/api/terms-test.js b/test/sanity-check/api/terms-test.js index 097ab370..871f870e 100644 --- a/test/sanity-check/api/terms-test.js +++ b/test/sanity-check/api/terms-test.js @@ -47,19 +47,19 @@ describe('Terms API Test', () => { it('should create term', async () => { const response = await makeTerms(taxonomy.uid).create(term) expect(response.uid).to.be.equal(term.term.uid) - await new Promise(resolve => setTimeout(resolve, 15000)); + await new Promise(resolve => setTimeout(resolve, 15000)) }) it('should create child term 1', async () => { const response = await makeTerms(taxonomy.uid).create(childTerm1) expect(response.uid).to.be.equal(childTerm1.term.uid) - await new Promise(resolve => setTimeout(resolve, 15000)); + await new Promise(resolve => setTimeout(resolve, 15000)) }) it('should create child term 2', async () => { const response = await makeTerms(taxonomy.uid).create(childTerm2) expect(response.uid).to.be.equal(childTerm2.term.uid) - await new Promise(resolve => setTimeout(resolve, 15000)); + await new Promise(resolve => setTimeout(resolve, 15000)) }) it('should query and get all terms', done => { @@ -172,15 +172,15 @@ describe('Branch creation api Test', () => { }) it('should create staging branch', async () => { - const response = await makeBranch().create({ branch: stageBranch }); - expect(response.uid).to.be.equal(stageBranch.uid); - expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`); - expect(response.source).to.be.equal(stageBranch.source); - expect(response.alias).to.not.equal(undefined); - expect(response.fetch).to.not.equal(undefined); - expect(response.delete).to.not.equal(undefined); - await new Promise(resolve => setTimeout(resolve, 15000)); - }); + const response = await makeBranch().create({ branch: stageBranch }) + expect(response.uid).to.be.equal(stageBranch.uid) + expect(response.urlPath).to.be.equal(`/stacks/branches/${stageBranch.uid}`) + expect(response.source).to.be.equal(stageBranch.source) + expect(response.alias).to.not.equal(undefined) + expect(response.fetch).to.not.equal(undefined) + expect(response.delete).to.not.equal(undefined) + await new Promise(resolve => setTimeout(resolve, 15000)) + }) }) function makeBranch (uid = null) { diff --git a/test/sanity-check/api/ungroupedVariants-test.js b/test/sanity-check/api/ungroupedVariants-test.js index 38eb19f4..ac2fbf11 100644 --- a/test/sanity-check/api/ungroupedVariants-test.js +++ b/test/sanity-check/api/ungroupedVariants-test.js @@ -4,23 +4,21 @@ import { jsonReader } from '../utility/fileOperations/readwrite' import { contentstackClient } from '../utility/ContentstackClient.js' var client = {} -var stack = {} const variants = { - "uid": "iphone_color_white", // optional - "name": "White", - "personalize_metadata": { - "experience_uid": "exp1", - "experience_short_uid": "expShortUid1", - "project_uid": "project_uid1", - "variant_short_uid": "variantShort_uid1" - }, + uid: 'iphone_color_white', // optional + name: 'White', + personalize_metadata: { + experience_uid: 'exp1', + experience_short_uid: 'expShortUid1', + project_uid: 'project_uid1', + variant_short_uid: 'variantShort_uid1' + } } var variantsUID = '' describe('Ungrouped Variants api Test', () => { setup(() => { const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') client = contentstackClient(user.authtoken) }) it('Should create ungrouped variants create', done => { @@ -94,6 +92,6 @@ describe('Ungrouped Variants api Test', () => { }) }) -function makeVariants(uid = null) { +function makeVariants (uid = null) { return client.stack({ api_key: process.env.API_KEY }).variants(uid) } diff --git a/test/sanity-check/api/variantGroup-test.js b/test/sanity-check/api/variantGroup-test.js index c1f1f080..4ad64ebf 100644 --- a/test/sanity-check/api/variantGroup-test.js +++ b/test/sanity-check/api/variantGroup-test.js @@ -1,17 +1,14 @@ import { expect } from 'chai' import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite' -import { createVariantGroup, createVariantGroup1, createVariantGroup2 } from '../mock/variantGroup.js' +import { createVariantGroup } from '../mock/variantGroup.js' import { contentstackClient } from '../utility/ContentstackClient.js' var client = {} -var stack = {} -var tokenUID = '' describe('Variant Group api Test', () => { setup(() => { const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') client = contentstackClient(user.authtoken) }) @@ -80,6 +77,6 @@ describe('Variant Group api Test', () => { }) }) -function makeVariantGroup(uid = null) { +function makeVariantGroup (uid = null) { return client.stack({ api_key: process.env.API_KEY }).variantGroup(uid) -} \ No newline at end of file +} diff --git a/test/sanity-check/api/variants-test.js b/test/sanity-check/api/variants-test.js index 6f73976a..297de7ca 100644 --- a/test/sanity-check/api/variants-test.js +++ b/test/sanity-check/api/variants-test.js @@ -2,19 +2,17 @@ import { expect } from 'chai' import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite' import { createVariantGroup } from '../mock/variantGroup.js' -import { variant, variant1, variant2 } from '../mock/variants.js' +import { variant } from '../mock/variants.js' import { contentstackClient } from '../utility/ContentstackClient.js' var client = {} -var stack = {} var variantUid = '' -var variantName = '' +let variantName = '' var variantGroupUid = '' describe('Variants api Test', () => { setup(() => { const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') client = contentstackClient(user.authtoken) }) @@ -64,7 +62,7 @@ describe('Variants api Test', () => { variants.items.forEach((variants) => { variantUid = variants.uid variantName = variants.name - expect(variants.name).to.be.not.equal(null) + expect(variantName).to.be.not.equal(null) expect(variants.uid).to.be.not.equal(null) }) done() @@ -129,10 +127,10 @@ describe('Variants api Test', () => { }) }) -function makeVariants(uid = null) { +function makeVariants (uid = null) { return client.stack({ api_key: process.env.API_KEY }).variantGroup(variantGroupUid).variants(uid) } -function makeVariantGroup(uid = null) { +function makeVariantGroup (uid = null) { return client.stack({ api_key: process.env.API_KEY }).variantGroup(uid) -} \ No newline at end of file +} diff --git a/test/sanity-check/mock/globalfield.js b/test/sanity-check/mock/globalfield.js index ef1d3ec0..46a529b3 100644 --- a/test/sanity-check/mock/globalfield.js +++ b/test/sanity-check/mock/globalfield.js @@ -1,71 +1,71 @@ const createGlobalField = { global_field: { - title: "First", - uid: "first", + title: 'First', + uid: 'first', schema: [ { - display_name: "Name", - uid: "name", - data_type: "text", + display_name: 'Name', + uid: 'name', + data_type: 'text' }, { - data_type: "text", - display_name: "Rich text editor", - uid: "description", + data_type: 'text', + display_name: 'Rich text editor', + uid: 'description', field_metadata: { allow_rich_text: true, - description: "", + description: '', multiline: false, - rich_text_type: "advanced", + rich_text_type: 'advanced', options: [], - version: 3, + version: 3 }, multiple: false, mandatory: false, - unique: false, - }, - ], - }, -}; + unique: false + } + ] + } +} const createNestedGlobalField = { - "global_field": { - "title": "Nested Global Fields9", - "uid": "nested_global_field9", - "schema": [ - { - "data_type": "text", - "display_name": "Single Line Textbox", - "uid": "single_line" - }, - { - "data_type": "global_field", - "display_name": "Global", - "uid": "global_field", - "reference_to": "nested_global_field33" - } - ] + global_field: { + title: 'Nested Global Fields9', + uid: 'nested_global_field9', + schema: [ + { + data_type: 'text', + display_name: 'Single Line Textbox', + uid: 'single_line' + }, + { + data_type: 'global_field', + display_name: 'Global', + uid: 'global_field', + reference_to: 'nested_global_field33' + } + ] } } const createNestedGlobalFieldForReference = { - "global_field": { - "title": "nested global field for reference", - "uid": "nested_global_field33", - "schema": [ - { - "data_type": "text", - "display_name": "Single Line Textbox", - "uid": "single_line" - }, - { - "data_type": "global_field", - "display_name": "Global", - "uid": "global_field", - "reference_to": "first" - } - ] + global_field: { + title: 'nested global field for reference', + uid: 'nested_global_field33', + schema: [ + { + data_type: 'text', + display_name: 'Single Line Textbox', + uid: 'single_line' + }, + { + data_type: 'global_field', + display_name: 'Global', + uid: 'global_field', + reference_to: 'first' + } + ] } } -export { createGlobalField, createNestedGlobalField, createNestedGlobalFieldForReference }; +export { createGlobalField, createNestedGlobalField, createNestedGlobalFieldForReference } diff --git a/test/sanity-check/mock/variantEntry.js b/test/sanity-check/mock/variantEntry.js index ac8d9ef6..b73eede6 100644 --- a/test/sanity-check/mock/variantEntry.js +++ b/test/sanity-check/mock/variantEntry.js @@ -1,49 +1,49 @@ const variantEntryFirst = { entry: { - title: "First page variant", - url: "/first-page-variant", + title: 'First page variant', + url: '/first-page-variant', _variant: { - _change_set: ["title", "url"], - }, - }, -}; + _change_set: ['title', 'url'] + } + } +} var publishVariantEntryFirst = { entry: { - environments: ["development"], - locales: ["en-us", "en-at"], + environments: ['development'], + locales: ['en-us', 'en-at'], variants: [ { - uid: "", - version: 1, - }, + uid: '', + version: 1 + } ], variant_rules: { publish_latest_base: false, - publish_latest_base_conditionally: true, - }, + publish_latest_base_conditionally: true + } }, - locale: "en-us", - version: 1, -}; + locale: 'en-us', + version: 1 +} const unpublishVariantEntryFirst = { entry: { - environments: ["development"], - locales: ["en-at"], + environments: ['development'], + locales: ['en-at'], variants: [ { - uid: "", - version: 1, - }, + uid: '', + version: 1 + } ], variant_rules: { publish_latest_base: false, - publish_latest_base_conditionally: true, - }, + publish_latest_base_conditionally: true + } }, - locale: "en-us", - version: 1, -}; + locale: 'en-us', + version: 1 +} -export { variantEntryFirst, publishVariantEntryFirst, unpublishVariantEntryFirst }; +export { variantEntryFirst, publishVariantEntryFirst, unpublishVariantEntryFirst } diff --git a/test/sanity-check/mock/variantGroup.js b/test/sanity-check/mock/variantGroup.js index a4f24b1f..1187b6fd 100644 --- a/test/sanity-check/mock/variantGroup.js +++ b/test/sanity-check/mock/variantGroup.js @@ -1,82 +1,82 @@ const createVariantGroup = { - "name": "Colors", - "content_types": [ - "multi_page" - ], - "uid": "iphone_color_white", - } + name: 'Colors', + content_types: [ + 'multi_page' + ], + uid: 'iphone_color_white' +} const createVariantGroup1 = { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "uid11", - "name": "iPhone Colors", - "content_types": [ - "multi_page" - ], - "source" : "Personalize" - } + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'uid11', + name: 'iPhone Colors', + content_types: [ + 'multi_page' + ], + source: 'Personalize' +} const createVariantGroup2 = { - count: 2, - variant_groups: [ - { - "uid": "uid21", - "name": "iPhone Colors", - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "content_types": [ - "multi_page" - ], - "variant_count": 1, - "variants": [ - { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_white", - "name": "White" - } - ] - }, - { - "uid": "uid22", - "name": "iPhone", - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "content_types": [ - "iphone_prod_desc" - ], - "variant_count": 1, - "variants": [ - { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_white", - "name": "White" - } - ] - } - ], - ungrouped_variants: [ - { - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_red", - "name": "Red" - } - ], - ungrouped_variant_count: 1 - } + count: 2, + variant_groups: [ + { + uid: 'uid21', + name: 'iPhone Colors', + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + content_types: [ + 'multi_page' + ], + variant_count: 1, + variants: [ + { + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_white', + name: 'White' + } + ] + }, + { + uid: 'uid22', + name: 'iPhone', + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + content_types: [ + 'iphone_prod_desc' + ], + variant_count: 1, + variants: [ + { + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_white', + name: 'White' + } + ] + } + ], + ungrouped_variants: [ + { + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_red', + name: 'Red' + } + ], + ungrouped_variant_count: 1 +} export { createVariantGroup, createVariantGroup1, createVariantGroup2 } diff --git a/test/sanity-check/mock/variants.js b/test/sanity-check/mock/variants.js index d23636ba..6ec68040 100644 --- a/test/sanity-check/mock/variants.js +++ b/test/sanity-check/mock/variants.js @@ -1,50 +1,50 @@ const variant = { - "uid": "white", // optional - "name": "White", - "personalize_metadata": { // optional sent from personalize while creating variant - "experience_uid": "exp1", - "experience_short_uid": "expShortUid1", - "project_uid": "project_uid1", - "variant_short_uid": "variantShort_uid1" - }, + uid: 'white', // optional + name: 'White', + personalize_metadata: { // optional sent from personalize while creating variant + experience_uid: 'exp1', + experience_short_uid: 'expShortUid1', + project_uid: 'project_uid1', + variant_short_uid: 'variantShort_uid1' } +} const variant1 = { - "created_by": "blt6cdf4e0b02b1c446", - "updated_by": "blt303b74fa96e1082a", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_white", - "name": "White", - } + created_by: 'blt6cdf4e0b02b1c446', + updated_by: 'blt303b74fa96e1082a', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_white', + name: 'White' +} const variant2 = { - "uid": "variant_group_1", - "name": "Variant Group 1", - "content_types": [ - "CTSTAET123" - ], - "personalize_metadata": { - "experience_uid": "variant_group_ex_uid", - "experience_short_uid": "variant_group_short_uid", - "project_uid": "variant_group_project_uid" - }, - "variants": [ // variants inside the group - { - "uid": "variant1", - "created_by": "user_id", - "updated_by": "user_id", - "name": "Variant 1", - "personalize_metadata": { - "experience_uid": "exp1", - "experience_short_uid": "expShortUid1", - "project_uid": "project_uid1", - "variant_short_uid": "variantShort_uid1" - }, - "created_at": "2024-04-16T05:53:50.547Z", - "updated_at": "2024-04-16T05:53:50.547Z" - } - ], - "count": 1 + uid: 'variant_group_1', + name: 'Variant Group 1', + content_types: [ + 'CTSTAET123' + ], + personalize_metadata: { + experience_uid: 'variant_group_ex_uid', + experience_short_uid: 'variant_group_short_uid', + project_uid: 'variant_group_project_uid' + }, + variants: [ // variants inside the group + { + uid: 'variant1', + created_by: 'user_id', + updated_by: 'user_id', + name: 'Variant 1', + personalize_metadata: { + experience_uid: 'exp1', + experience_short_uid: 'expShortUid1', + project_uid: 'project_uid1', + variant_short_uid: 'variantShort_uid1' + }, + created_at: '2024-04-16T05:53:50.547Z', + updated_at: '2024-04-16T05:53:50.547Z' + } + ], + count: 1 } export { variant, variant1, variant2 } diff --git a/test/unit/asset-test.js b/test/unit/asset-test.js index d0c3dfc7..24926889 100644 --- a/test/unit/asset-test.js +++ b/test/unit/asset-test.js @@ -316,7 +316,6 @@ describe('Contentstack Asset test', () => { .catch(done) }) - it('Asset download test', done => { var mock = new MockAdapter(Axios) const downloadResponse = new Blob(['file content'], { type: 'text/plain' }) @@ -352,7 +351,7 @@ describe('Contentstack Asset test', () => { }) .download({ responseType: 'blob' }) .then((response) => { - console.log("🚀 ~ .then ~ response:", response) + console.log('🚀 ~ .then ~ response:', response) expect(response.data).to.be.instanceOf(Blob) expect(response.data.type).to.be.equal('text/plain') done() diff --git a/test/unit/branchAlias-test.js b/test/unit/branchAlias-test.js index 4fd8bd99..f8f0fa35 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 => { diff --git a/test/unit/bulkOperation-test.js b/test/unit/bulkOperation-test.js index e0324146..07e1d7fb 100644 --- a/test/unit/bulkOperation-test.js +++ b/test/unit/bulkOperation-test.js @@ -1,33 +1,33 @@ -import Axios from 'axios'; -import { expect } from 'chai'; -import MockAdapter from 'axios-mock-adapter'; -import { describe, it } from 'mocha'; -import { BulkOperation } from '../../lib/stack/bulkOperation'; -import { stackHeadersMock } from './mock/objects'; +import Axios from 'axios' +import { expect } from 'chai' +import MockAdapter from 'axios-mock-adapter' +import { describe, it } from 'mocha' +import { BulkOperation } from '../../lib/stack/bulkOperation' +import { stackHeadersMock } from './mock/objects' describe('Contentstack BulkOperation test', () => { it('BulkOperation test without uid', done => { - const bulkOperation = makeBulkOperation(); - expect(bulkOperation.urlPath).to.be.equal('/bulk'); - expect(bulkOperation.stackHeaders).to.be.equal(undefined); - expect(bulkOperation.addItems).to.not.equal(undefined); - expect(bulkOperation.publish).to.not.equal(undefined); - expect(bulkOperation.unpublish).to.not.equal(undefined); - expect(bulkOperation.delete).to.not.equal(undefined); - done(); - }); + const bulkOperation = makeBulkOperation() + expect(bulkOperation.urlPath).to.be.equal('/bulk') + expect(bulkOperation.stackHeaders).to.be.equal(undefined) + expect(bulkOperation.addItems).to.not.equal(undefined) + expect(bulkOperation.publish).to.not.equal(undefined) + expect(bulkOperation.unpublish).to.not.equal(undefined) + expect(bulkOperation.delete).to.not.equal(undefined) + done() + }) it('BulkOperation test with stackHeaders', done => { - const bulkOperation = makeBulkOperation({ stackHeaders: { ...stackHeadersMock } }); - expect(bulkOperation.urlPath).to.be.equal('/bulk'); - expect(bulkOperation.stackHeaders).to.not.equal(undefined); - expect(bulkOperation.stackHeaders.api_key).to.be.equal(stackHeadersMock.api_key); - expect(bulkOperation.addItems).to.not.equal(undefined); - expect(bulkOperation.publish).to.not.equal(undefined); - expect(bulkOperation.unpublish).to.not.equal(undefined); - expect(bulkOperation.delete).to.not.equal(undefined); - done(); - }); + const bulkOperation = makeBulkOperation({ stackHeaders: { ...stackHeadersMock } }) + expect(bulkOperation.urlPath).to.be.equal('/bulk') + expect(bulkOperation.stackHeaders).to.not.equal(undefined) + expect(bulkOperation.stackHeaders.api_key).to.be.equal(stackHeadersMock.api_key) + expect(bulkOperation.addItems).to.not.equal(undefined) + expect(bulkOperation.publish).to.not.equal(undefined) + expect(bulkOperation.unpublish).to.not.equal(undefined) + expect(bulkOperation.delete).to.not.equal(undefined) + done() + }) it('should add items to a release', async () => { const items = { @@ -41,21 +41,21 @@ describe('Contentstack BulkOperation test', () => { uid: 'entry_uid', version: 2, locale: 'en-us', - title: 'validation test', - }, - ], - }; + title: 'validation test' + } + ] + } - var mock = new MockAdapter(Axios); + var mock = new MockAdapter(Axios) mock.onPost('/bulk/release/items').reply(200, { notice: 'Your add to release request is in progress.', - job_id: 'job_id', - }); + job_id: 'job_id' + }) - const response = await makeBulkOperation().addItems({ data: items, bulk_version: '2.0' }); - expect(response.notice).to.equal('Your add to release request is in progress.'); - expect(response.job_id).to.not.equal(undefined); - }); + const response = await makeBulkOperation().addItems({ data: items, bulk_version: '2.0' }) + expect(response.notice).to.equal('Your add to release request is in progress.') + expect(response.job_id).to.not.equal(undefined) + }) it('should update items to a release', async () => { const items = { @@ -65,19 +65,19 @@ describe('Contentstack BulkOperation test', () => { reference: true, items: [ '$all' - ], - }; + ] + } - var mock = new MockAdapter(Axios); + var mock = new MockAdapter(Axios) mock.onPut('/bulk/release/update_items').reply(200, { notice: 'Your update release items to latest version request is in progress.', - job_id: 'job_id', - }); + job_id: 'job_id' + }) - const response = await makeBulkOperation().updateItems({ data: items, bulk_version: '2.0' }); - expect(response.notice).to.equal('Your update release items to latest version request is in progress.'); - expect(response.job_id).to.not.equal(undefined); - }); + const response = await makeBulkOperation().updateItems({ data: items, bulk_version: '2.0' }) + expect(response.notice).to.equal('Your update release items to latest version request is in progress.') + expect(response.job_id).to.not.equal(undefined) + }) it('should publish items in bulk', async () => { const publishDetails = { @@ -86,24 +86,24 @@ describe('Contentstack BulkOperation test', () => { uid: 'entry_uid', content_type: 'content_type_uid', version: 'version', - locale: 'entry_locale', - }, + locale: 'entry_locale' + } ], assets: [{ uid: 'uid' }], locales: ['en'], - environments: ['env_uid'], - }; + environments: ['env_uid'] + } - var mock = new MockAdapter(Axios); + var mock = new MockAdapter(Axios) mock.onPost('/bulk/publish').reply(200, { notice: 'Your publish request is in progress.', - job_id: 'job_id', - }); + job_id: 'job_id' + }) - const response = await makeBulkOperation().publish({ details: publishDetails }); - expect(response.notice).to.equal('Your publish request is in progress.'); - expect(response.job_id).to.not.equal(undefined); - }); + const response = await makeBulkOperation().publish({ details: publishDetails }) + expect(response.notice).to.equal('Your publish request is in progress.') + expect(response.job_id).to.not.equal(undefined) + }) it('should unpublish items in bulk', async () => { const unpublishDetails = { @@ -112,24 +112,24 @@ describe('Contentstack BulkOperation test', () => { uid: 'entry_uid', content_type: 'content_type_uid', version: 'version', - locale: 'entry_locale', - }, + locale: 'entry_locale' + } ], assets: [{ uid: 'uid' }], locales: ['en'], - environments: ['env_uid'], - }; + environments: ['env_uid'] + } - var mock = new MockAdapter(Axios); + var mock = new MockAdapter(Axios) mock.onPost('/bulk/unpublish').reply(200, { notice: 'Your unpublish request is in progress.', - job_id: 'job_id', - }); + job_id: 'job_id' + }) - const response = await makeBulkOperation().unpublish({ details: unpublishDetails }); - expect(response.notice).to.equal('Your unpublish request is in progress.'); - expect(response.job_id).to.not.equal(undefined); - }); + const response = await makeBulkOperation().unpublish({ details: unpublishDetails }) + expect(response.notice).to.equal('Your unpublish request is in progress.') + expect(response.job_id).to.not.equal(undefined) + }) it('should delete items in bulk', async () => { const deleteDetails = { @@ -137,22 +137,22 @@ describe('Contentstack BulkOperation test', () => { { uid: 'entry_uid', content_type: 'content_type_uid', - locale: 'entry_locale', - }, + locale: 'entry_locale' + } ], - assets: [{ uid: 'uid' }], - }; + assets: [{ uid: 'uid' }] + } - var mock = new MockAdapter(Axios); + var mock = new MockAdapter(Axios) mock.onPost('/bulk/delete').reply(200, { notice: 'Your delete request is in progress.', - job_id: 'job_id', - }); + job_id: 'job_id' + }) - const response = await makeBulkOperation().delete({ details: deleteDetails }); - expect(response.notice).to.equal('Your delete request is in progress.'); - expect(response.job_id).to.not.equal(undefined); - }); + const response = await makeBulkOperation().delete({ details: deleteDetails }) + expect(response.notice).to.equal('Your delete request is in progress.') + expect(response.job_id).to.not.equal(undefined) + }) it('should update items in bulk', async () => { const updateBody = { @@ -160,13 +160,13 @@ describe('Contentstack BulkOperation test', () => { { content_type: 'content_type_uid1', uid: 'entry_uid', - locale: 'en-us', + locale: 'en-us' }, { content_type: 'content_type_uid2', uid: 'entry_uid', - locale: 'en-us', - }, + locale: 'en-us' + } ], workflow: { workflow_stage: { @@ -178,48 +178,48 @@ describe('Contentstack BulkOperation test', () => { { uid: 'user_uid', name: 'user_name', - email: 'user_email_id', - }, + email: 'user_email_id' + } ], assigned_by_roles: [ { uid: 'role_uid', - name: 'role_name', - }, - ], - }, - }, - }; - - var mock = new MockAdapter(Axios); + name: 'role_name' + } + ] + } + } + } + + var mock = new MockAdapter(Axios) mock.onPost('/bulk/workflow').reply(200, { notice: 'Your update request is in progress.', - job_id: 'job_id', - }); + job_id: 'job_id' + }) - const response = await makeBulkOperation().update(updateBody); - expect(response.notice).to.equal('Your update request is in progress.'); - expect(response.job_id).to.not.equal(undefined); - }); + const response = await makeBulkOperation().update(updateBody) + expect(response.notice).to.equal('Your update request is in progress.') + expect(response.job_id).to.not.equal(undefined) + }) it('should fetch job status', async () => { - const jobId = 'job_id'; + const jobId = 'job_id' const jobStatusDetails = { - job_id: jobId, - }; + job_id: jobId + } - var mock = new MockAdapter(Axios); + var mock = new MockAdapter(Axios) mock.onGet(`/bulk/jobs/${jobId}`).reply(200, { notice: 'Your job status request is successful.', - status: 'completed', - }); - - const response = await makeBulkOperation().jobStatus(jobStatusDetails); - expect(response.notice).to.equal('Your job status request is successful.'); - expect(response.status).to.equal('completed'); - }); -}); - -function makeBulkOperation(data) { - return new BulkOperation(Axios, data); -} \ No newline at end of file + status: 'completed' + }) + + const response = await makeBulkOperation().jobStatus(jobStatusDetails) + expect(response.notice).to.equal('Your job status request is successful.') + expect(response.status).to.equal('completed') + }) +}) + +function makeBulkOperation (data) { + return new BulkOperation(Axios, data) +} diff --git a/test/unit/concurrency-Queue-test.js b/test/unit/concurrency-Queue-test.js index 04a6fb58..981ec556 100644 --- a/test/unit/concurrency-Queue-test.js +++ b/test/unit/concurrency-Queue-test.js @@ -2,7 +2,7 @@ import Axios from 'axios' import sinon from 'sinon' import { expect } from 'chai' import http from 'http' -import { describe, it } from 'mocha' +import { describe, it, before, beforeEach, after } from 'mocha' import MockAdapter from 'axios-mock-adapter' import { ConcurrencyQueue } from '../../lib/core/concurrency-queue' import FormData from 'form-data' @@ -185,6 +185,7 @@ describe('Concurrency queue test', () => { it('Initialize with bad axios instance', done => { try { + // eslint-disable-next-line no-new new ConcurrencyQueue({ axios: undefined }) expect.fail('Undefined axios should fail') } catch (error) { @@ -302,18 +303,20 @@ describe('Concurrency queue test', () => { const client = Axios.create({ baseURL: `${host}:${port}` }) - const concurrency = new ConcurrencyQueue({ axios: client, config: { retryCondition: (error) => { - if (error.response.status === 408) { - return true - } - return false - }, - logHandler: logHandlerStub, - retryDelayOptions: { - base: retryDelayOptionsStub() - }, - retryLimit: 2, - retryOnError: true, timeout: 250 } }) + const concurrency = new ConcurrencyQueue({ axios: client, + config: { retryCondition: (error) => { + if (error.response.status === 408) { + return true + } + return false + }, + logHandler: logHandlerStub, + retryDelayOptions: { + base: retryDelayOptionsStub() + }, + retryLimit: 2, + retryOnError: true, + timeout: 250 } }) client.get('http://localhost:4444/timeout', { timeout: 250 }).then(function (res) { @@ -328,7 +331,7 @@ describe('Concurrency queue test', () => { }) it('Concurrency with 100 failing requests retry on error with no retry condition tests', done => { - reconfigureQueue({ retryCondition: (error) => false }) + reconfigureQueue({ retryCondition: () => false }) Promise.all(sequence(100).map(() => wrapPromise(api.get('/fail')))) .then((responses) => { return responses.map(r => r.data) diff --git a/test/unit/entry-test.js b/test/unit/entry-test.js index a0d113d2..0df9c293 100644 --- a/test/unit/entry-test.js +++ b/test/unit/entry-test.js @@ -275,7 +275,7 @@ describe('Contentstack Entry test', () => { ...noticeMock }) - const publishing_rule = { + const publishingRule = { 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’), @@ -283,7 +283,7 @@ describe('Contentstack Entry test', () => { comment: 'Please review this.' } makeEntry({ entry: { ...systemUidMock } }) - .publishRequest({ publishing_rule, locale: 'en-us' }) + .publishRequest({ publishing_rule: publishingRule, locale: 'en-us' }) .then((response) => { expect(response.notice).to.be.equal(noticeMock.notice) done() @@ -298,7 +298,7 @@ describe('Contentstack Entry test', () => { }) makeEntry({ entry: { ...systemUidMock }, stackHeaders: stackHeadersMock - }) + }) .includeVariants({ include_variant: 'True', variants_uid: 'test_uid' }) .then((response) => { expect(response.api_key).to.be.equal('api_key') @@ -315,7 +315,7 @@ describe('Contentstack Entry test', () => { ...noticeMock }) - const workflow_stage = { + const workflowStage = { uid: 'uid', comment: 'Please review this.', due_date: 'Thu Dec 01 2018', @@ -332,7 +332,7 @@ describe('Contentstack Entry test', () => { } makeEntry({ entry: { ...systemUidMock } }) - .setWorkflowStage({ workflow_stage, locale: 'en-us' }) + .setWorkflowStage({ workflow_stage: workflowStage, locale: 'en-us' }) .then((response) => { expect(response.notice).to.be.equal(noticeMock.notice) done() @@ -347,7 +347,7 @@ describe('Contentstack Entry test', () => { ...noticeMock }) - const workflow_stage = { + const workflowStage = { uid: 'uid', comment: 'Please review this.', due_date: 'Thu Dec 01 2018', @@ -364,7 +364,7 @@ describe('Contentstack Entry test', () => { } makeEntry({ entry: { ...systemUidMock }, stackHeaders: stackHeadersMock }) - .setWorkflowStage({ workflow_stage, locale: 'en-us' }) + .setWorkflowStage({ workflow_stage: workflowStage, locale: 'en-us' }) .then((response) => { expect(response.notice).to.be.equal(noticeMock.notice) done() @@ -378,7 +378,7 @@ describe('Contentstack Entry test', () => { ...noticeMock }) - const publishing_rule = { + const publishingRule = { 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’), @@ -386,7 +386,7 @@ describe('Contentstack Entry test', () => { comment: 'Please review this.' } makeEntry({ entry: { ...systemUidMock }, stackHeaders: stackHeadersMock }) - .publishRequest({ publishing_rule, locale: 'en-us' }) + .publishRequest({ publishing_rule: publishingRule, locale: 'en-us' }) .then((response) => { expect(response.notice).to.be.equal(noticeMock.notice) done() @@ -407,19 +407,19 @@ describe('Contentstack Entry test', () => { array_file: [ { file_size: 69420, uid: 'array_file_1' }, { file_size: 69420, uid: 'array_file_2' }, - { file_size: 69420, uid: 'array_file_3' }, + { file_size: 69420, uid: 'array_file_3' } ], wrapper1: { something: 'something', something_else: 'something_else', - file_inside_wrapper : { - file_size: 69420, - uid: 'single_file' + file_inside_wrapper: { + file_size: 69420, + uid: 'single_file' }, - file_array_wrapper : [ + file_array_wrapper: [ { file_size: 69420, uid: 'array_file_wrap_1' }, { file_size: 69420, uid: 'array_file_wrap_2' }, - { file_size: 69420, uid: 'array_file_wrap_3' }, + { file_size: 69420, uid: 'array_file_wrap_3' } ], array_wrapper: [ { @@ -451,11 +451,11 @@ describe('Contentstack Entry test', () => { array_of_array_wrapper: [ { something: 'something', - oneMoreWrapper : { - file_array_wrapper : [ + oneMoreWrapper: { + file_array_wrapper: [ { file_size: 69420, uid: 'array_file_wrap_1' }, { file_size: 69420, uid: 'array_file_wrap_2' }, - { file_size: 69420, uid: 'array_file_wrap_3' }, + { file_size: 69420, uid: 'array_file_wrap_3' } ], array_wrapper: [ { @@ -482,25 +482,25 @@ describe('Contentstack Entry test', () => { }, something_else: 'something_else' } - ], + ] }, something_else: 'something_else' }, { something: 'something', - file_array_wrapper : [ + file_array_wrapper: [ { file_size: 69420, uid: 'array_file_wrap_1' }, { file_size: 69420, uid: 'array_file_wrap_2' }, - { file_size: 69420, uid: 'array_file_wrap_3' }, + { file_size: 69420, uid: 'array_file_wrap_3' } ], something_else: 'something_else' }, { something: 'something', - file_array_wrapper : [ + file_array_wrapper: [ { file_size: 69420, uid: 'array_file_wrap_1' }, { file_size: 69420, uid: 'array_file_wrap_2' }, - { file_size: 69420, uid: 'array_file_wrap_3' }, + { file_size: 69420, uid: 'array_file_wrap_3' } ], something_else: 'something_else' } @@ -508,7 +508,7 @@ describe('Contentstack Entry test', () => { } }, ...systemUidMock - }; + } const expectedResult = { empty_array: [], empty_object: {}, @@ -519,8 +519,8 @@ describe('Contentstack Entry test', () => { wrapper1: { something: 'something', something_else: 'something_else', - file_inside_wrapper : 'single_file', - file_array_wrapper : ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], + file_inside_wrapper: 'single_file', + file_array_wrapper: ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], array_wrapper: [ { something: 'something', @@ -542,8 +542,8 @@ describe('Contentstack Entry test', () => { array_of_array_wrapper: [ { something: 'something', - oneMoreWrapper : { - file_array_wrapper : ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], + oneMoreWrapper: { + file_array_wrapper: ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], array_wrapper: [ { something: 'something', @@ -560,28 +560,28 @@ describe('Contentstack Entry test', () => { single_file: 'single_file_3', something_else: 'something_else' } - ], + ] }, something_else: 'something_else' }, { something: 'something', - file_array_wrapper : ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], + file_array_wrapper: ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], something_else: 'something_else' }, { something: 'something', - file_array_wrapper : ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], + file_array_wrapper: ['array_file_wrap_1', 'array_file_wrap_2', 'array_file_wrap_3'], something_else: 'something_else' } ] } }, ...systemUidMock - }; - const result = cleanAssets(entry); - expect(result).to.deep.equal(expectedResult); - done(); + } + const result = cleanAssets(entry) + expect(result).to.deep.equal(expectedResult) + done() }) it('should get languages of the given Entry uid', done => { @@ -619,11 +619,11 @@ describe('Contentstack Entry test', () => { var mock = new MockAdapter(Axios) const references = [ { - entry_uid: "entry_uid", - content_type_uid: "referred_content_type", - locale: "en-us", - title: "Jeff Goins", - content_type_title: "Referred Content Type" + entry_uid: 'entry_uid', + content_type_uid: 'referred_content_type', + locale: 'en-us', + title: 'Jeff Goins', + content_type_title: 'Referred Content Type' } ] mock.onGet('/content_types/content_type_uid/entries/UID/references').reply(200, { diff --git a/test/unit/globalField-test.js b/test/unit/globalField-test.js index 0de87493..f9c2f912 100644 --- a/test/unit/globalField-test.js +++ b/test/unit/globalField-test.js @@ -6,479 +6,479 @@ import { GlobalField, GlobalFieldCollection, createFormData } from '../../lib/st import { systemUidMock, checkSystemFields, globalFieldMock, stackHeadersMock, noticeMock, nestedGlobalFieldMock, nestedGlobalFieldPayload } from './mock/objects' import MockAdapter from 'axios-mock-adapter' -describe("Contentstack GlobalField test", () => { - it("GlobalField test without uid", (done) => { - const globalField = makeGlobalField(); - expect(globalField.urlPath).to.be.equal("/global_fields"); - expect(globalField.stackHeaders).to.be.equal(undefined); - expect(globalField.update).to.be.equal(undefined); - expect(globalField.delete).to.be.equal(undefined); - expect(globalField.fetch).to.be.equal(undefined); - expect(globalField.create).to.not.equal(undefined); - expect(globalField.query).to.not.equal(undefined); - done(); - }); - - it("GlobalField test with uid", (done) => { +describe('Contentstack GlobalField test', () => { + it('GlobalField test without uid', (done) => { + const globalField = makeGlobalField() + expect(globalField.urlPath).to.be.equal('/global_fields') + expect(globalField.stackHeaders).to.be.equal(undefined) + expect(globalField.update).to.be.equal(undefined) + expect(globalField.delete).to.be.equal(undefined) + expect(globalField.fetch).to.be.equal(undefined) + expect(globalField.create).to.not.equal(undefined) + expect(globalField.query).to.not.equal(undefined) + done() + }) + + it('GlobalField test with uid', (done) => { const globalField = makeGlobalField({ global_field: { - ...systemUidMock, - }, - }); + ...systemUidMock + } + }) expect(globalField.urlPath).to.be.equal( `/global_fields/${systemUidMock.uid}` - ); - expect(globalField.stackHeaders).to.be.equal(undefined); - expect(globalField.update).to.not.equal(undefined); - expect(globalField.delete).to.not.equal(undefined); - expect(globalField.fetch).to.not.equal(undefined); - expect(globalField.create).to.be.equal(undefined); - expect(globalField.query).to.be.equal(undefined); - done(); - }); - - it("GlobalField test with Stack Headers", (done) => { + ) + expect(globalField.stackHeaders).to.be.equal(undefined) + expect(globalField.update).to.not.equal(undefined) + expect(globalField.delete).to.not.equal(undefined) + expect(globalField.fetch).to.not.equal(undefined) + expect(globalField.create).to.be.equal(undefined) + expect(globalField.query).to.be.equal(undefined) + done() + }) + + it('GlobalField test with Stack Headers', (done) => { const globalField = makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, - stackHeaders: stackHeadersMock, - }); + stackHeaders: stackHeadersMock + }) expect(globalField.urlPath).to.be.equal( `/global_fields/${systemUidMock.uid}` - ); - expect(globalField.stackHeaders).to.not.equal(undefined); + ) + expect(globalField.stackHeaders).to.not.equal(undefined) expect(globalField.stackHeaders.api_key).to.be.equal( stackHeadersMock.api_key - ); - expect(globalField.update).to.not.equal(undefined); - expect(globalField.delete).to.not.equal(undefined); - expect(globalField.fetch).to.not.equal(undefined); - expect(globalField.create).to.be.equal(undefined); - expect(globalField.query).to.be.equal(undefined); - done(); - }); - - it("GlobalField Collection test with blank data", (done) => { - const globalFields = new GlobalFieldCollection(Axios, {}); - expect(globalFields.length).to.be.equal(0); - done(); - }); - - it("GlobalField Collection test with data", (done) => { + ) + expect(globalField.update).to.not.equal(undefined) + expect(globalField.delete).to.not.equal(undefined) + expect(globalField.fetch).to.not.equal(undefined) + expect(globalField.create).to.be.equal(undefined) + expect(globalField.query).to.be.equal(undefined) + done() + }) + + it('GlobalField Collection test with blank data', (done) => { + const globalFields = new GlobalFieldCollection(Axios, {}) + expect(globalFields.length).to.be.equal(0) + done() + }) + + it('GlobalField Collection test with data', (done) => { const globalFields = new GlobalFieldCollection(Axios, { - global_fields: [globalFieldMock], - }); - expect(globalFields.length).to.be.equal(1); - checkGlobalField(globalFields[0]); - done(); - }); - - it("GlobalField create test", (done) => { - var mock = new MockAdapter(Axios); - mock.onPost("/global_fields").reply(200, { + global_fields: [globalFieldMock] + }) + expect(globalFields.length).to.be.equal(1) + checkGlobalField(globalFields[0]) + done() + }) + + it('GlobalField create test', (done) => { + var mock = new MockAdapter(Axios) + mock.onPost('/global_fields').reply(200, { global_field: { - ...globalFieldMock, - }, - }); + ...globalFieldMock + } + }) makeGlobalField() .create() .then((globalField) => { - checkGlobalField(globalField.global_field); - done(); + checkGlobalField(globalField.global_field) + done() }) - .catch(done); - }); - - it("GlobalField Query test", (done) => { - var mock = new MockAdapter(Axios); - mock.onGet("/global_fields").reply(200, { - global_fields: [globalFieldMock], - }); + .catch(done) + }) + + it('GlobalField Query test', (done) => { + var mock = new MockAdapter(Axios) + mock.onGet('/global_fields').reply(200, { + global_fields: [globalFieldMock] + }) makeGlobalField() .query() .find() .then((globalField) => { - checkGlobalField(globalField.items[0]); - done(); + checkGlobalField(globalField.items[0]) + done() }) - .catch(done); - }); + .catch(done) + }) - it("GlobalField update test", (done) => { - var mock = new MockAdapter(Axios); - mock.onPut("/global_fields/UID").reply(200, { + it('GlobalField update test', (done) => { + var mock = new MockAdapter(Axios) + mock.onPut('/global_fields/UID').reply(200, { global_field: { - ...globalFieldMock, - }, - }); + ...globalFieldMock + } + }) makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, - stackHeaders: stackHeadersMock, + stackHeaders: stackHeadersMock }) .update() .then((globalField) => { - checkGlobalField(globalField.global_field); - done(); + checkGlobalField(globalField.global_field) + done() }) - .catch(done); - }); + .catch(done) + }) - it("GlobalField fetch test", (done) => { - var mock = new MockAdapter(Axios); - mock.onGet("/global_fields/UID").reply(200, { + it('GlobalField fetch test', (done) => { + var mock = new MockAdapter(Axios) + mock.onGet('/global_fields/UID').reply(200, { global_field: { - ...globalFieldMock, - }, - }); + ...globalFieldMock + } + }) makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, - stackHeaders: stackHeadersMock, + stackHeaders: stackHeadersMock }) .fetch() .then((globalField) => { - checkGlobalField(globalField.global_field); - done(); + checkGlobalField(globalField.global_field) + done() }) - .catch(done); - }); - - it("GlobalField delete test", (done) => { - var mock = new MockAdapter(Axios); - mock.onDelete("/global_fields/UID").reply(200, { - ...noticeMock, - }); + .catch(done) + }) + + it('GlobalField delete test', (done) => { + var mock = new MockAdapter(Axios) + mock.onDelete('/global_fields/UID').reply(200, { + ...noticeMock + }) makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, - stackHeaders: stackHeadersMock, + stackHeaders: stackHeadersMock }) .delete() .then((response) => { - expect(response.notice).to.be.equal(noticeMock.notice); - done(); + expect(response.notice).to.be.equal(noticeMock.notice) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Global Field import test", (done) => { - var mock = new MockAdapter(Axios); - mock.onPost("/global_fields/import").reply(200, { + it('Global Field import test', (done) => { + var mock = new MockAdapter(Axios) + mock.onPost('/global_fields/import').reply(200, { global_field: { - ...globalFieldMock, - }, - }); + ...globalFieldMock + } + }) const gfUpload = { - global_field: path.join(__dirname, "../api/mock/globalfield.json"), - }; - const form = createFormData(gfUpload)(); - var boundary = form.getBoundary(); + 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); + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) makeGlobalField() .import() .then((webhook) => { - checkGlobalField(webhook); - done(); + checkGlobalField(webhook) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Global Field import test with overwrite flag", (done) => { - var mock = new MockAdapter(Axios); - mock.onPost("/global_fields/import").reply(200, { + it('Global Field import test with overwrite flag', (done) => { + var mock = new MockAdapter(Axios) + mock.onPost('/global_fields/import').reply(200, { global_field: { - ...globalFieldMock, - }, - }); + ...globalFieldMock + } + }) const gfUpload = { - global_field: path.join(__dirname, "../api/mock/globalfield.json"), - }; - const form = createFormData(gfUpload)(); - var boundary = form.getBoundary(); + 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); + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) makeGlobalField() .import(gfUpload, { overwrite: true }) .then((webhook) => { - checkGlobalField(webhook); - done(); + checkGlobalField(webhook) + done() }) - .catch(done); - }); -}); + .catch(done) + }) +}) -describe("Contentstack GlobalField test (API Version 3.2)", () => { - it("GlobalField test without uid", (done) => { +describe('Contentstack GlobalField test (API Version 3.2)', () => { + it('GlobalField test without uid', (done) => { const globalField = makeGlobalField({ stackHeaders: stackHeadersMock, - api_version: "3.2"}); - expect(globalField.urlPath).to.be.equal("/global_fields"); - expect(globalField.apiVersion).to.be.equal("3.2"); - expect(globalField.stackHeaders).to.deep.equal({api_key: 'api_key', api_version: '3.2'}); - done(); - }); - - it("GlobalField test with uid", (done) => { + api_version: '3.2' }) + expect(globalField.urlPath).to.be.equal('/global_fields') + expect(globalField.apiVersion).to.be.equal('3.2') + expect(globalField.stackHeaders).to.deep.equal({ api_key: 'api_key', api_version: '3.2' }) + done() + }) + + it('GlobalField test with uid', (done) => { const globalField = makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, stackHeaders: stackHeadersMock, - api_version: "3.2", - }); + api_version: '3.2' + }) expect(globalField.urlPath).to.be.equal( `/global_fields/${systemUidMock.uid}` - ); - expect(globalField.apiVersion).to.be.equal("3.2"); - expect(globalField.update).to.not.equal(undefined); - expect(globalField.delete).to.not.equal(undefined); - expect(globalField.fetch).to.not.equal(undefined); - expect(globalField.create).to.be.equal(undefined); - expect(globalField.query).to.be.equal(undefined); - done(); - }); - - it("GlobalField test with Stack Headers", (done) => { + ) + expect(globalField.apiVersion).to.be.equal('3.2') + expect(globalField.update).to.not.equal(undefined) + expect(globalField.delete).to.not.equal(undefined) + expect(globalField.fetch).to.not.equal(undefined) + expect(globalField.create).to.be.equal(undefined) + expect(globalField.query).to.be.equal(undefined) + done() + }) + + it('GlobalField test with Stack Headers', (done) => { const globalField = makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, stackHeaders: stackHeadersMock, - api_version: "3.2", - }); + api_version: '3.2' + }) expect(globalField.urlPath).to.be.equal( `/global_fields/${systemUidMock.uid}` - ); - expect(globalField.apiVersion).to.be.equal("3.2"); - expect(globalField.stackHeaders).to.not.equal(undefined); + ) + expect(globalField.apiVersion).to.be.equal('3.2') + expect(globalField.stackHeaders).to.not.equal(undefined) expect(globalField.stackHeaders.api_key).to.be.equal( stackHeadersMock.api_key - ); - expect(globalField.update).to.not.equal(undefined); - expect(globalField.delete).to.not.equal(undefined); - expect(globalField.fetch).to.not.equal(undefined); - expect(globalField.create).to.be.equal(undefined); - expect(globalField.query).to.be.equal(undefined); - done(); - }); - - it("GlobalField Collection test with blank data", (done) => { + ) + expect(globalField.update).to.not.equal(undefined) + expect(globalField.delete).to.not.equal(undefined) + expect(globalField.fetch).to.not.equal(undefined) + expect(globalField.create).to.be.equal(undefined) + expect(globalField.query).to.be.equal(undefined) + done() + }) + + it('GlobalField Collection test with blank data', (done) => { const globalFields = new GlobalFieldCollection(Axios, { - api_version: "3.2", - }); - expect(globalFields.length).to.be.equal(0); - done(); - }); + api_version: '3.2' + }) + expect(globalFields.length).to.be.equal(0) + done() + }) - it("GlobalField Collection test with data", (done) => { + it('GlobalField Collection test with data', (done) => { const globalFields = new GlobalFieldCollection(Axios, { global_fields: [nestedGlobalFieldMock], - api_version: "3.2", - }); - expect(globalFields.length).to.be.equal(1); - checkGlobalField(globalFields[0]); - done(); - }); - - it("GlobalField create test", (done) => { - var mock = new MockAdapter(Axios); - mock.onPost("/global_fields").reply(200, { + api_version: '3.2' + }) + expect(globalFields.length).to.be.equal(1) + checkGlobalField(globalFields[0]) + done() + }) + + it('GlobalField create test', (done) => { + var mock = new MockAdapter(Axios) + mock.onPost('/global_fields').reply(200, { global_field: { - ...nestedGlobalFieldMock, - }, - }); + ...nestedGlobalFieldMock + } + }) makeGlobalField({ stackHeaders: stackHeadersMock, - api_version: "3.2"}) + api_version: '3.2' }) .create() .then((globalField) => { - checkGlobalField(globalField.global_field); - done(); + checkGlobalField(globalField.global_field) + done() }) - .catch(done); - }); + .catch(done) + }) - it("GlobalField Query test", (done) => { - var mock = new MockAdapter(Axios); - mock.onGet("/global_fields").reply(200, { - global_fields: [nestedGlobalFieldMock], - }); + it('GlobalField Query test', (done) => { + var mock = new MockAdapter(Axios) + mock.onGet('/global_fields').reply(200, { + global_fields: [nestedGlobalFieldMock] + }) makeGlobalField({ stackHeaders: stackHeadersMock, - api_version: "3.2"}) + api_version: '3.2' }) .query() .find() .then((globalField) => { - checkGlobalField(globalField.items[0]); - done(); + checkGlobalField(globalField.items[0]) + done() }) - .catch(done); - }); + .catch(done) + }) - it("GlobalField update test", (done) => { - var mock = new MockAdapter(Axios); - mock.onPut("/global_fields/UID").reply(200, { + it('GlobalField update test', (done) => { + var mock = new MockAdapter(Axios) + mock.onPut('/global_fields/UID').reply(200, { global_field: { - ...nestedGlobalFieldMock, - }, - }); + ...nestedGlobalFieldMock + } + }) makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, stackHeaders: stackHeadersMock, - api_version: "3.2", + api_version: '3.2' }) .update() .then((globalField) => { - checkGlobalField(globalField.global_field); - done(); + checkGlobalField(globalField.global_field) + done() }) - .catch(done); - }); + .catch(done) + }) - it("GlobalField fetch test", (done) => { - var mock = new MockAdapter(Axios); - mock.onGet("/global_fields/UID").reply(200, { + it('GlobalField fetch test', (done) => { + var mock = new MockAdapter(Axios) + mock.onGet('/global_fields/UID').reply(200, { global_field: { - ...nestedGlobalFieldMock, - }, - }); + ...nestedGlobalFieldMock + } + }) makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, stackHeaders: stackHeadersMock, - api_version: "3.2", + api_version: '3.2' }) .fetch() .then((globalField) => { - checkGlobalField(globalField.global_field); - done(); + checkGlobalField(globalField.global_field) + done() }) - .catch(done); - }); - - it("GlobalField delete test", (done) => { - var mock = new MockAdapter(Axios); - mock.onDelete("/global_fields/UID").reply(200, { - ...noticeMock, - }); + .catch(done) + }) + + it('GlobalField delete test', (done) => { + var mock = new MockAdapter(Axios) + mock.onDelete('/global_fields/UID').reply(200, { + ...noticeMock + }) makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, stackHeaders: stackHeadersMock, - api_version: "3.2", + api_version: '3.2' }) .delete() .then((response) => { - expect(response.notice).to.be.equal(noticeMock.notice); - done(); + expect(response.notice).to.be.equal(noticeMock.notice) + done() }) - .catch(done); - }); + .catch(done) + }) - it("GlobalField import test", (done) => { - var mock = new MockAdapter(Axios); - mock.onPost("/global_fields/import").reply(200, { + it('GlobalField import test', (done) => { + var mock = new MockAdapter(Axios) + mock.onPost('/global_fields/import').reply(200, { global_field: { - ...globalFieldMock, - }, - }); + ...globalFieldMock + } + }) const gfUpload = { - global_field: path.join(__dirname, "../api/mock/globalfield.json"), - }; - const form = createFormData(gfUpload)(); - var boundary = form.getBoundary(); + 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); + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) makeGlobalField({ stackHeaders: stackHeadersMock, - api_version: "3.2"}) + api_version: '3.2' }) .import() .then((webhook) => { - checkGlobalField(webhook); - done(); + checkGlobalField(webhook) + done() }) - .catch(done); - }); + .catch(done) + }) - it("GlobalField import test with overwrite flag", (done) => { - var mock = new MockAdapter(Axios); - mock.onPost("/global_fields/import").reply(200, { + it('GlobalField import test with overwrite flag', (done) => { + var mock = new MockAdapter(Axios) + mock.onPost('/global_fields/import').reply(200, { global_field: { - ...nestedGlobalFieldMock, - }, - }); + ...nestedGlobalFieldMock + } + }) const gfUpload = { - global_field: path.join(__dirname, "../api/mock/globalfield.json"), - }; - const form = createFormData(gfUpload)(); - var boundary = form.getBoundary(); + 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); + expect(boundary).to.be.equal(form.getBoundary()) + expect(boundary.length).to.be.equal(50) makeGlobalField({ stackHeaders: stackHeadersMock, - api_version: "3.2"}) + api_version: '3.2' }) .import(gfUpload, { overwrite: true }) .then((webhook) => { - checkGlobalField(webhook); - done(); + checkGlobalField(webhook) + done() }) - .catch(done); - }); + .catch(done) + }) - it("should update nested global field", (done) => { - var mock = new MockAdapter(Axios); + it('should update nested global field', (done) => { + var mock = new MockAdapter(Axios) const updatedData = { global_field: { - title: "Updated Nested Global Field Title", - schema: nestedGlobalFieldPayload, - }, - }; + title: 'Updated Nested Global Field Title', + schema: nestedGlobalFieldPayload + } + } mock .onPut(`/global_fields/${systemUidMock.uid}`) .reply(200, { global_field: { ...nestedGlobalFieldMock, - ...updatedData.global_field, - }, - }); + ...updatedData.global_field + } + }) makeGlobalField({ global_field: { - ...systemUidMock, + ...systemUidMock }, - stackHeaders: stackHeadersMock, + stackHeaders: stackHeadersMock }) .updateNestedGlobalField(updatedData) .then((response) => { - expect(response.global_field.title).to.be.equal("Updated Nested Global Field Title"); - expect(response.global_field.schema).to.deep.equal(nestedGlobalFieldPayload); - done(); + expect(response.global_field.title).to.be.equal('Updated Nested Global Field Title') + expect(response.global_field.schema).to.deep.equal(nestedGlobalFieldPayload) + done() }) - .catch(done); - }); -}); + .catch(done) + }) +}) function makeGlobalField (data) { return new GlobalField(Axios, data) } -function checkGlobalField(globalField) { - checkSystemFields(globalField); - expect(globalField.title).to.be.equal("title"); - expect(globalField.schema.length).to.be.equal(2); +function checkGlobalField (globalField) { + checkSystemFields(globalField) + expect(globalField.title).to.be.equal('title') + expect(globalField.schema.length).to.be.equal(2) } diff --git a/test/unit/mock/objects.js b/test/unit/mock/objects.js index 11e0e291..5aea75b5 100644 --- a/test/unit/mock/objects.js +++ b/test/unit/mock/objects.js @@ -149,88 +149,88 @@ const roleMock = { admin: false } const roleMockWithTaxonomy = { - ...systemFieldsMock, - ...systemFieldsUserMock, - name: "Admin", - description: "Admin Role", - rules: [ - { - module: "branch", - branches: [ - "main" - ], - acl: { - read: true - } - }, - { - module: "environment", - environments: ["env_uid1", "env_uid2"], - acl: { - read: true - } - }, - { - module: "locale", - locales: ["locales"], - acl: { - read: true - } - }, - { - module: "taxonomy", - taxonomies: ["taxonomy_1"], - terms: ["taxonomy_1.term_1"], - content_types: [ - { - uid: "$all", - acl: { + ...systemFieldsMock, + ...systemFieldsUserMock, + name: 'Admin', + description: 'Admin Role', + rules: [ + { + module: 'branch', + branches: [ + 'main' + ], + acl: { + read: true + } + }, + { + module: 'environment', + environments: ['env_uid1', 'env_uid2'], + acl: { + read: true + } + }, + { + module: 'locale', + locales: ['locales'], + acl: { + read: true + } + }, + { + module: 'taxonomy', + taxonomies: ['taxonomy_1'], + terms: ['taxonomy_1.term_1'], + content_types: [ + { + uid: '$all', + acl: { + read: true, + sub_acl: { read: true, - sub_acl: { - read: true, - create: true, - update: true, - delete: true, - publish: true - } + create: true, + update: true, + delete: true, + publish: true } } - ], - acl: { + } + ], + acl: { + read: true, + sub_acl: { read: true, - sub_acl: { - read: true, - create: true, - update: true, - delete: true, - publish: true - } + create: true, + update: true, + delete: true, + publish: true } - }, - { - module: "content_type", - content_types: ["ct_1"], - acl: { + } + }, + { + module: 'content_type', + content_types: ['ct_1'], + acl: { + read: true, + sub_acl: { read: true, - sub_acl: { - read: true, - create: true, - update: true, - delete: true, - publish: true - } + create: true, + update: true, + delete: true, + publish: true } } - ], - org_uid: "org_uid", - api_key: "api_key", - admin: false, - default: true, - users: [ - 'user_uid' - ] - } - + } + ], + org_uid: 'org_uid', + api_key: 'api_key', + admin: false, + default: true, + users: [ + 'user_uid' + ] +} + const branchMock = { ...systemFieldsMock, ...systemFieldsUserMock, @@ -473,30 +473,30 @@ const nestedGlobalFieldPayload = { field_metadata: { description: '', default_value: '', - version: 3, + version: 3 }, format: '', error_messages: { - format: '', + format: '' }, mandatory: false, multiple: false, non_localizable: false, - unique: false, + unique: false }, { data_type: 'global_field', display_name: 'Global', reference_to: 'nested_global_field1234', field_metadata: { - description: '', + description: '' }, uid: 'global_field', mandatory: false, multiple: false, non_localizable: false, - unique: false, - }, + unique: false + } ], global_field_refs: [ { @@ -506,16 +506,16 @@ const nestedGlobalFieldPayload = { paths: [ 'schema.1', 'schema.3.schema.4', - 'schema.4.blocks.0.schema.2', - ], + 'schema.4.blocks.0.schema.2' + ] }, { uid: 'nested_global_field_123', occurrence_count: 1, - isChild: false, - }, - ], - }, + isChild: false + } + ] + } } const entryMock = { @@ -531,54 +531,54 @@ const entryMock = { } const variantsEntriesMock = { - "title": "title", - "url": "/url", - "author": "Kurt Tank", - "created_by": "created_by", - "updated_by": "updated_by", - "created_at": "created_at_date", - "updated_at": "updated_at_date", - "uid": "UID", - "locale": "en-us", - "_version": 1, - "_in_progress": false, - "_variant": { - "uid": "_variant_uid", - "variant_id": 'variant_id', - "customized_fields": ["title", "author"], - "base_entry_version": 1, - } + title: 'title', + url: '/url', + author: 'Kurt Tank', + created_by: 'created_by', + updated_by: 'updated_by', + created_at: 'created_at_date', + updated_at: 'updated_at_date', + uid: 'UID', + locale: 'en-us', + _version: 1, + _in_progress: false, + _variant: { + uid: '_variant_uid', + variant_id: 'variant_id', + customized_fields: ['title', 'author'], + base_entry_version: 1 + } } const variantsUpdateEntryMock = { - "title": "title", - "url": "/url", - "uid": "UID", - "locale": "en-us", - "_version": 1, - "_in_progress": false, - "_variant": { - "customized_fields": ["title", "url"], + title: 'title', + url: '/url', + uid: 'UID', + locale: 'en-us', + _version: 1, + _in_progress: false, + _variant: { + customized_fields: ['title', 'url'] }, - "created_at": "created_at_date", - "updated_at": "updated_at_date", + created_at: 'created_at_date', + updated_at: 'updated_at_date' } const variantsEntryMock = { - "title": "title", - "url": "/url", - "locale": "en-us", - "uid": "UID", - "_version": 1, - "_in_progress": false, - "created_by": "created_by_uid", - "updated_by": "updated_by_uid", - "created_at": "created_at_date", - "updated_at": "updated_at_date", - "_variant": { - "uid": "_variant_uid", - "variant_id": 'variant_id', - "customized_fields": ["title"], - "base_entry_version": 10, - } + title: 'title', + url: '/url', + locale: 'en-us', + uid: 'UID', + _version: 1, + _in_progress: false, + created_by: 'created_by_uid', + updated_by: 'updated_by_uid', + created_at: 'created_at_date', + updated_at: 'updated_at_date', + _variant: { + uid: '_variant_uid', + variant_id: 'variant_id', + customized_fields: ['title'], + base_entry_version: 10 + } } const labelMock = { @@ -602,7 +602,6 @@ const variantsMock1 = { name: 'name' } - const environmentMock = { ...systemFieldsMock, ...systemFieldsUserMock, @@ -974,10 +973,10 @@ const auditLogsMock = { ] } -const taxonomyImportMock = { - "uid": "UID", - "name": "name", - "description": "test" +const taxonomyImportMock = { + uid: 'UID', + name: 'name', + description: 'test' } const taxonomyMock = { @@ -1050,8 +1049,8 @@ const variantGroupMock = { name: 'Test', source: 'Personalize', content_types: [ - "iphone_product_page" - ], + 'iphone_product_page' + ] } const variantMock = { @@ -1061,33 +1060,33 @@ const variantMock = { } const variantsMock = { - "uid": "variant_group_1", - "name": "Variant Group 1", - "content_types": [ - "CTSTAET123" + uid: 'variant_group_1', + name: 'Variant Group 1', + content_types: [ + 'CTSTAET123' ], - "personalize_metadata": { - "experience_uid": "variant_group_ex_uid", - "experience_short_uid": "variant_group_short_uid", - "project_uid": "variant_group_project_uid" + personalize_metadata: { + experience_uid: 'variant_group_ex_uid', + experience_short_uid: 'variant_group_short_uid', + project_uid: 'variant_group_project_uid' }, - "variants": [ // variants inside the group - { - "uid": "UID", - "created_by": "user_id", - "updated_by": "user_id", - "name": "Test", - "personalize_metadata": { - "experience_uid": "exp1", - "experience_short_uid": "expShortUid1", - "project_uid": "project_uid1", - "variant_short_uid": "variantShort_uid1" - }, - "created_at": "created_at_date", - "updated_at": "updated_at_date" - } + variants: [ // variants inside the group + { + uid: 'UID', + created_by: 'user_id', + updated_by: 'user_id', + name: 'Test', + personalize_metadata: { + experience_uid: 'exp1', + experience_short_uid: 'expShortUid1', + project_uid: 'project_uid1', + variant_short_uid: 'variantShort_uid1' + }, + created_at: 'created_at_date', + updated_at: 'updated_at_date' + } ], - "count": 1 + count: 1 } const variantGroupsMock = { @@ -1096,47 +1095,47 @@ const variantGroupsMock = { { ...systemFieldsMock, ...systemFieldsUserMock, - "name": "Test", - "source": 'Personalize', - "content_types": [ - "iphone_product_page" + name: 'Test', + source: 'Personalize', + content_types: [ + 'iphone_product_page' ], - "variant_count": 1, - "variants": [ + variant_count: 1, + variants: [ { ...systemFieldsMock, ...systemFieldsUserMock, - "name": "Test" + name: 'Test' } ] }, { - "name": "Test", - "source": 'Personalize', + name: 'Test', + source: 'Personalize', ...systemFieldsMock, ...systemFieldsUserMock, - "content_types": [ - "iphone_prod_desc" + content_types: [ + 'iphone_prod_desc' ], - "variant_count": 1, - "variants": [ + variant_count: 1, + variants: [ { ...systemFieldsMock, ...systemFieldsUserMock, - "name": "Test" + name: 'Test' } ] } ], ungrouped_variants: [ - { - "created_by": "blt6cdf4e0b02b1c446", - "updated_by": "blt303b74fa96e1082a", - "created_at": "2022-10-26T06:52:20.073Z", - "updated_at": "2023-09-25T04:55:56.549Z", - "uid": "iphone_color_red", - "name": "Red" - } + { + created_by: 'blt6cdf4e0b02b1c446', + updated_by: 'blt303b74fa96e1082a', + created_at: '2022-10-26T06:52:20.073Z', + updated_at: '2023-09-25T04:55:56.549Z', + uid: 'iphone_color_red', + name: 'Red' + } ], ungrouped_variant_count: 1 } @@ -1165,27 +1164,27 @@ const varinatsEntryMock = { _in_progress: false, _rules: [], _variant: { - _uid: "variant uid", - _instance_uid: "entry_variant uid", - _change_set: [], - _base_entry_version: 'version number of base entry', - } + _uid: 'variant uid', + _instance_uid: 'entry_variant uid', + _change_set: [], + _base_entry_version: 'version number of base entry' + } } const variantEntryVersion = { - "versions": [ - { - "_version": 3, - "locale": "en-us" - }, - { - "_version": 2, - "locale": "en-us" - }, - { - "_version": 1, - "locale": "en-us" - } + versions: [ + { + _version: 3, + locale: 'en-us' + }, + { + _version: 2, + locale: 'en-us' + }, + { + _version: 1, + locale: 'en-us' + } ] } diff --git a/test/unit/publishRules-test.js b/test/unit/publishRules-test.js index 0f4ac2db..e1a26918 100644 --- a/test/unit/publishRules-test.js +++ b/test/unit/publishRules-test.js @@ -65,14 +65,14 @@ describe('Contentstack PublishRule test', () => { it('PublishRule create test', done => { var mock = new MockAdapter(Axios) mock.onPost('/workflows/publishing_rules').reply(200, { - publishing_rule: { + publishing_rule: { ...publishRulesMock } }) makePublishRule() .create() - .then((publish_rule) => { - checkPublishRules(publish_rule) + .then((publishRule) => { + checkPublishRules(publishRule) done() }) .catch(done) @@ -87,8 +87,8 @@ describe('Contentstack PublishRule test', () => { }) makePublishRule() .fetchAll() - .then((publish_rule) => { - checkPublishRules(publish_rule.items[0]) + .then((publishRule) => { + checkPublishRules(publishRule.items[0]) done() }) .catch(done) @@ -103,8 +103,8 @@ describe('Contentstack PublishRule test', () => { }) makePublishRule({ stackHeaders: stackHeadersMock }) .fetchAll({}) - .then((publish_rule) => { - checkPublishRules(publish_rule.items[0]) + .then((publishRule) => { + checkPublishRules(publishRule.items[0]) done() }) .catch(done) @@ -119,8 +119,8 @@ describe('Contentstack PublishRule test', () => { }) makePublishRule({ stackHeaders: stackHeadersMock }) .fetchAll(null) - .then((publish_rule) => { - checkPublishRules(publish_rule.items[0]) + .then((publishRule) => { + checkPublishRules(publishRule.items[0]) done() }) .catch(done) @@ -129,19 +129,19 @@ describe('Contentstack PublishRule test', () => { it('PublishRule update test', done => { var mock = new MockAdapter(Axios) mock.onPut('/workflows/publishing_rules/UID').reply(200, { - publishing_rule: { + publishing_rule: { ...publishRulesMock } }) makePublishRule({ - publishing_rule: { + publishing_rule: { ...systemUidMock }, stackHeaders: stackHeadersMock }) .update() - .then((publish_rule) => { - checkPublishRules(publish_rule) + .then((publishRule) => { + checkPublishRules(publishRule) done() }) .catch(done) @@ -161,8 +161,8 @@ describe('Contentstack PublishRule test', () => { stackHeaders: stackHeadersMock }) .fetch() - .then((publish_rule) => { - checkPublishRules(publish_rule) + .then((publishRule) => { + checkPublishRules(publishRule) done() }) .catch(done) @@ -180,25 +180,22 @@ describe('Contentstack PublishRule test', () => { stackHeaders: stackHeadersMock }) .delete() - .then((publish_rule) => { - expect(publish_rule.notice).to.be.equal(noticeMock.notice) + .then((publishRule) => { + expect(publishRule.notice).to.be.equal(noticeMock.notice) done() }) .catch(done) }) - }) - -function makePublishRule(data) { - return new PublishRules(Axios, data) +function makePublishRule (data) { + return new PublishRules(Axios, data) } 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 diff --git a/test/unit/release-test.js b/test/unit/release-test.js index f20ad79a..829f22bf 100644 --- a/test/unit/release-test.js +++ b/test/unit/release-test.js @@ -233,7 +233,7 @@ describe('Contentstack Release test', () => { }, stackHeaders: stackHeadersMock }) - .item() + .item() .move({ data: { release_uid: 'UID2', items: ['$all'] }, release_version: '2.0' }) .then((response) => { expect(response.notice).to.be.equal(noticeMock.notice) @@ -244,7 +244,7 @@ describe('Contentstack Release test', () => { it('Release delete item test', done => { var mock = new MockAdapter(Axios) - mock.onDelete('/releases/UID/item').reply(200, + mock.onDelete('/releases/UID/item').reply(200, { ...noticeMock } ) makeRelease({ @@ -262,7 +262,7 @@ describe('Contentstack Release test', () => { .catch(done) }) - it("should delete specific item for v2", (done) => { + it('should delete specific item for v2', (done) => { var mock = new MockAdapter(Axios) mock.onDelete('/releases/UID/item').reply(200, { notice: 'Notice' @@ -275,17 +275,17 @@ describe('Contentstack Release test', () => { }) .item() .delete({ - item: { uid: 'uid', locale: "en-us" }, - release_version: "2.0", + item: { uid: 'uid', locale: 'en-us' }, + release_version: '2.0' }) .then((response) => { - expect(response.notice).to.be.equal('Notice'); - done(); + expect(response.notice).to.be.equal('Notice') + done() }) - .catch(done); - }); - - it("should delete specific items for v2", (done) => { + .catch(done) + }) + + it('should delete specific items for v2', (done) => { var mock = new MockAdapter(Axios) mock.onDelete('/releases/UID/items').reply(200, { notice: 'Notice' @@ -299,17 +299,17 @@ describe('Contentstack Release test', () => { .item() .delete({ items: [ - { uid: 'uid1', locale: "en-us" }, - { uid: 'uid2', locale: "en-us" }, + { uid: 'uid1', locale: 'en-us' }, + { uid: 'uid2', locale: 'en-us' } ], - release_version: "2.0", + release_version: '2.0' }) .then((response) => { - expect(response.notice).to.be.equal('Notice'); - done(); + expect(response.notice).to.be.equal('Notice') + done() }) - .catch(done); - }); + .catch(done) + }) }) function makeRelease (data) { diff --git a/test/unit/role-test.js b/test/unit/role-test.js index c926650f..c276d852 100644 --- a/test/unit/role-test.js +++ b/test/unit/role-test.js @@ -3,7 +3,7 @@ import { expect } from 'chai' import { describe, it } from 'mocha' import MockAdapter from 'axios-mock-adapter' import { Role, RoleCollection } from '../../lib/stack/roles' -import { systemUidMock, stackHeadersMock, roleMock, noticeMock, roleMockWithTaxonomy} from './mock/objects' +import { systemUidMock, stackHeadersMock, roleMock, noticeMock, roleMockWithTaxonomy } from './mock/objects' describe('Contentstack Role test', () => { it('Role test without uid', done => { diff --git a/test/unit/stack-test.js b/test/unit/stack-test.js index 64743855..17388906 100644 --- a/test/unit/stack-test.js +++ b/test/unit/stack-test.js @@ -2,7 +2,7 @@ import { describe, it } from 'mocha' import { Stack, StackCollection } from '../../lib/stack/index' import Axios from 'axios' import { expect } from 'chai' -import { stackMock, noticeMock, systemUidMock, stackHeadersMock } from './mock/objects' +import { stackMock, noticeMock, systemUidMock } from './mock/objects' import MockAdapter from 'axios-mock-adapter' describe('Contentstack Stack test', () => { @@ -860,7 +860,6 @@ describe('Contentstack Stack test', () => { // .catch(done) // }) - it('Stack transfer ownership test', done => { const mock = new MockAdapter(Axios) mock.onPost('/stacks/transfer_ownership').reply(200, { @@ -1000,55 +999,55 @@ describe('Contentstack Stack test', () => { }) it('Global fields initialization without uid', done => { - const global_field = makeStack({ + const globalField = makeStack({ stack: { api_key: 'stack_api_key' } }) - .globalField() - expect(global_field.uid).to.be.equal(undefined) - expect(global_field.stackHeaders).to.not.equal(undefined) - expect(global_field.stackHeaders.api_key).to.be.equal('stack_api_key') + .globalField() + expect(globalField.uid).to.be.equal(undefined) + expect(globalField.stackHeaders).to.not.equal(undefined) + expect(globalField.stackHeaders.api_key).to.be.equal('stack_api_key') done() }) it('Management token initialization without uid', done => { - const management_token = makeStack({ + const managementToken = makeStack({ stack: { api_key: 'stack_api_key' } }) - .managementToken() - expect(management_token.uid).to.be.equal(undefined) - expect(management_token.stackHeaders).to.not.equal(undefined) - expect(management_token.stackHeaders.api_key).to.be.equal('stack_api_key') + .managementToken() + expect(managementToken.uid).to.be.equal(undefined) + expect(managementToken.stackHeaders).to.not.equal(undefined) + expect(managementToken.stackHeaders.api_key).to.be.equal('stack_api_key') done() }) it('Global fields initialization uid', done => { - const global_field = makeStack({ + const globalField = makeStack({ stack: { api_key: 'stack_api_key' } }) - .globalField(systemUidMock.uid) - expect(global_field.uid).to.be.equal(systemUidMock.uid) - expect(global_field.stackHeaders.api_key).to.be.equal('stack_api_key') + .globalField(systemUidMock.uid) + expect(globalField.uid).to.be.equal(systemUidMock.uid) + expect(globalField.stackHeaders.api_key).to.be.equal('stack_api_key') done() }) it('Management token initialization uid', done => { - const management_token = makeStack({ + const managementToken = makeStack({ stack: { api_key: 'stack_api_key' } }) - .managementToken(systemUidMock.uid) - expect(management_token.uid).to.be.equal(systemUidMock.uid) - expect(management_token.stackHeaders.api_key).to.be.equal('stack_api_key') + .managementToken(systemUidMock.uid) + expect(managementToken.uid).to.be.equal(systemUidMock.uid) + expect(managementToken.stackHeaders.api_key).to.be.equal('stack_api_key') done() }) - + it('should update users roles', done => { var mock = new MockAdapter(Axios) const usersRolesData = { @@ -1073,17 +1072,16 @@ describe('Contentstack Stack test', () => { }) it('should fetch variants of a stack', done => { - var mock = new MockAdapter(Axios) const variantsResponse = makeStack({ stack: { api_key: 'stack_api_key' } }) .variants() - expect(variantsResponse.create).to.be.not.equal(undefined) - expect(variantsResponse.query).to.be.not.equal(undefined) - expect(variantsResponse.fetchByUIDs).to.be.not.equal(undefined) - done() + expect(variantsResponse.create).to.be.not.equal(undefined) + expect(variantsResponse.query).to.be.not.equal(undefined) + expect(variantsResponse.fetchByUIDs).to.be.not.equal(undefined) + done() }) }) diff --git a/test/unit/taxonomy-test.js b/test/unit/taxonomy-test.js index a20d303a..879b56cf 100644 --- a/test/unit/taxonomy-test.js +++ b/test/unit/taxonomy-test.js @@ -3,7 +3,7 @@ import path from 'path' import { expect } from 'chai' import { describe, it } from 'mocha' import MockAdapter from 'axios-mock-adapter' -import { Taxonomy, createFormData, TaxonomyCollection } from '../../lib/stack/taxonomy' +import { Taxonomy, createFormData } from '../../lib/stack/taxonomy' import { systemUidMock, stackHeadersMock, taxonomyMock, noticeMock, termsMock, taxonomyImportMock } from './mock/objects' describe('Contentstack Taxonomy test', () => { @@ -167,7 +167,6 @@ describe('Contentstack Taxonomy test', () => { .catch(done) }) - it('term create test', done => { var mock = new MockAdapter(Axios) mock.onPost(`/taxonomies/taxonomy_uid/terms`).reply(200, { diff --git a/test/unit/ungroupedVariants-test.js b/test/unit/ungroupedVariants-test.js index c67e0a55..2a81c78f 100644 --- a/test/unit/ungroupedVariants-test.js +++ b/test/unit/ungroupedVariants-test.js @@ -108,7 +108,7 @@ describe('Contentstack Variants test', () => { ] }) makeVariants() - .fetchByUIDs(['uid1','uid2']) + .fetchByUIDs(['uid1', 'uid2']) .then((variants) => { checkVariants(variants.variants[0]) done() @@ -162,7 +162,7 @@ function makeVariants (data = {}) { } function checkVariants (variants) { - if(variants.variants){ + if (variants.variants) { variants = variants.variants } checkSystemFields(variants) diff --git a/test/unit/variantGroup-test.js b/test/unit/variantGroup-test.js index c50f6817..cb3f934a 100644 --- a/test/unit/variantGroup-test.js +++ b/test/unit/variantGroup-test.js @@ -4,7 +4,6 @@ import { describe, it } from 'mocha' import MockAdapter from 'axios-mock-adapter' import { VariantGroup, VariantGroupCollection } from '../../lib/stack/variantGroup' import { systemUidMock, stackHeadersMock, variantGroupMock, noticeMock, checkSystemFields, variantGroupsMock } from './mock/objects' -import { checkEnvironment } from './variantGroup-test' describe('Contentstack VariantGroup test', () => { it('VariantGroup test without uid', done => { @@ -19,7 +18,7 @@ describe('Contentstack VariantGroup test', () => { }) it('VariantGroup test with uid', done => { - const variantGroup = makeVariantGroup({variant_group: {...systemUidMock}}) + const variantGroup = makeVariantGroup({ variant_group: { ...systemUidMock } }) expect(variantGroup.urlPath).to.be.equal(`/variant_groups/${systemUidMock.uid}`) expect(variantGroup.stackHeaders).to.be.equal(undefined) expect(variantGroup.update).to.not.equal(undefined) @@ -30,8 +29,8 @@ describe('Contentstack VariantGroup test', () => { }) it('VariantGroup test with Stack Headers', done => { - const variantGroup = makeVariantGroup({ variant_group:{ - ...systemUidMock, + const variantGroup = makeVariantGroup({ variant_group: { + ...systemUidMock, stackHeaders: stackHeadersMock } }) @@ -80,7 +79,7 @@ describe('Contentstack VariantGroup test', () => { it('VariantGroup Query test', done => { var mock = new MockAdapter(Axios) - mock.onGet('/variant_groups').reply(200, { ...variantGroupsMock + mock.onGet('/variant_groups').reply(200, { ...variantGroupsMock }) makeVariantGroup() .query() @@ -99,12 +98,12 @@ describe('Contentstack VariantGroup test', () => { ...variantGroupMock } }) - makeVariantGroup({variant_group:{ - ...systemUidMock, + makeVariantGroup({ variant_group: { + ...systemUidMock, stackHeaders: stackHeadersMock } }) - .update({name: 'test'}) + .update({ name: 'test' }) .then((variantGroup) => { checkVariantGroup(variantGroup.variant_group) done() @@ -160,7 +159,7 @@ describe('Contentstack VariantGroup test', () => { }, stackHeaders: stackHeadersMock }) - .variants() + .variants() expect(variants.variant_group_uid).to.be.equal(systemUidMock.uid) done() }) @@ -171,11 +170,11 @@ function makeVariantGroup (data = {}) { } function checkVariantGroup (variantGroup) { - if(variantGroup.variant_group){ + if (variantGroup.variant_group) { variantGroup = variantGroup.variant_group } checkSystemFields(variantGroup) expect(variantGroup.name).to.be.equal('Test') expect(variantGroup.source).to.be.equal('Personalize') expect(variantGroup.content_types.length).to.be.equal(1) -} \ No newline at end of file +} diff --git a/test/unit/variants-entry-test.js b/test/unit/variants-entry-test.js index a9780361..69589873 100644 --- a/test/unit/variants-entry-test.js +++ b/test/unit/variants-entry-test.js @@ -1,213 +1,212 @@ -import Axios from "axios"; -import { expect } from "chai"; -import { describe, it } from "mocha"; -import MockAdapter from "axios-mock-adapter"; +import Axios from 'axios' +import { expect } from 'chai' +import { describe, it } from 'mocha' +import MockAdapter from 'axios-mock-adapter' import { Variants, - VariantsCollection, -} from "../../lib/stack/contentType/entry/variants/"; -import { Entry } from "../../lib/stack/contentType/entry/"; + VariantsCollection +} from '../../lib/stack/contentType/entry/variants/' +import { Entry } from '../../lib/stack/contentType/entry/' import { checkSystemFields, varinatsEntryMock, - variantEntryVersion, -} from "./mock/objects"; -import { systemUidMock, noticeMock } from "./mock/objects"; + variantEntryVersion + , systemUidMock, noticeMock } from './mock/objects' -describe("Contentstack Variants entry test", () => { - it("Variants entry test without uid", (done) => { +describe('Contentstack Variants entry test', () => { + it('Variants entry test without uid', (done) => { const entry = makeEntryVariants({ - content_type_uid: "content_type_uid", - entry_uid: "UID", - }); + content_type_uid: 'content_type_uid', + entry_uid: 'UID' + }) expect(entry.urlPath).to.be.equal( - "/content_types/content_type_uid/entries/UID/variants" - ); - expect(entry.stackHeaders).to.be.equal(undefined); - expect(entry.update).to.be.equal(undefined); - expect(entry.delete).to.be.equal(undefined); - expect(entry.fetch).to.be.equal(undefined); - expect(entry.query).to.not.equal(undefined); - done(); - }); + '/content_types/content_type_uid/entries/UID/variants' + ) + expect(entry.stackHeaders).to.be.equal(undefined) + expect(entry.update).to.be.equal(undefined) + expect(entry.delete).to.be.equal(undefined) + expect(entry.fetch).to.be.equal(undefined) + expect(entry.query).to.not.equal(undefined) + done() + }) - it("Variants entry test with uid", (done) => { + it('Variants entry test with uid', (done) => { const entry = makeEntryVariants({ - content_type_uid: "content_type_uid", - entry_uid: "UID", - }); + content_type_uid: 'content_type_uid', + entry_uid: 'UID' + }) expect(entry.urlPath).to.be.equal( `/content_types/content_type_uid/entries/UID/variants` - ); - done(); - }); + ) + done() + }) - it("Variants entry Collection test with blank data", (done) => { - const entries = new VariantsCollection(Axios, {}); - expect(entries.length).to.be.equal(0); - done(); - }); + it('Variants entry Collection test with blank data', (done) => { + const entries = new VariantsCollection(Axios, {}) + expect(entries.length).to.be.equal(0) + done() + }) - it("Variants entry Collection test with data", (done) => { + it('Variants entry Collection test with data', (done) => { const entries = new VariantsCollection(Axios, { - entries: [varinatsEntryMock], - }); - expect(entries.length).to.be.equal(1); - checkEntry(entries[0].variants); - done(); - }); + entries: [varinatsEntryMock] + }) + expect(entries.length).to.be.equal(1) + checkEntry(entries[0].variants) + done() + }) - it("Variants entry Query test", (done) => { - var mock = new MockAdapter(Axios); + it('Variants entry Query test', (done) => { + var mock = new MockAdapter(Axios) mock - .onGet("/content_types/content_type_uid/entries/UID/variants") + .onGet('/content_types/content_type_uid/entries/UID/variants') .reply(200, { - entries: [varinatsEntryMock], - }); + entries: [varinatsEntryMock] + }) makeEntryVariants({ - content_type_uid: "content_type_uid", - entry_uid: "UID", + content_type_uid: 'content_type_uid', + entry_uid: 'UID' }) .query() .find() .then((entry) => { - checkEntry(entry.items[0].variants); - done(); + checkEntry(entry.items[0].variants) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Variants entry fetch test", (done) => { - var mock = new MockAdapter(Axios); + it('Variants entry fetch test', (done) => { + var mock = new MockAdapter(Axios) mock .onGet( - "/content_types/content_type_uid/entries/UID/variants/variants_uid" + '/content_types/content_type_uid/entries/UID/variants/variants_uid' ) .reply(200, { entry: { - ...varinatsEntryMock, - }, - }); + ...varinatsEntryMock + } + }) makeEntryVariants({ - content_type_uid: "content_type_uid", - entry_uid: "UID", - variants_uid: "variants_uid", + content_type_uid: 'content_type_uid', + entry_uid: 'UID', + variants_uid: 'variants_uid' }) .fetch() .then((entry) => { - checkEntry(entry.entry); - done(); + checkEntry(entry.entry) + done() }) - .catch(done); - }); - it("Variants entry version test", (done) => { - var mock = new MockAdapter(Axios); + .catch(done) + }) + it('Variants entry version test', (done) => { + var mock = new MockAdapter(Axios) mock .onGet( - "/content_types/content_type_uid/entries/UID/variants/variants_uid/versions" + '/content_types/content_type_uid/entries/UID/variants/variants_uid/versions' ) .reply(200, { - ...variantEntryVersion, - }); + ...variantEntryVersion + }) makeEntryVariants({ - content_type_uid: "content_type_uid", - entry_uid: "UID", - variants_uid: "variants_uid", + content_type_uid: 'content_type_uid', + entry_uid: 'UID', + variants_uid: 'variants_uid' }) .versions() .then((entry) => { - expect(entry.versions.length).to.be.equal(3); - done(); + expect(entry.versions.length).to.be.equal(3) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Entry publish test", (done) => { - var mock = new MockAdapter(Axios); + it('Entry publish test', (done) => { + var mock = new MockAdapter(Axios) const publishVariantEntryFirst = { entry: { - environments: ["development"], - locales: ["en-us"], + environments: ['development'], + locales: ['en-us'], variants: [ { - uid: "variants_uid", - version: 1, - }, + uid: 'variants_uid', + version: 1 + } ], variant_rules: { publish_latest_base: false, - publish_latest_base_conditionally: true, - }, + publish_latest_base_conditionally: true + } }, - locale: "en-us", - version: 1, - }; + locale: 'en-us', + version: 1 + } mock - .onPost("/content_types/content_type_uid/entries/UID/publish") + .onPost('/content_types/content_type_uid/entries/UID/publish') .reply(200, { ...noticeMock, - job_id: "job_id", - }); + job_id: 'job_id' + }) - makeEntry({ entry: { ...systemUidMock }, options: { api_version: "3.2" } }) + makeEntry({ entry: { ...systemUidMock }, options: { api_version: '3.2' } }) .publish({ publishDetails: publishVariantEntryFirst.entry, - locale: publishVariantEntryFirst.locale, + locale: publishVariantEntryFirst.locale }) .then((entry) => { - expect(entry.notice).to.be.equal(noticeMock.notice); - expect(entry.job_id).to.be.not.equal(undefined); - done(); + expect(entry.notice).to.be.equal(noticeMock.notice) + expect(entry.job_id).to.be.not.equal(undefined) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Entry unpublish test", (done) => { + it('Entry unpublish test', (done) => { var unpublishVariantEntryFirst = { entry: { - environments: ["development"], - locales: ["en-at"], + environments: ['development'], + locales: ['en-at'], variants: [ { - uid: "", - version: 1, - }, + uid: '', + version: 1 + } ], variant_rules: { publish_latest_base: false, - publish_latest_base_conditionally: true, - }, + publish_latest_base_conditionally: true + } }, - locale: "en-us", - version: 1, - }; - var mock = new MockAdapter(Axios); + locale: 'en-us', + version: 1 + } + var mock = new MockAdapter(Axios) mock - .onPost("/content_types/content_type_uid/entries/UID/unpublish") + .onPost('/content_types/content_type_uid/entries/UID/unpublish') .reply(200, { ...noticeMock, - job_id: "job_id", - }); - makeEntry({ entry: { ...systemUidMock }, options: { api_version: "3.2" } }) + job_id: 'job_id' + }) + makeEntry({ entry: { ...systemUidMock }, options: { api_version: '3.2' } }) .unpublish({ publishDetails: unpublishVariantEntryFirst.entry, - locale: unpublishVariantEntryFirst.locale, + locale: unpublishVariantEntryFirst.locale }) .then((entry) => { - expect(entry.notice).to.be.equal(noticeMock.notice); - done(); + expect(entry.notice).to.be.equal(noticeMock.notice) + done() }) - .catch(done); - }); + .catch(done) + }) - it("Variants update test", (done) => { - var mock = new MockAdapter(Axios); + it('Variants update test', (done) => { + var mock = new MockAdapter(Axios) const updatedData = { entry: { - title: "Updated Variant Title", - url: "/updated-variant-url", - }, - }; + title: 'Updated Variant Title', + url: '/updated-variant-url' + } + } const variantEntryMock = { uid: 'variant_uid', title: 'Variant Title', @@ -222,33 +221,33 @@ describe("Contentstack Variants entry test", () => { .reply(200, { entry: { ...variantEntryMock, - ...updatedData.entry, - }, - }); + ...updatedData.entry + } + }) - makeEntryVariants({ - content_type_uid: "content_type_uid", - entry_uid: "entry_uid", - variants_uid: "variant_uid", + makeEntryVariants({ + content_type_uid: 'content_type_uid', + entry_uid: 'entry_uid', + variants_uid: 'variant_uid' }) .update(updatedData) .then((response) => { - expect(response.entry.title).to.be.equal("Updated Variant Title"); - expect(response.entry.url).to.be.equal("/updated-variant-url"); - done(); + expect(response.entry.title).to.be.equal('Updated Variant Title') + expect(response.entry.url).to.be.equal('/updated-variant-url') + done() }) - .catch(done); - }); -}); + .catch(done) + }) +}) -function makeEntryVariants(data) { - return new Variants(Axios, { ...data }); +function makeEntryVariants (data) { + return new Variants(Axios, { ...data }) } -function makeEntry(data) { - return new Entry(Axios, { content_type_uid: "content_type_uid", ...data }); +function makeEntry (data) { + return new Entry(Axios, { content_type_uid: 'content_type_uid', ...data }) } -function checkEntry(entry) { - checkSystemFields(entry); +function checkEntry (entry) { + checkSystemFields(entry) } diff --git a/test/unit/variantsWithVariantsGroup-test.js b/test/unit/variantsWithVariantsGroup-test.js index f441dedc..94e0ab4a 100644 --- a/test/unit/variantsWithVariantsGroup-test.js +++ b/test/unit/variantsWithVariantsGroup-test.js @@ -3,12 +3,11 @@ import { expect } from 'chai' import { describe, it } from 'mocha' import MockAdapter from 'axios-mock-adapter' import { Variants, VariantsCollection } from '../../lib/stack/variantGroup/variants' -import { systemUidMock, stackHeadersMock, variantMock, noticeMock, checkSystemFields, variantsMock } from './mock/objects' -import { checkEnvironment } from './variantsWithVariantsGroup-test' +import { systemUidMock, stackHeadersMock, variantMock, checkSystemFields, variantsMock } from './mock/objects' describe('Contentstack Variants test', () => { it(' Variants test without uid', done => { - const variants = makeVariants({variant_group_uid: systemUidMock.uid}) + const variants = makeVariants({ variant_group_uid: systemUidMock.uid }) expect(variants.urlPath).to.be.equal(`/variant_groups/${systemUidMock.uid}/variants`) expect(variants.stackHeaders).to.be.equal(undefined) expect(variants.update).to.be.equal(undefined) @@ -20,7 +19,7 @@ describe('Contentstack Variants test', () => { }) it(' Variants test with uid', done => { - const variants = makeVariants({variant_group_uid: systemUidMock.uid, variants: {uid: systemUidMock.uid}}) + const variants = makeVariants({ variant_group_uid: systemUidMock.uid, variants: { uid: systemUidMock.uid } }) expect(variants.urlPath).to.be.equal(`/variant_groups/${systemUidMock.uid}/variants/${systemUidMock.uid}`) expect(variants.stackHeaders).to.be.equal(undefined) expect(variants.update).to.not.equal(undefined) @@ -31,7 +30,7 @@ describe('Contentstack Variants test', () => { }) it(' Variants test with Stack Headers', done => { - const variants = makeVariants({ variant_group_uid: systemUidMock.uid, + const variants = makeVariants({ variant_group_uid: systemUidMock.uid, stackHeaders: stackHeadersMock }) expect(variants.urlPath).to.be.equal(`/variant_groups/${systemUidMock.uid}/variants`) @@ -41,13 +40,13 @@ describe('Contentstack Variants test', () => { }) it(' Variants Collection test with blank data', done => { - const variants = new VariantsCollection(Axios, {}) + const variants = new VariantsCollection(Axios, {}) expect(variants.length).to.be.equal(0) done() }) it(' Variants Collection test with data', done => { - const variants = new VariantsCollection(Axios, { variant_group_uid: systemUidMock.uid, + const variants = new VariantsCollection(Axios, { variant_group_uid: systemUidMock.uid, variants: [ variantMock ] @@ -64,7 +63,7 @@ describe('Contentstack Variants test', () => { ...variantMock } }) - makeVariants({variant_group_uid: systemUidMock.uid}) + makeVariants({ variant_group_uid: systemUidMock.uid }) .create() .then((variant) => { checkVariants(variant) @@ -75,9 +74,9 @@ describe('Contentstack Variants test', () => { it(' Variants Query test', done => { var mock = new MockAdapter(Axios) - mock.onGet('/variant_groups/UID/variants').reply(200, { variant_group_uid: systemUidMock.uid, ...variantsMock + mock.onGet('/variant_groups/UID/variants').reply(200, { variant_group_uid: systemUidMock.uid, ...variantsMock }) - makeVariants({variant_group_uid: systemUidMock.uid}) + makeVariants({ variant_group_uid: systemUidMock.uid }) .query() .find() .then((variants) => { @@ -90,14 +89,15 @@ describe('Contentstack Variants test', () => { it(' Variants update test', done => { var mock = new MockAdapter(Axios) mock.onPut('/variant_groups/UID/variants/UID').reply(200, { variant_group_uid: systemUidMock.uid, - variants: { + variants: { ...variantMock } }) - makeVariants({variant_group_uid: systemUidMock.uid, variants:{ + makeVariants({ variant_group_uid: systemUidMock.uid, + variants: { ...systemUidMock, - stackHeaders: stackHeadersMock - } + stackHeaders: stackHeadersMock + } }) .update() .then((variant) => { @@ -110,12 +110,12 @@ describe('Contentstack Variants test', () => { it(' Variants fetch test', done => { var mock = new MockAdapter(Axios) mock.onGet('/variant_groups/UID/variants/UID').reply(200, { variant_group_uid: systemUidMock.uid, - variants: { + variants: { ...variantMock } }) - makeVariants({ variant_group_uid: systemUidMock.uid, - variants: { + makeVariants({ variant_group_uid: systemUidMock.uid, + variants: { ...systemUidMock }, stackHeaders: stackHeadersMock @@ -127,7 +127,6 @@ describe('Contentstack Variants test', () => { }) .catch(done) }) - }) function makeVariants (data = {}) { @@ -135,10 +134,10 @@ function makeVariants (data = {}) { } function checkVariants (variant) { - if(variant.variants){ + if (variant.variants) { variant = variant.variants } checkSystemFields(variant) expect(variant.name).to.be.equal('Test') expect(variant.uid).to.be.equal('UID') -} \ No newline at end of file +} diff --git a/webpack/webpack.web.js b/webpack/webpack.web.js index 913ecbb7..bbb5ccd8 100644 --- a/webpack/webpack.web.js +++ b/webpack/webpack.web.js @@ -6,7 +6,7 @@ const { merge } = require('webpack-merge') const commonConfig = require('./webpack.common.js')() module.exports = function (options) { - delete commonConfig.externals; + delete commonConfig.externals return merge(commonConfig, { output: { libraryTarget: 'umd', From f5e416aed898fe245e21d11a983d97e182c7ca96 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 12 Mar 2025 11:53:22 +0530 Subject: [PATCH 2/4] merged development & fix lint errors --- lib/stack/auditlog/index.js | 2 +- lib/stack/index.js | 2 +- test/sanity-check/api/auditlog-test.js | 50 +++++++++++++------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/stack/auditlog/index.js b/lib/stack/auditlog/index.js index 88062a91..ed27a020 100644 --- a/lib/stack/auditlog/index.js +++ b/lib/stack/auditlog/index.js @@ -1,6 +1,6 @@ import cloneDeep from 'lodash/cloneDeep' import error from '../../core/contentstackError' -import { fetchAll, parseData } from '../../entity' +import { fetchAll } from '../../entity' /** * diff --git a/lib/stack/index.js b/lib/stack/index.js index 642dac33..74416687 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -810,7 +810,7 @@ export function Stack (http, data) { */ this.delete = deleteEntity(http) - /** + /** * @description Audit log displays a record of all the activities performed in a stack and helps you keep a track of all published items, updates, deletes, and current status of the existing content. * @param {String} * @returns {AuditLog} diff --git a/test/sanity-check/api/auditlog-test.js b/test/sanity-check/api/auditlog-test.js index 26442be9..57b4e037 100644 --- a/test/sanity-check/api/auditlog-test.js +++ b/test/sanity-check/api/auditlog-test.js @@ -1,31 +1,33 @@ -import { expect } from "chai"; -import { describe, it, setup } from "mocha"; -import { jsonReader } from "../utility/fileOperations/readwrite.js"; +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite.js' -import { contentstackClient } from "../utility/ContentstackClient.js"; +import { contentstackClient } from '../utility/ContentstackClient.js' -let client = {}; -let uid = ""; -describe("Audit Log api Test", () => { +let client = {} +let uid = '' +describe('Audit Log api Test', () => { setup(() => { - const user = jsonReader("loggedinuser.json"); - client = contentstackClient(user.authtoken); - }); + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) - it("Should Fetch all the Audit Logs", async () => { - const response = await makeAuditLog().fetchAll(); - uid = response.items[0].uid; - expect(Array.isArray(response.items)).to.be.true; - expect(response.items[0].uid).not.to.be.undefined; - }); + it('Should Fetch all the Audit Logs', async () => { + const response = await makeAuditLog().fetchAll() + uid = response.items[0].uid + // eslint-disable-next-line no-unused-expressions + expect(Array.isArray(response.items)).to.be.true + // eslint-disable-next-line no-unused-expressions + expect(response.items[0].uid).not.to.be.undefined + }) - it("Should Fetch a single audit log", async () => { - const response = await makeAuditLog(uid).fetch(); - console.log(response); - expect(response.log.uid).to.be.equal(uid); - }); -}); + it('Should Fetch a single audit log', async () => { + const response = await makeAuditLog(uid).fetch() + console.log(response) + expect(response.log.uid).to.be.equal(uid) + }) +}) -function makeAuditLog(uid = null) { - return client.stack({ api_key: process.env.API_KEY }).auditLog(uid); +function makeAuditLog (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).auditLog(uid) } From 867e5bb856bba8c47344fcab22d8863c4481e467 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 12 Mar 2025 12:25:08 +0530 Subject: [PATCH 3/4] fix: sanity check --- lib/stack/release/items/index.js | 9 +++++++-- test/sanity-check/api/auditlog-test.js | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/stack/release/items/index.js b/lib/stack/release/items/index.js index abfa34c9..11dd464c 100644 --- a/lib/stack/release/items/index.js +++ b/lib/stack/release/items/index.js @@ -145,8 +145,13 @@ export function ReleaseItem (http, data = {}) { } if (param.item) { this.urlPath = `releases/${data.releaseUid}/item` - headers.data['item'] = param.item - } else { headers.data['items'] = param.items } + //NOTE - Breaking sanity check that's why disabling it + // eslint-disable-next-line no-self-assign + param['item'] = param.item + } else { + // eslint-disable-next-line no-self-assign + param['items'] = param.items + } try { const response = await http.post(this.urlPath, param, headers) diff --git a/test/sanity-check/api/auditlog-test.js b/test/sanity-check/api/auditlog-test.js index 57b4e037..2fe8eaea 100644 --- a/test/sanity-check/api/auditlog-test.js +++ b/test/sanity-check/api/auditlog-test.js @@ -23,7 +23,6 @@ describe('Audit Log api Test', () => { it('Should Fetch a single audit log', async () => { const response = await makeAuditLog(uid).fetch() - console.log(response) expect(response.log.uid).to.be.equal(uid) }) }) From 40b053a92e9804d989de497bf7a2fe81f77f2cf6 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 12 Mar 2025 12:27:06 +0530 Subject: [PATCH 4/4] fix: linting issue --- lib/stack/release/items/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stack/release/items/index.js b/lib/stack/release/items/index.js index 11dd464c..f9e0d26e 100644 --- a/lib/stack/release/items/index.js +++ b/lib/stack/release/items/index.js @@ -145,8 +145,8 @@ export function ReleaseItem (http, data = {}) { } if (param.item) { this.urlPath = `releases/${data.releaseUid}/item` - //NOTE - Breaking sanity check that's why disabling it - // eslint-disable-next-line no-self-assign + // NOTE - Breaking sanity check that's why disabling it + // eslint-disable-next-line no-self-assign param['item'] = param.item } else { // eslint-disable-next-line no-self-assign