diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 1e2d24a5..e79864e0 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment PR - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' uses: thollander/actions-comment-pull-request@v2 with: message: | We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - name: Check branch - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' run: | echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." exit 1 \ No newline at end of file diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 27062c53..5cb5242a 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -4,7 +4,8 @@ on: branches: - master - main - - next + - staging + - development jobs: build-test: name: Build & Test diff --git a/CHANGELOG.md b/CHANGELOG.md index 51ee6dd7..b65b5e61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog + +## [v1.20.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.20.2) (2025-04-21) + - Fix + - Handle the sanity tests when ENVs are not provided ## [v1.20.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.20.1) (2025-04-07) - Fix - Ensure 'api' is replaced with 'app' in uiHostName regardless of position diff --git a/package-lock.json b/package-lock.json index 0b55535d..91deb3ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/management", - "version": "1.20.1", + "version": "1.20.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.20.1", + "version": "1.20.2", "license": "MIT", "dependencies": { "assert": "^2.1.0", diff --git a/package.json b/package.json index 0e5498ff..ca6cf2a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.20.1", + "version": "1.20.2", "description": "The Content Management API is used to manage the content of your Contentstack account", "main": "./dist/node/contentstack-management.js", "browser": "./dist/web/contentstack-management.js", @@ -33,7 +33,6 @@ "test:sanity-test": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json", "test:sanity": "npm run test:sanity-test || true", "test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs", - "test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill", "test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill", "test:unit:report:json": "BABEL_ENV=test nyc --reporter=clover --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter json --reporter-options output=report.json --require babel-polyfill", "test:typescript": "jest --testPathPattern=test/typescript --config ./jest.config.js --coverage", diff --git a/test/api/app-delete-test.js b/test/api/app-delete-test.js deleted file mode 100644 index cd9a6648..00000000 --- a/test/api/app-delete-test.js +++ /dev/null @@ -1,38 +0,0 @@ -import dotenv from 'dotenv' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { expect } from 'chai' - -dotenv.config() - -let apps = {} -let installation = {} -const orgID = process.env.ORGANIZATION -let client = {} - -describe('Apps api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - apps = jsonReader('apps.json') - installation = jsonReader('installation.json') - }) - - it('Uninstall installation test', done => { - client.organization(orgID).app(apps.uid).installation(installation.uid).uninstall() - .then((installation) => { - expect(installation).to.deep.equal({}) - done() - }).catch(done) - }) - - it('Delete app test', done => { - client.organization(orgID).app(apps.uid).delete() - .then((appResponse) => { - expect(appResponse).to.deep.equal({}) - done() - }) - .catch(done) - }) -}) diff --git a/test/api/app-request-test.js b/test/api/app-request-test.js deleted file mode 100644 index e03bb114..00000000 --- a/test/api/app-request-test.js +++ /dev/null @@ -1,52 +0,0 @@ -import dotenv from 'dotenv' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { expect } from 'chai' - -dotenv.config() - -let apps = {} -const orgID = process.env.ORGANIZATION -let client = {} -let stack = {} -let requestUID = '' -describe('Apps request api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - apps = jsonReader('apps.json') - stack = jsonReader('stack.json') - }) - - it('test create app request', done => { - client.organization(orgID).request() - .create({ appUid: apps.uid, targetUid: stack.api_key }) - .then((response) => { - requestUID = response.data.data.uid - expect(response.data).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('test get all request for oranization', done => { - client.organization(orgID).request() - .findAll() - .then((response) => { - expect(response.data).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('test delete app request', done => { - client.organization(orgID).request() - .delete(requestUID) - .then((response) => { - expect(response.data).to.not.equal(undefined) - done() - }) - .catch(done) - }) -}) diff --git a/test/api/app-test.js b/test/api/app-test.js deleted file mode 100644 index b77c6885..00000000 --- a/test/api/app-test.js +++ /dev/null @@ -1,192 +0,0 @@ -import dotenv from 'dotenv' -import { describe, it, setup } from 'mocha' -import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite' -import { expect } from 'chai' -import * as contentstack from '../../lib/contentstack.js' - -dotenv.config() - -const orgID = process.env.ORGANIZATION -let client = {} -let appUid = '' -let installationUid = '' -const app = { - name: 'My New App', - description: 'My new test app', - target_type: 'organization' -} -const config = { redirect_uri: 'https://example.com/oauth/callback', app_token_config: { enabled: true, scopes: ['scim:manage'] }, user_token_config: { enabled: true, scopes: ['user:read', 'user:write', 'scim:manage'], allow_pkce: true } } - -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 }) - }) - - it('Fetch all apps test', done => { - client.organization(orgID).app().findAll() - .then((apps) => { - for (const index in apps.items) { - const appObject = apps.items[index] - expect(appObject.name).to.not.equal(null) - expect(appObject.uid).to.not.equal(null) - expect(appObject.target_type).to.not.equal(null) - } - done() - }) - .catch(done) - }) - - it('Fetch all authorized apps test', done => { - client.organization(orgID).app().findAllAuthorized() - .then((apps) => { - for (const index in apps.data) { - const appObject = apps.data[index] - expect(appObject.name).to.not.equal(null) - expect(appObject.uid).to.not.equal(null) - expect(appObject.target_type).to.not.equal(null) - } - done() - }) - .catch(done) - }) - - it('Create app test', done => { - client.organization(orgID).app().create(app) - .then((appResponse) => { - appUid = appResponse.uid - jsonWrite(appResponse, 'apps.json') - expect(appResponse.uid).to.not.equal(undefined) - expect(appResponse.name).to.be.equal(app.name) - expect(appResponse.description).to.be.equal(app.description) - expect(appResponse.target_type).to.be.equal(app.target_type) - done() - }) - .catch(done) - }) - - it('Fetch app test', done => { - client.organization(orgID).app(appUid).fetch() - .then((appResponse) => { - expect(appResponse.uid).to.be.equal(appUid) - expect(appResponse.name).to.be.equal(app.name) - expect(appResponse.description).to.be.equal(app.description) - expect(appResponse.target_type).to.be.equal(app.target_type) - done() - }) - .catch(done) - }) - - it('Update app test', done => { - const updateApp = { name: 'Update my app name' } - let appObject = client.organization(orgID).app(appUid) - appObject = Object.assign(appObject, updateApp) - appObject.update() - .then((appResponse) => { - appUid = appResponse.uid - expect(appResponse.uid).to.not.equal(undefined) - expect(appResponse.name).to.be.equal(updateApp.name) - expect(appResponse.description).to.be.equal(app.description) - expect(appResponse.target_type).to.be.equal(app.target_type) - done() - }) - .catch(done) - }) - - it('Update OAuth app test', done => { - client.organization(orgID).app(appUid).updateOAuth({ config }) - .then((appResponse) => { - expect(appResponse.redirect_uri).to.be.equal(config.redirect_uri) - expect(appResponse.app_token_config.enabled).to.be.equal(config.app_token_config.enabled) - expect(appResponse.user_token_config.enabled).to.be.equal(config.user_token_config.enabled) - done() - }) - .catch(done) - }) - - it('Fetch OAuth app test', done => { - client.organization(orgID).app(appUid).fetchOAuth() - .then((appResponse) => { - expect(appResponse.redirect_uri).to.be.equal(config.redirect_uri) - expect(appResponse.app_token_config.enabled).to.be.equal(config.app_token_config.enabled) - expect(appResponse.user_token_config.enabled).to.be.equal(config.user_token_config.enabled) - done() - }) - .catch(done) - }) - - it('Install app test', done => { - client.organization(orgID).app(appUid).install({ targetType: 'organization', targetUid: process.env.ORGANIZATION }) - .then((installation) => { - installationUid = installation.uid - jsonWrite(installation, 'installation.json') - expect(installation.uid).to.not.equal(undefined) - expect(installation.params.organization_uid).to.be.equal(orgID) - expect(installation.urlPath).to.be.equal(`/installations/${installation.uid}`) - expect(installation.fetch).to.not.equal(undefined) - expect(installation.update).to.not.equal(undefined) - expect(installation.uninstall).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('Get installationData for installation test', done => { - client.organization(orgID).app(appUid).installation(installationUid).installationData() - .then((installation) => { - expect(installation).to.not.equal(null) - done() - }).catch(done) - }) - - it('Get configuration for installation test', done => { - client.organization(orgID).app(appUid).installation(installationUid).configuration() - .then((config) => { - expect(config).to.not.equal(null) - done() - }).catch(done) - }) - it('Set configuration for installation test', done => { - client.organization(orgID).app(appUid).installation(installationUid).setConfiguration({}) - .then((config) => { - expect(config.data).to.deep.equal({}) - done() - }).catch(done) - }) - it('Get server config for installation test', done => { - client.organization(orgID).app(appUid).installation(installationUid).serverConfig() - .then((config) => { - expect(config).to.not.equal(null) - done() - }).catch(done) - }) - it('Set server config for installation test', done => { - client.organization(orgID).app(appUid).installation(installationUid).setServerConfig({}) - .then((config) => { - expect(config.data).to.deep.equal({}) - done() - }).catch(done) - }) - - it('Fetch installation test', done => { - client.organization(orgID).app(appUid).installation(installationUid).fetch() - .then((installation) => { - expect(installation.uid).to.be.equal(installationUid) - expect(installation.params.organization_uid).to.be.equal(orgID) - expect(installation.urlPath).to.be.equal(`/installations/${installation.uid}`) - expect(installation.target.type).to.be.equal('organization') - expect(installation.target.uid).to.be.equal(orgID) - expect(installation.status).to.be.equal('installed') - done() - }).catch(done) - }) - it('test fetch app request', done => { - client.organization(orgID).app(appUid) - .getRequests() - .then((response) => { - expect(response.data).to.not.equal(undefined) - done() - }) - .catch(done) - }) -}) diff --git a/test/api/asset-test.js b/test/api/asset-test.js deleted file mode 100644 index 0a534fa6..00000000 --- a/test/api/asset-test.js +++ /dev/null @@ -1,219 +0,0 @@ -import path from 'path' -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader, writeDownloadedFile } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} -var stack = {} - -var folderUID = '' -var assetUID = '' -var publishAssetUID = '' -var assetURL = '' -describe('Assets api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Asset Upload ', done => { - const asset = { - upload: path.join(__dirname, './mock/customUpload.html'), - title: 'customasset', - description: 'Custom Asset Desc', - tags: ['Custom'] - } - makeAsset().create(asset) - .then((asset) => { - assetUID = asset.uid - assetURL = asset.url - expect(asset.uid).to.be.not.equal(null) - expect(asset.url).to.be.not.equal(null) - expect(asset.filename).to.be.equal('customUpload.html') - expect(asset.title).to.be.equal('customasset') - expect(asset.description).to.be.equal('Custom Asset Desc') - expect(asset.content_type).to.be.equal('text/html') - done() - }) - .catch(done) - }) - - it('Download asset from URL.', done => { - makeAsset().download({ url: assetURL, responseType: 'stream' }) - .then((response) => { - writeDownloadedFile(response, 'asset1') - done() - }).catch(done) - }) - it('Download asset from fetch details ', done => { - makeAsset(assetUID).fetch() - .then((asset) => asset.download({ responseType: 'stream' })) - .then((response) => { - writeDownloadedFile(response, 'asset2') - done() - }).catch(done) - }) - - it('Create folder ', done => { - makeAsset().folder().create({ asset: { name: 'Sample Folder' } }) - .then((asset) => { - folderUID = asset.uid - expect(asset.uid).to.be.not.equal(null) - expect(asset.name).to.be.equal('Sample Folder') - expect(asset.is_dir).to.be.equal(true) - done() - }) - .catch(done) - }) - - it('Asset Upload in folder', done => { - const asset = { - upload: path.join(__dirname, './mock/customUpload.html'), - title: 'customasset in Folder', - description: 'Custom Asset Desc in Folder', - parent_uid: folderUID, - tags: 'folder' - } - makeAsset().create(asset) - .then((asset) => { - publishAssetUID = asset.uid - expect(asset.uid).to.be.not.equal(null) - expect(asset.url).to.be.not.equal(null) - expect(asset.filename).to.be.equal('customUpload.html') - expect(asset.title).to.be.equal('customasset in Folder') - expect(asset.description).to.be.equal('Custom Asset Desc in Folder') - expect(asset.content_type).to.be.equal('text/html') - expect(asset.parent_uid).to.be.equal(folderUID) - done() - }) - .catch(done) - }) - - it('Asset Upload in folder with contenttype', done => { - const asset = { - upload: path.join(__dirname, './mock/berries.jfif'), - title: 'customasset2 in Folder', - description: 'Custom Asset Desc in Folder', - parent_uid: folderUID, - tags: 'folder', - content_type: 'image/jpeg' - } - makeAsset().create(asset) - .then((asset) => { - publishAssetUID = asset.uid - expect(asset.uid).to.be.not.equal(null) - expect(asset.url).to.be.not.equal(null) - expect(asset.filename).to.be.equal('berries.jfif') - expect(asset.title).to.be.equal('customasset2 in Folder') - expect(asset.description).to.be.equal('Custom Asset Desc in Folder') - expect(asset.content_type).to.be.equal('image/jpeg') - expect(asset.parent_uid).to.be.equal(folderUID) - done() - }) - .catch(done) - }) - it('Replace asset ', done => { - const asset = { - upload: path.join(__dirname, './mock/upload.html') - } - makeAsset(assetUID) - .replace(asset) - .then((asset) => { - expect(asset.uid).to.be.equal(assetUID) - expect(asset.filename).to.be.equal('upload.html') - expect(asset.content_type).to.be.equal('text/html') - done() - }) - .catch(done) - }) - - it('Fetch and Update asset details', done => { - makeAsset(assetUID) - .fetch() - .then((asset) => { - asset.title = 'Update title' - asset.description = 'Update description' - delete asset.ACL - return asset.update() - }) - .then((asset) => { - expect(asset.uid).to.be.equal(assetUID) - expect(asset.title).to.be.equal('Update title') - expect(asset.description).to.be.equal('Update description') - done() - }) - .catch(done) - }) - - it('Publish Asset', done => { - makeAsset(publishAssetUID) - .publish({ publishDetails: { - locales: ['hi-in', 'en-us'], - environments: ['development'] - } }) - .then((data) => { - expect(data.notice).to.be.equal('Asset sent for publishing.') - done() - }) - .catch(done) - }) - - it('Unpublish Asset', done => { - makeAsset(publishAssetUID) - .unpublish({ publishDetails: { - locales: ['hi-in', 'en-us'], - environments: ['development'] - } }) - .then((data) => { - expect(data.notice).to.be.equal('Asset sent for unpublishing.') - done() - }) - .catch(done) - }) - - it('Delete asset', done => { - makeAsset(assetUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Asset deleted successfully.') - done() - }) - .catch(done) - }) - - it('Query to fetch all asset', done => { - makeAsset() - .query() - .find() - .then((collection) => { - collection.items.forEach((asset) => { - expect(asset.uid).to.be.not.equal(null) - expect(asset.title).to.be.not.equal(null) - expect(asset.description).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query to fetch title match asset', done => { - makeAsset() - .query({ query: { title: 'Update title' } }) - .find() - .then((collection) => { - collection.items.forEach((asset) => { - expect(asset.uid).to.be.not.equal(null) - expect(asset.title).to.be.equal('Update title') - expect(asset.description).to.be.equal('Update description') - }) - done() - }) - .catch(done) - }) -}) - -function makeAsset (uid = null) { - return client.stack({ api_key: stack.api_key }).asset(uid) -} diff --git a/test/api/authorization-test.js b/test/api/authorization-test.js deleted file mode 100644 index a37e9319..00000000 --- a/test/api/authorization-test.js +++ /dev/null @@ -1,46 +0,0 @@ -import dotenv from 'dotenv' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { expect } from 'chai' - -dotenv.config() - -const orgID = process.env.ORGANIZATION -let client = {} -let apps = {} - -describe('Apps api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - apps = jsonReader('apps.json') - }) - - it('fetch all authorization apps test', done => { - client.organization(orgID).app(apps.uid).authorization().findAll() - .then((response) => { - expect(response).to.not.equal(null) - done() - }) - .catch(done) - }) - - it('revoke all authorization apps test', done => { - client.organization(orgID).app(apps.uid).authorization().revokeAll() - .then((response) => { - expect(response).to.not.equal(null) - done() - }) - .catch(done) - }) - - it('revoke all authorization apps test', done => { - client.organization(orgID).app(apps.uid).authorization().revoke('uid') - .then((response) => { - expect(response).to.not.equal(null) - done() - }) - .catch(done) - }) -}) diff --git a/test/api/branch-test.js b/test/api/branch-test.js deleted file mode 100644 index 69237d6e..00000000 --- a/test/api/branch-test.js +++ /dev/null @@ -1,222 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { branch, devBranch } from './mock/branch' - -var client = {} -var stack = {} - -describe('Branch api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Branch query should return master branch', done => { - makeBranch() - .query() - .find() - .then((response) => { - expect(response.items.length).to.be.equal(1) - var item = response.items[0] - expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) - expect(item.delete).to.not.equal(undefined) - expect(item.fetch).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('Should create Branch', done => { - makeBranch() - .create({ branch }) - .then((response) => { - expect(response.uid).to.be.equal(branch.uid) - expect(response.urlPath).to.be.equal(`/stacks/branches/${branch.uid}`) - expect(response.source).to.be.equal(branch.source) - expect(response.alias).to.not.equal(undefined) - expect(response.delete).to.not.equal(undefined) - expect(response.fetch).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('Should create Branch from staging', done => { - makeBranch() - .create({ branch: devBranch }) - .then((response) => { - expect(response.uid).to.be.equal(devBranch.uid) - expect(response.urlPath).to.be.equal(`/stacks/branches/${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) - done() - }) - .catch(done) - }) - - it('Should fetch branch from branch uid', done => { - makeBranch(devBranch.uid) - .fetch() - .then((response) => { - expect(response.uid).to.be.equal(devBranch.uid) - expect(response.urlPath).to.be.equal(`/stacks/branches/${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) - done() - }) - .catch(done) - }) - - it('Branch query should return all branches', done => { - makeBranch() - .query() - .find() - .then((response) => { - expect(response.items.length).to.be.equal(3) - response.items.forEach(item => { - expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) - expect(item.delete).to.not.equal(undefined) - expect(item.fetch).to.not.equal(undefined) - }) - done() - }) - .catch(done) - }) - - it('Branch query for specific condition', done => { - makeBranch() - .query({ query: { source: 'master' } }) - .find() - .then((response) => { - expect(response.items.length).to.be.equal(1) - response.items.forEach(item => { - expect(item.urlPath).to.be.equal(`/stacks/branches/${item.uid}`) - expect(item.source).to.be.equal(`master`) - expect(item.delete).to.not.equal(undefined) - expect(item.fetch).to.not.equal(undefined) - }) - done() - }) - .catch(done) - }) - - it('Should delete branch from branch uid', done => { - makeBranch(devBranch.uid) - .delete() - .then((response) => { - expect(response.notice).to.be.equal('Branch deleted successfully.') - done() - }) - .catch(done) - }) - - it('Should provide list of content types and global fields that exist in only one branch or are different between the two branches', done => { - makeBranch(branch.uid) - .compare(devBranch.uid) - .all() - .then((response) => { - expect(response.branches.base_branch).to.be.equal(branch.uid) - expect(response.branches.compare_branch).to.be.equal(devBranch.uid) - done() - }) - .catch(done) - }) - - it('Should list differences for a content types between two branches', done => { - makeBranch(branch.uid) - .compare(devBranch.uid) - .contentTypes() - .then((response) => { - expect(response.branches.base_branch).to.be.equal(branch.uid) - expect(response.branches.compare_branch).to.be.equal(devBranch.uid) - done() - }) - .catch(done) - }) - - it('Should list differences for a global fields between two branches', done => { - makeBranch(branch.uid) - .compare(devBranch.uid) - .globalFields() - .then((response) => { - expect(response.branches.base_branch).to.be.equal(branch.uid) - expect(response.branches.compare_branch).to.be.equal(devBranch.uid) - done() - }) - .catch(done) - }) - - it('Should provide list of global fields that exist in only one branch or are different between the two branches', done => { - const params = { - base_branch: branch.uid, - compare_branch: devBranch.uid, - 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: 'ct5', - type: 'content_type', - merge_strategy: 'merge_prefer_compare' - }, - { - uid: 'bot_all', - type: 'content_type', - merge_strategy: 'merge_prefer_base' - } - ] - } - makeBranch() - .merge(mergeObj, params) - .then((response) => { - expect(response.merge_details.base_branch).to.be.equal(branch.uid) - expect(response.merge_details.compare_branch).to.be.equal(devBranch.uid) - done() - }) - .catch(done) - }) - - it('Should list all recent merge jobs', done => { - makeBranch() - .mergeQueue() - .find() - .then((response) => { - expect(response.queue).to.not.equal(undefined) - expect(response.queue[0].merge_details.base_branch).to.be.equal(branch.uid) - expect(response.queue[0].merge_details.compare_branch).to.be.equal(devBranch.uid) - done() - }) - .catch(done) - }) - - it('Should list details of merge job when job uid is passed', done => { - const mergeJobUid = 'db7bf199-2a9d-4c2c-99d5-72453f70fb40' - makeBranch() - .mergeQueue(mergeJobUid) - .fetch() - .then((response) => { - expect(response.queue).to.not.equal(undefined) - expect(response.queue[0].merge_details.base_branch).to.be.equal(branch.uid) - expect(response.queue[0].merge_details.compare_branch).to.be.equal(devBranch.uid) - done() - }) - .catch(done) - }) -}) - -function makeBranch (uid = null) { - return client.stack({ api_key: stack.api_key }).branch(uid) -} diff --git a/test/api/branchAlias-test.js b/test/api/branchAlias-test.js deleted file mode 100644 index 688058c9..00000000 --- a/test/api/branchAlias-test.js +++ /dev/null @@ -1,78 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { branch } from './mock/branch' - -var client = {} -var stack = {} - -describe('Branch Alias api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Should create Branch Alias', done => { - makeBranchAlias(`${branch.uid}_alias`) - .createOrUpdate(branch.uid) - .then((response) => { - expect(response.uid).to.be.equal(branch.uid) - expect(response.urlPath).to.be.equal(`/stacks/branches/${branch.uid}`) - expect(response.source).to.be.equal(branch.source) - expect(response.alias).to.be.equal(`${branch.uid}_alias`) - expect(response.delete).to.not.equal(undefined) - expect(response.fetch).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('Branch query should return master branch', done => { - makeBranchAlias() - .fetchAll({ query: { uid: branch.uid } }) - .then((response) => { - expect(response.items.length).to.be.equal(1) - var item = response.items[0] - expect(item.urlPath).to.be.equal(`/stacks/branches/${branch.uid}`) - expect(item.delete).to.not.equal(undefined) - expect(item.fetch).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('Should fetch Branch Alias', done => { - makeBranchAlias(`${branch.uid}_alias`) - .fetch() - .then((response) => { - expect(response.uid).to.be.equal(branch.uid) - expect(response.urlPath).to.be.equal(`/stacks/branches/${branch.uid}`) - expect(response.source).to.be.equal(branch.source) - expect(response.alias).to.be.equal(`${branch.uid}_alias`) - expect(response.delete).to.not.equal(undefined) - expect(response.fetch).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('Should delete Branch Alias', done => { - try { - makeBranchAlias(`${branch.uid}_alias`) - .delete() - .then((response) => { - expect(response.notice).to.be.equal('BranchAlias deleted successfully.') - done() - }) - .catch(done) - } catch (e) { - done() - } - }) -}) - -function makeBranchAlias (uid = null) { - return client.stack({ api_key: stack.api_key }).branchAlias(uid) -} diff --git a/test/api/bulkOperation-test.js b/test/api/bulkOperation-test.js deleted file mode 100644 index 7fc2ff2d..00000000 --- a/test/api/bulkOperation-test.js +++ /dev/null @@ -1,109 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} -var stack = {} - -describe('BulkOperation api test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('should publish one entry when publishDetails of an entry is passed', done => { - const publishDetails = { - entries: [ - { - uid: 'blte6542a9aac484405', - content_type: 'bye', - version: 1, - locale: 'en-us' - } - ], - locales: [ - 'en-us' - ], - environments: [ - 'dev' - ] - } - doBulkOperation() - .publish({ details: publishDetails, api_version: '3.2' }) - .then((response) => { - expect(response.notice).to.not.equal(undefined) - expect(response.job_id).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('should publish one asset when publishDetails of an asset is passed', done => { - const publishDetails = { - assets: [ - { - uid: 'blt9f8e5aa45ac36455' - } - ], - locales: [ - 'en-us' - ], - environments: [ - 'dev' - ] - } - doBulkOperation() - .publish({ details: publishDetails, api_version: '3.2' }) - .then((response) => { - expect(response.notice).to.not.equal(undefined) - expect(response.job_id).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('should publish multiple entries assets when publishDetails of entries and assets are passed', done => { - const publishDetails = { - entries: [ - { - uid: 'blt077157784a170bab', - content_type: 'bye', - version: 1, - locale: 'en-us' - }, { - uid: 'blta519039712ca2b8a', - content_type: 'bye', - version: 1, - locale: 'en-us' - } - ], - assets: [ - { - uid: 'blt9f8e5aa45ac36455' - }, { - uid: 'blt3b097cc58475b0a3' - } - ], - locales: [ - 'en-us' - ], - environments: [ - 'dev' - ] - } - doBulkOperation() - .publish({ details: publishDetails, api_version: '3.2' }) - .then((response) => { - expect(response.notice).to.not.equal(undefined) - expect(response.job_id).to.not.equal(undefined) - done() - }) - .catch(done) - }) -}) - -function doBulkOperation (uid = null) { - return client.stack({ api_key: stack.api_key }).bulkOperation() -} diff --git a/test/api/contentType-delete-test.js b/test/api/contentType-delete-test.js deleted file mode 100644 index bd5bf5cb..00000000 --- a/test/api/contentType-delete-test.js +++ /dev/null @@ -1,29 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { multiPageCT } from './mock/content-type' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -describe('Content Type delete api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Content Type delete', done => { - makeContentType(multiPageCT.content_type.uid) - .delete().then((data) => { - expect(data.notice).to.be.equal('Content Type deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeContentType (uid = null) { - return client.stack({ api_key: stack.api_key }).contentType(uid) -} diff --git a/test/api/contentType-test.js b/test/api/contentType-test.js deleted file mode 100644 index 6f104234..00000000 --- a/test/api/contentType-test.js +++ /dev/null @@ -1,121 +0,0 @@ -import path from 'path' -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { singlepageCT, multiPageCT, schema } from './mock/content-type' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -describe('Content Type api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Create Single page ContentType Schema', done => { - makeContentType() - .create(singlepageCT) - .then((contentType) => { - expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid) - expect(contentType.title).to.be.equal(singlepageCT.content_type.title) - done() - }) - .catch(done) - }) - - it('Create Multi page ContentType Schema', done => { - makeContentType() - .create(multiPageCT) - .then((contentType) => { - expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid) - expect(contentType.title).to.be.equal(multiPageCT.content_type.title) - done() - }) - .catch(done) - }) - - it('Get all ContentType', done => { - makeContentType() - .query() - .find() - .then((response) => { - response.items.forEach(contentType => { - expect(contentType.uid).to.be.not.equal(null) - expect(contentType.title).to.be.not.equal(null) - expect(contentType.schema).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query ContentType title', done => { - makeContentType() - .query({ query: { title: singlepageCT.content_type.title } }) - .find() - .then((response) => { - response.items.forEach(contentType => { - expect(contentType.uid).to.be.not.equal(null) - expect(contentType.title).to.be.not.equal(null) - expect(contentType.schema).to.be.not.equal(null) - expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid, 'UID not mathcing') - expect(contentType.title).to.be.equal(singlepageCT.content_type.title, 'Title not mathcing') - }) - done() - }) - .catch(done) - }) - - it('Fetch ContentType from uid', done => { - makeContentType(multiPageCT.content_type.uid) - .fetch() - .then((contentType) => { - expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid) - expect(contentType.title).to.be.equal(multiPageCT.content_type.title) - done() - }) - .catch(done) - }) - - it('Fetch and Update ContentType schema', done => { - makeContentType(multiPageCT.content_type.uid) - .fetch() - .then((contentType) => { - contentType.schema = schema - return contentType.update() - }) - .then((contentType) => { - expect(contentType.schema.length).to.be.equal(6) - done() - }) - .catch(done) - }) - - it('Update ContentType schema without fetch', done => { - makeContentType(multiPageCT.content_type.uid) - .updateCT({ content_type: { schema: schema } }) - .then((contentType) => { - expect(contentType.schema.length).to.be.equal(6) - done() - }) - .catch(done) - }) - - it('Import content type', done => { - makeContentType().import({ - content_type: path.join(__dirname, './mock/contentType.json') - }) - .then((response) => { - expect(response.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) -}) - -function makeContentType (uid = null) { - return client.stack({ api_key: stack.api_key }).contentType(uid) -} diff --git a/test/api/delete-test.js b/test/api/delete-test.js deleted file mode 100644 index 9276d10d..00000000 --- a/test/api/delete-test.js +++ /dev/null @@ -1,35 +0,0 @@ - -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -var client = {} - -var stack = {} -describe('Delete api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Delete role in stack', done => { - const role = jsonReader('role.json') - client.stack({ api_key: stack.api_key }).role(role.uid) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('The role deleted successfully.', 'Role delete notice does not match') - done() - }) - .catch(done) - }) - - it('User logout test', done => { - client.logout() - .then((response) => { - expect(response.notice).to.be.equal('You\'ve logged out successfully.') - done() - }) - .catch(done) - }) -}) diff --git a/test/api/deliveryToken-test.js b/test/api/deliveryToken-test.js deleted file mode 100644 index 3218b757..00000000 --- a/test/api/deliveryToken-test.js +++ /dev/null @@ -1,143 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { createDeliveryToken, createDeliveryToken2 } from './mock/deliveryToken.js' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -var tokenUID = '' -describe('Delivery Token api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Add a Delivery Token', done => { - makeDeliveryToken() - .create(createDeliveryToken) - .then((token) => { - expect(token.name).to.be.equal(createDeliveryToken.token.name) - expect(token.description).to.be.equal(createDeliveryToken.token.description) - expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0]) - expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Add a Delivery Token for production', done => { - makeDeliveryToken() - .create(createDeliveryToken2) - .then((token) => { - tokenUID = token.uid - expect(token.name).to.be.equal(createDeliveryToken2.token.name) - expect(token.description).to.be.equal(createDeliveryToken2.token.description) - expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) - expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get a Delivery Token from uid', done => { - makeDeliveryToken(tokenUID) - .fetch() - .then((token) => { - expect(token.name).to.be.equal(createDeliveryToken2.token.name) - expect(token.description).to.be.equal(createDeliveryToken2.token.description) - expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) - expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Query to get all Delivery Token', done => { - makeDeliveryToken() - .query() - .find() - .then((tokens) => { - tokens.items.forEach((token) => { - expect(token.name).to.be.not.equal(null) - expect(token.description).to.be.not.equal(null) - expect(token.scope[0].environments[0].name).to.be.not.equal(null) - expect(token.scope[0].module).to.be.not.equal(null) - expect(token.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query to get a Delivery Token from name', done => { - makeDeliveryToken() - .query({ query: { name: createDeliveryToken.token.name } }) - .find() - .then((tokens) => { - tokens.items.forEach((token) => { - expect(token.name).to.be.equal(createDeliveryToken.token.name) - expect(token.description).to.be.equal(createDeliveryToken.token.description) - expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0]) - expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Fetch and update a Delivery Token from uid', done => { - makeDeliveryToken(tokenUID) - .fetch() - .then((token) => { - token.name = 'Update Production Name' - token.description = 'Update Production description' - token.scope = createDeliveryToken2.token.scope - return token.update() - }) - .then((token) => { - expect(token.name).to.be.equal('Update Production Name') - expect(token.description).to.be.equal('Update Production description') - expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) - expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Update a Delivery Token from uid', done => { - const token = makeDeliveryToken(tokenUID) - Object.assign(token, createDeliveryToken2.token) - token.update() - .then((token) => { - expect(token.name).to.be.equal(createDeliveryToken2.token.name) - expect(token.description).to.be.equal(createDeliveryToken2.token.description) - expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0]) - expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Delete a Delivery Token from uid', done => { - makeDeliveryToken(tokenUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Delivery Token deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeDeliveryToken (uid = null) { - return client.stack({ api_key: stack.api_key }).deliveryToken(uid) -} diff --git a/test/api/entry-test.js b/test/api/entry-test.js deleted file mode 100644 index af97ad76..00000000 --- a/test/api/entry-test.js +++ /dev/null @@ -1,234 +0,0 @@ -import path from 'path' -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite' -import { multiPageCT, singlepageCT } from './mock/content-type.js' -import { entryFirst, entrySecond, entryThird } from './mock/entry.js' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -var entryUTD = '' -describe('Entry api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Create Entry in Single ', done => { - var entry = { - title: 'Sample Entry', - url: 'sampleEntry' - } - makeEntry(singlepageCT.content_type.uid) - .create({ entry }) - .then((entryResponse) => { - entryUTD = entryResponse.uid - expect(entryResponse.title).to.be.equal(entry.title) - expect(entryResponse.url).to.be.equal(entry.url) - expect(entryResponse.uid).to.be.not.equal(null) - expect(entryResponse.locale).to.be.equal(stack.master_locale) - done() - }) - .catch(done) - }) - it('Entry fetch with Content Type', done => { - makeEntry(singlepageCT.content_type.uid, entryUTD) - .fetch({ include_content_type: true }) - .then((entryResponse) => { - expect(entryResponse.uid).to.be.not.equal(null) - expect(entryResponse.content_type).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Localize entry with title update', done => { - makeEntry(singlepageCT.content_type.uid, entryUTD) - .fetch() - .then((entry) => { - entry.title = 'Sample Entry in en-at' - return entry.update({ locale: 'en-at' }) - }) - .then((entryResponse) => { - entryUTD = entryResponse.uid - expect(entryResponse.title).to.be.equal('Sample Entry in en-at') - expect(entryResponse.uid).to.be.not.equal(null) - expect(entryResponse.locale).to.be.equal('en-at') - done() - }) - .catch(done) - }) - - it('Create Entries for Multiple page', done => { - makeEntry(multiPageCT.content_type.uid) - .create({ entry: entryFirst }) - .then((entry) => { - expect(entry.uid).to.be.not.equal(null) - expect(entry.title).to.be.equal(entryFirst.title) - expect(entry.single_line).to.be.equal(entryFirst.single_line) - expect(entry.url).to.be.equal(`/${entryFirst.title.toLowerCase().replace(/ /g, '-')}`) - expect(entry.multi_line).to.be.equal(entryFirst.multi_line) - expect(entry.markdown).to.be.equal(entryFirst.markdown) - done() - }) - .catch(done) - }) - - it('Create Entries 2 for Multiple page', done => { - makeEntry(multiPageCT.content_type.uid) - .create({ entry: entrySecond }) - .then((entry) => { - expect(entry.uid).to.be.not.equal(null) - expect(entry.title).to.be.equal(entrySecond.title) - expect(entry.url).to.be.equal(`/${entrySecond.title.toLowerCase().replace(/ /g, '-')}`) - expect(entry.single_line).to.be.equal(entrySecond.single_line) - expect(entry.multi_line).to.be.equal(entrySecond.multi_line) - expect(entry.markdown).to.be.equal(entrySecond.markdown) - expect(entry.tags[0]).to.be.equal(entrySecond.tags[0]) - done() - }) - .catch(done) - }) - - it('Create Entries 3 for Multiple page', done => { - makeEntry(multiPageCT.content_type.uid) - .create({ entry: entryThird }) - .then((entry) => { - expect(entry.uid).to.be.not.equal(null) - expect(entry.title).to.be.equal(entryThird.title) - expect(entry.url).to.be.equal(`/${entryThird.title.toLowerCase().replace(/ /g, '-')}`) - expect(entry.single_line).to.be.equal(entryThird.single_line) - expect(entry.multi_line).to.be.equal(entryThird.multi_line) - expect(entry.markdown).to.be.equal(entryThird.markdown) - expect(entry.tags[0]).to.be.equal(entryThird.tags[0]) - done() - }) - .catch(done) - }) - - it('Get all Entry', done => { - makeEntry(multiPageCT.content_type.uid) - .query({ include_count: true, include_content_type: true }).find() - .then((collection) => { - jsonWrite(collection.items, 'entry.json') - expect(collection.count).to.be.equal(3) - collection.items.forEach((entry) => { - expect(entry.uid).to.be.not.equal(null) - expect(entry.content_type_uid).to.be.equal(multiPageCT.content_type.uid) - }) - done() - }) - .catch(done) - }) - - it('Get all Entry from tag', done => { - makeEntry(multiPageCT.content_type.uid) - .query({ include_count: true, query: { tags: entrySecond.tags[0] } }).find() - .then((collection) => { - expect(collection.count).to.be.equal(1) - collection.items.forEach((entry) => { - expect(entry.uid).to.be.not.equal(null) - expect(entry.tags).to.have.all.keys(0) - }) - done() - }) - .catch(done) - }) - - it('Publish Entry', done => { - makeEntry(singlepageCT.content_type.uid, entryUTD) - .publish({ publishDetails: { - locales: ['en-us'], - environments: ['development'] - } }) - .then((data) => { - expect(data.notice).to.be.equal('The requested action has been performed.') - done() - }) - .catch(done) - }) - - it('Publish localized Entry to locales', done => { - makeEntry(singlepageCT.content_type.uid, entryUTD) - .publish({ publishDetails: { - locales: ['hi-in', 'en-at'], - environments: ['development'] - }, - locale: 'en-at' }) - .then((data) => { - expect(data.notice).to.be.equal('The requested action has been performed.') - done() - }) - .catch(done) - }) - - it('Unpublish localized entry', done => { - makeEntry(singlepageCT.content_type.uid, entryUTD) - .unpublish({ publishDetails: { - locales: ['hi-in', 'en-at'], - environments: ['development'] - }, - locale: 'en-at' }) - .then((data) => { - expect(data.notice).to.be.equal('The requested action has been performed.') - done() - }) - .catch(done) - }) - - it('Import Entry', done => { - makeEntry(multiPageCT.content_type.uid) - .import({ - entry: path.join(__dirname, './mock/entry.json') - }) - .then((response) => { - expect(response.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Create and update an entry with asset', done => { - // get asset - let asset - makeAsset() - .query() - .find() - .then((collection) => { - asset = collection.items[0] - // create entry - const entry = { - ...entryFirst, - title: 'uniqueTitle45', - modular_blocks: [ - { - block1: { - file: asset.uid - } - } - ] - } - 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() - }) - }) - }) - }) -}) - -function makeEntry (contentType, uid = null) { - return client.stack({ api_key: stack.api_key }).contentType(contentType).entry(uid) -} - -function makeAsset (uid = null) { - return client.stack({ api_key: stack.api_key }).asset(uid) -} diff --git a/test/api/environment-test.js b/test/api/environment-test.js deleted file mode 100644 index e462ee02..00000000 --- a/test/api/environment-test.js +++ /dev/null @@ -1,139 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite' -import { environmentCreate, environmentProdCreate } from './mock/environment.js' -import { cloneDeep } from 'lodash' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -describe('Environment api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Add a Environment development', done => { - makeEnvironment() - .create(environmentCreate) - .then((environment) => { - expect(environment.name).to.be.equal(environmentCreate.environment.name) - expect(environment.deploy_content).to.be.equal(environmentCreate.environment.deploy_content) - expect(environment.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Add a Environment production', done => { - makeEnvironment() - .create(environmentProdCreate) - .then((environment) => { - expect(environment.name).to.be.equal(environmentProdCreate.environment.name) - expect(environment.deploy_content).to.be.equal(environmentProdCreate.environment.deploy_content) - expect(environment.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get a Environment development', done => { - makeEnvironment(environmentCreate.environment.name) - .fetch() - .then((environment) => { - expect(environment.name).to.be.equal(environmentCreate.environment.name) - expect(environment.deploy_content).to.be.equal(environmentCreate.environment.deploy_content) - expect(environment.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Query a Environment development', done => { - makeEnvironment() - .query({ query: { name: environmentCreate.environment.name } }) - .find() - .then((environments) => { - environments.items.forEach((environment) => { - expect(environment.name).to.be.equal(environmentCreate.environment.name) - expect(environment.deploy_content).to.be.equal(environmentCreate.environment.deploy_content) - expect(environment.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Fetch and Update a Environment', done => { - makeEnvironment(environmentCreate.environment.name) - .fetch() - .then((environment) => { - environment.name = 'dev' - return environment.update() - }) - .then((environment) => { - expect(environment.name).to.be.equal('dev') - expect(environment.deploy_content).to.be.equal(environmentCreate.environment.deploy_content) - expect(environment.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Update a Environment', done => { - var environment = makeEnvironment('dev') - Object.assign(environment, cloneDeep(environmentCreate.environment)) - environment.update() - .then((environment) => { - expect(environment.name).to.be.equal(environmentCreate.environment.name) - expect(environment.deploy_content).to.be.equal(environmentCreate.environment.deploy_content) - expect(environment.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('delete a Environment', done => { - makeEnvironment(environmentProdCreate.environment.name) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Environment deleted successfully.') - done() - }) - .catch(done) - }) - - it('Add a Environment production', done => { - makeEnvironment() - .create(environmentProdCreate) - .then((environment) => { - expect(environment.name).to.be.equal(environmentProdCreate.environment.name) - expect(environment.deploy_content).to.be.equal(environmentProdCreate.environment.deploy_content) - expect(environment.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Query all Environments', done => { - makeEnvironment() - .query() - .find() - .then((environments) => { - jsonWrite(environments.items, 'environments.json') - environments.items.forEach((environment) => { - expect(environment.name).to.be.not.equal(null) - expect(environment.deploy_content).to.be.not.equal(null) - expect(environment.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) -}) - -function makeEnvironment (uid = null) { - return client.stack({ api_key: stack.api_key }).environment(uid) -} diff --git a/test/api/extension-test.js b/test/api/extension-test.js deleted file mode 100644 index 01fac1c4..00000000 --- a/test/api/extension-test.js +++ /dev/null @@ -1,296 +0,0 @@ -import path from 'path' -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { customFieldURL, customFieldSRC, customWidgetURL, customWidgetSRC, customDashboardURL, customDashboardSRC } from './mock/extension' -import { contentstackClient } from '../utility/ContentstackClient.js' -var client = {} -var stack = {} - -var customFieldUID = '' -var customWidgetUID = '' -var customDashboardUID = '' - -describe('Extension api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - it('Create Custom field with source URL', done => { - makeExtension() - .create(customFieldURL) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - customFieldUID = extension.uid - expect(extension.title).to.be.equal(customFieldURL.extension.title) - expect(extension.src).to.be.equal(customFieldURL.extension.src) - expect(extension.type).to.be.equal(customFieldURL.extension.type) - expect(extension.tag).to.be.equal(customFieldURL.extension.tag) - done() - }) - .catch(done) - }) - - it('Create Custom field with source Code', done => { - makeExtension() - .create(customFieldSRC) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.equal(customFieldSRC.extension.title) - expect(extension.src).to.be.equal(customFieldSRC.extension.src) - expect(extension.type).to.be.equal(customFieldSRC.extension.type) - expect(extension.tag).to.be.equal(customFieldSRC.extension.tag) - done() - }) - .catch(done) - }) - - it('Create Custom widget with source URL', done => { - makeExtension() - .create(customWidgetURL) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - customWidgetUID = extension.uid - expect(extension.title).to.be.equal(customWidgetURL.extension.title) - expect(extension.src).to.be.equal(customWidgetURL.extension.src) - expect(extension.type).to.be.equal(customWidgetURL.extension.type) - expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) - done() - }) - .catch(done) - }) - - it('Create Custom widget with source Code', done => { - makeExtension() - .create(customWidgetSRC) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.equal(customWidgetSRC.extension.title) - expect(extension.src).to.be.equal(customWidgetSRC.extension.src) - expect(extension.type).to.be.equal(customWidgetSRC.extension.type) - expect(extension.tag).to.be.equal(customWidgetSRC.extension.tag) - done() - }) - .catch(done) - }) - - it('Create Custom dashboard with source URL', done => { - makeExtension() - .create(customDashboardURL) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - customDashboardUID = extension.uid - expect(extension.title).to.be.equal(customDashboardURL.extension.title) - expect(extension.src).to.be.equal(customDashboardURL.extension.src) - expect(extension.type).to.be.equal(customDashboardURL.extension.type) - expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) - done() - }) - .catch(done) - }) - - it('Create Custom dashboard with source Code', done => { - makeExtension() - .create(customDashboardSRC) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.equal(customDashboardSRC.extension.title) - expect(extension.src).to.be.equal(customDashboardSRC.extension.src) - expect(extension.type).to.be.equal(customDashboardSRC.extension.type) - expect(extension.tag).to.be.equal(customDashboardSRC.extension.tag) - done() - }) - .catch(done) - }) - - it('fetch and Update Custom fields', done => { - makeExtension(customFieldUID) - .fetch() - .then((extension) => { - expect(extension.title).to.be.equal(customFieldURL.extension.title) - expect(extension.src).to.be.equal(customFieldURL.extension.src) - expect(extension.type).to.be.equal(customFieldURL.extension.type) - expect(extension.tag).to.be.equal(customFieldURL.extension.tag) - extension.title = 'Old field' - return extension.update() - }) - .then((extension) => { - expect(extension.uid).to.be.equal(customFieldUID) - expect(extension.title).to.be.equal('Old field') - expect(extension.src).to.be.equal(customFieldURL.extension.src) - expect(extension.type).to.be.equal(customFieldURL.extension.type) - expect(extension.tag).to.be.equal(customFieldURL.extension.tag) - done() - }) - .catch(done) - }) - - it('fetch and Update Custom Widget', done => { - makeExtension(customWidgetUID) - .fetch() - .then((extension) => { - expect(extension.title).to.be.equal(customWidgetURL.extension.title) - expect(extension.src).to.be.equal(customWidgetURL.extension.src) - expect(extension.type).to.be.equal(customWidgetURL.extension.type) - expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) - extension.title = 'Old widget' - return extension.update() - }) - .then((extension) => { - expect(extension.uid).to.be.equal(customWidgetUID) - expect(extension.title).to.be.equal('Old widget') - expect(extension.src).to.be.equal(customWidgetURL.extension.src) - expect(extension.type).to.be.equal(customWidgetURL.extension.type) - expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) - done() - }) - .catch(done) - }) - - it('fetch and Update Custom dashboard', done => { - makeExtension(customDashboardUID) - .fetch() - .then((extension) => { - expect(extension.title).to.be.equal(customDashboardURL.extension.title) - expect(extension.src).to.be.equal(customDashboardURL.extension.src) - expect(extension.type).to.be.equal(customDashboardURL.extension.type) - expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) - extension.title = 'Old dashboard' - return extension.update() - }) - .then((extension) => { - expect(extension.uid).to.be.equal(customDashboardUID) - expect(extension.title).to.be.equal('Old dashboard') - expect(extension.src).to.be.equal(customDashboardURL.extension.src) - expect(extension.type).to.be.equal(customDashboardURL.extension.type) - expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) - done() - }) - .catch(done) - }) - - it('Query Custom field', done => { - makeExtension() - .query({ query: { type: 'field' } }) - .find() - .then((extensions) => { - extensions.items.forEach(extension => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.not.equal(null) - expect(extension.type).to.be.equal('field') - }) - done() - }) - .catch(done) - }) - - it('Query Custom widget', done => { - makeExtension() - .query({ query: { type: 'widget' } }) - .find() - .then((extensions) => { - extensions.items.forEach(extension => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.not.equal(null) - expect(extension.type).to.be.equal('widget') - }) - done() - }) - .catch(done) - }) - - it('Query Custom dashboard', done => { - makeExtension() - .query({ query: { type: 'dashboard' } }) - .find() - .then((extensions) => { - extensions.items.forEach(extension => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.not.equal(null) - expect(extension.type).to.be.equal('dashboard') - }) - done() - }) - .catch(done) - }) - - it('Upload Custom field', done => { - makeExtension() - .upload({ - title: 'Custom field Upload', - data_type: customFieldURL.extension.data_type, - type: customFieldURL.extension.type, - tags: customFieldURL.extension.tags, - multiple: customFieldURL.extension.multiple, - upload: path.join(__dirname, './mock/customUpload.html') - }) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.equal('Custom field Upload') - expect(extension.data_type).to.be.equal(customFieldURL.extension.data_type) - expect(extension.type).to.be.equal(customFieldURL.extension.type) - expect(extension.tag).to.be.equal(customFieldURL.extension.tag) - done() - }) - .catch(done) - }) - - it('Upload Custom widget', done => { - makeExtension() - .upload({ - title: 'Custom widget Upload', - data_type: customWidgetURL.extension.data_type, - type: customWidgetURL.extension.type, - scope: customWidgetURL.extension.scope, - tags: customWidgetURL.extension.tags.join(','), - upload: path.join(__dirname, './mock/customUpload.html') - }) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.equal('Custom widget Upload') - expect(extension.type).to.be.equal(customWidgetURL.extension.type) - expect(extension.tag).to.be.equal(customWidgetURL.extension.tag) - done() - }) - .catch(done) - }) - - it('Upload dashboard', done => { - makeExtension() - .upload({ - title: 'Custom dashboard Upload', - data_type: customDashboardURL.extension.data_type, - type: customDashboardURL.extension.type, - tags: customDashboardURL.extension.tags, - enable: customDashboardURL.extension.enable, - default_width: customDashboardURL.extension.default_width, - upload: path.join(__dirname, './mock/customUpload.html') - }) - .then((extension) => { - expect(extension.uid).to.be.not.equal(null) - expect(extension.title).to.be.equal('Custom dashboard Upload') - expect(extension.data_type).to.be.equal(customDashboardURL.extension.data_type) - expect(extension.type).to.be.equal(customDashboardURL.extension.type) - expect(extension.tag).to.be.equal(customDashboardURL.extension.tag) - expect(extension.enable).to.be.equal(customDashboardURL.extension.enable) - expect(extension.default_width).to.be.equal(customDashboardURL.extension.default_width) - done() - }) - .catch(done) - }) - - it('Delete Custom dashboard', done => { - makeExtension(customDashboardUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Extension deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeExtension (uid = null) { - return client.stack({ api_key: stack.api_key }).extension(uid) -} diff --git a/test/api/globalfield-test.js b/test/api/globalfield-test.js deleted file mode 100644 index ddccc2e8..00000000 --- a/test/api/globalfield-test.js +++ /dev/null @@ -1,119 +0,0 @@ -import path from 'path' -import { expect } from 'chai' -import { cloneDeep } from 'lodash' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { createGlobalField } from './mock/globalfield' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} - -describe('Global Field api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Create global fields', done => { - makeGlobalField().create(createGlobalField) - .then((globalField) => { - expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid) - expect(globalField.title).to.be.equal(createGlobalField.global_field.title) - expect(globalField.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) - expect(globalField.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) - expect(globalField.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) - done() - }) - .catch(done) - }) - - it('Fetch global Field', done => { - makeGlobalField(createGlobalField.global_field.uid).fetch() - .then((globalField) => { - expect(globalField.uid).to.be.equal(createGlobalField.global_field.uid) - expect(globalField.title).to.be.equal(createGlobalField.global_field.title) - expect(globalField.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) - expect(globalField.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) - expect(globalField.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) - done() - }) - .catch(done) - }) - - it('Fetch and update global Field', done => { - makeGlobalField(createGlobalField.global_field.uid).fetch() - .then((globalField) => { - globalField.title = 'Update title' - return globalField.update() - }) - .then((updateGlobal) => { - expect(updateGlobal.uid).to.be.equal(createGlobalField.global_field.uid) - expect(updateGlobal.title).to.be.equal('Update title') - expect(updateGlobal.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) - expect(updateGlobal.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) - expect(updateGlobal.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) - done() - }) - .catch(done) - }) - - it('Update global Field', done => { - var globalField = makeGlobalField(createGlobalField.global_field.uid) - Object.assign(globalField, cloneDeep(createGlobalField.global_field)) - globalField.update() - .then((updateGlobal) => { - expect(updateGlobal.uid).to.be.equal(createGlobalField.global_field.uid) - expect(updateGlobal.title).to.be.equal(createGlobalField.global_field.title) - expect(updateGlobal.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid) - expect(updateGlobal.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type) - expect(updateGlobal.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name) - done() - }) - .catch(done) - }) - - it('Import global Field', done => { - makeGlobalField().import({ - global_field: path.join(__dirname, './mock/globalfield.json') - }) - .then((response) => { - expect(response.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get all global field from Query', done => { - makeGlobalField().query() - .find() - .then((collection) => { - collection.items.forEach(globalField => { - expect(globalField.uid).to.be.not.equal(null) - expect(globalField.title).to.be.not.equal(null) - expect(globalField.schema).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Get global field title matching Upload', done => { - makeGlobalField().query({ query: { title: 'Upload' } }) - .find() - .then((collection) => { - collection.items.forEach(globalField => { - expect(globalField.uid).to.be.not.equal(null) - expect(globalField.title).to.be.equal('Upload') - }) - done() - }) - .catch(done) - }) -}) - -function makeGlobalField (uid = null) { - return client.stack({ api_key: stack.api_key }).globalField(uid) -} diff --git a/test/api/hosting-test.js b/test/api/hosting-test.js deleted file mode 100644 index ccc32e23..00000000 --- a/test/api/hosting-test.js +++ /dev/null @@ -1,139 +0,0 @@ -import dotenv from 'dotenv' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { expect } from 'chai' - -dotenv.config() - -let apps = {} -const orgID = process.env.ORGANIZATION -let client = {} -let uploadUid = '' -let deploymentUid = '' -describe('Apps hosting api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - apps = jsonReader('apps.json') - }) - - it('test get apps hosting details', done => { - makeHosting(apps.uid).isEnable() - .then((response) => { - expect(response.enabled).to.not.equal(false) - done() - }) - .catch(done) - }) - - it('test create upload url for apps hosting details', done => { - makeHosting(apps.uid).createUploadUrl() - .then((response) => { - uploadUid = response.upload_uid - expect(response.upload_uid).to.not.equal(undefined) - expect(response.form_fields).to.not.equal(undefined) - expect(response.upload_url).to.not.equal(undefined) - expect(response.expires_in).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('test deployment for signed upload app hosting', done => { - makeHosting(apps.uid).deployment().create({ uploadUid, fileType: 'SOURCE' }) - .then((response) => { - deploymentUid = response.uid - expect(response.deployment_number).to.not.equal(undefined) - expect(response.deployment_url).to.not.equal(undefined) - expect(response.environment).to.not.equal(undefined) - expect(response.uid).to.not.equal(undefined) - expect(response.urlPath).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('test deployment for signed upload app hosting', done => { - makeHosting(apps.uid).deployment().findAll() - .then((response) => { - response.items.forEach(deployment => { - expect(deployment.deployment_number).to.not.equal(undefined) - expect(deployment.deployment_url).to.not.equal(undefined) - expect(deployment.environment).to.not.equal(undefined) - expect(deployment.uid).to.not.equal(undefined) - expect(deployment.urlPath).to.not.equal(undefined) - }) - done() - }) - .catch(done) - }) - - it('test get deployment from uid for app hosting', done => { - makeHosting(apps.uid).deployment(deploymentUid).fetch() - .then((response) => { - expect(response.deployment_number).to.not.equal(undefined) - expect(response.deployment_url).to.not.equal(undefined) - expect(response.environment).to.not.equal(undefined) - expect(response.uid).to.not.equal(undefined) - expect(response.urlPath).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('test get deployment logs for app hosting', done => { - makeHosting(apps.uid).deployment(deploymentUid).logs() - .then((response) => { - for (const i in response) { - const deploymentLogs = response[i] - expect(deploymentLogs.message).to.not.equal(undefined) - expect(deploymentLogs.stage).to.not.equal(undefined) - expect(deploymentLogs.timestamp).to.not.equal(undefined) - } - done() - }) - .catch(done) - }) - - it('test get deployment signed download url for app hosting', done => { - makeHosting(apps.uid).deployment(deploymentUid).signedDownloadUrl() - .then((response) => { - expect(response.download_url).to.not.equal(undefined) - expect(response.expires_in).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('test latest live deployment for apps hosting', done => { - makeHosting(apps.uid).latestLiveDeployment() - .then((response) => { - expect(response).to.not.equal(undefined) - done() - }) - .catch(done) - }) - - it('test enable apps hosting details', done => { - makeHosting(apps.uid).enable() - .then((response) => { - expect(response.enabled).to.not.equal(true) - done() - }) - .catch(done) - }) - - it('test disable apps hosting details', done => { - makeHosting(apps.uid).disable() - .then((response) => { - expect(response.enabled).to.not.equal(false) - done() - }) - .catch(done) - }) -}) - -function makeHosting (appUid) { - return client.organization(orgID).app(appUid).hosting() -} diff --git a/test/api/label-test.js b/test/api/label-test.js deleted file mode 100644 index 4f32b93d..00000000 --- a/test/api/label-test.js +++ /dev/null @@ -1,127 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { singlepageCT } from './mock/content-type.js' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} -var stack = {} - -const label = { - name: 'First label', - content_types: [singlepageCT.content_type.uid] -} - -var labelUID = '' -var deleteLabelUID = '' -describe('Label api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Label create', done => { - makeLabel() - .create({ label }) - .then((labelResponse) => { - labelUID = labelResponse.uid - expect(labelResponse.uid).to.be.not.equal(null) - expect(labelResponse.name).to.be.equal(label.name) - expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) - done() - }) - .catch(done) - }) - - it('Label create with parent uid', done => { - const label = { - name: 'With Parent label', - parent: [labelUID], - content_types: [singlepageCT.content_type.uid] - } - makeLabel() - .create({ label }) - .then((labelResponse) => { - deleteLabelUID = labelResponse.uid - expect(labelResponse.uid).to.be.not.equal(null) - expect(labelResponse.name).to.be.equal(label.name) - expect(labelResponse.parent[0]).to.be.equal(label.parent[0]) - expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) - done() - }) - .catch(done) - }) - - it('Fetch label from uid', done => { - makeLabel(labelUID) - .fetch() - .then((labelResponse) => { - expect(labelResponse.uid).to.be.equal(labelUID) - expect(labelResponse.name).to.be.equal(label.name) - expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) - done() - }) - .catch(done) - }) - - it('Query to get all labels', done => { - makeLabel() - .query({ query: { name: label.name } }) - .find() - .then((response) => { - response.items.forEach((labelResponse) => { - expect(labelResponse.uid).to.be.not.equal(null) - expect(labelResponse.name).to.be.not.equal(null) - expect(labelResponse.content_types).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query label with name', done => { - makeLabel() - .query({ query: { name: label.name } }) - .find() - .then((response) => { - response.items.forEach((labelResponse) => { - expect(labelResponse.uid).to.be.equal(labelUID) - expect(labelResponse.name).to.be.equal(label.name) - expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) - }) - done() - }) - .catch(done) - }) - - it('Fetch and update label from uid', done => { - makeLabel(labelUID) - .fetch() - .then((labelResponse) => { - labelResponse.name = 'Update Name' - return labelResponse.update() - }) - .then((labelResponse) => { - expect(labelResponse.uid).to.be.equal(labelUID) - expect(labelResponse.name).to.be.equal('Update Name') - expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) - done() - }) - .catch(done) - }) - - it('Delete label from uid', done => { - makeLabel(deleteLabelUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Label deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeLabel (uid = null) { - return client.stack({ api_key: stack.api_key }).label(uid) -} diff --git a/test/api/locale-test.js b/test/api/locale-test.js deleted file mode 100644 index 230d8e41..00000000 --- a/test/api/locale-test.js +++ /dev/null @@ -1,129 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -describe('Locale api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Add a language English - Austria', done => { - makeLocale() - .create({ locale: { code: 'en-at' } }) - .then((locale) => { - expect(locale.code).to.be.equal('en-at') - expect(locale.name).to.be.equal('English - Austria') - expect(locale.fallback_locale).to.be.equal('en-us') - expect(locale.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Add a language Hindi - India', done => { - makeLocale() - .create({ locale: { code: 'hi-in' } }) - .then((locale) => { - expect(locale.code).to.be.equal('hi-in') - expect(locale.name).to.be.equal('Hindi - India') - expect(locale.fallback_locale).to.be.equal('en-us') - expect(locale.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Add a language Marathi - India with Fallback en-at', done => { - makeLocale() - .create({ locale: { code: 'mr-in', fallback_locale: 'en-at' } }) - .then((locale) => { - expect(locale.code).to.be.equal('mr-in') - expect(locale.name).to.be.equal('Marathi - India') - expect(locale.fallback_locale).to.be.equal('en-at') - expect(locale.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get a All languages', done => { - makeLocale() - .query() - .find() - .then((locales) => { - locales.items.forEach((locale) => { - expect(locale.code).to.be.not.equal(null) - expect(locale.name).to.be.not.equal(null) - expect(locale.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query a language Hindi - India', done => { - makeLocale() - .query({ query: { name: 'Hindi - India' } }) - .find() - .then((locales) => { - locales.items.forEach((locale) => { - expect(locale.code).to.be.equal('hi-in') - expect(locale.name).to.be.equal('Hindi - India') - expect(locale.fallback_locale).to.be.equal('en-us') - expect(locale.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Get a language Hindi - India', done => { - makeLocale('hi-in') - .fetch() - .then((locale) => { - expect(locale.code).to.be.equal('hi-in') - expect(locale.name).to.be.equal('Hindi - India') - expect(locale.fallback_locale).to.be.equal('en-us') - expect(locale.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get and update a language Hindi - India', done => { - makeLocale('hi-in') - .fetch() - .then((locale) => { - locale.fallback_locale = 'en-at' - return locale.update() - }) - .then((locale) => { - expect(locale.code).to.be.equal('hi-in') - expect(locale.name).to.be.equal('Hindi - India') - expect(locale.fallback_locale).to.be.equal('en-at') - expect(locale.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Removed a language Hindi - India', done => { - makeLocale('mr-in') - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Language removed successfully.') - done() - }) - .catch(done) - }) -}) - -function makeLocale (uid = null) { - return client.stack({ api_key: stack.api_key }).locale(uid) -} diff --git a/test/api/managementToken-test.js b/test/api/managementToken-test.js deleted file mode 100644 index 70aeb0df..00000000 --- a/test/api/managementToken-test.js +++ /dev/null @@ -1,136 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { createManagementToken, createManagementToken2 } from './mock/managementToken.js' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -var tokenUID = '' -describe('Management Token api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Add a Management Token', done => { - makeManagementToken() - .create(createManagementToken) - .then((token) => { - expect(token.name).to.be.equal(createManagementToken.token.name) - expect(token.description).to.be.equal(createManagementToken.token.description) - expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Add a Management Token for production', done => { - makeManagementToken() - .create(createManagementToken2) - .then((token) => { - tokenUID = token.uid - expect(token.name).to.be.equal(createManagementToken2.token.name) - expect(token.description).to.be.equal(createManagementToken2.token.description) - expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get a Management Token from uid', done => { - makeManagementToken(tokenUID) - .fetch() - .then((token) => { - expect(token.name).to.be.equal(createManagementToken2.token.name) - expect(token.description).to.be.equal(createManagementToken2.token.description) - expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Query to get all Management Token', done => { - makeManagementToken() - .query() - .find() - .then((tokens) => { - tokens.items.forEach((token) => { - expect(token.name).to.be.not.equal(null) - expect(token.description).to.be.not.equal(null) - expect(token.scope[0].module).to.be.not.equal(null) - expect(token.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query to get a Management Token from name', done => { - makeManagementToken() - .query({ query: { name: createManagementToken.token.name } }) - .find() - .then((tokens) => { - tokens.items.forEach((token) => { - expect(token.name).to.be.equal(createManagementToken.token.name) - expect(token.description).to.be.equal(createManagementToken.token.description) - expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Fetch and update a Management Token from uid', done => { - makeManagementToken(tokenUID) - .fetch() - .then((token) => { - token.name = 'Update Production Name' - token.description = 'Update Production description' - token.scope = createManagementToken2.token.scope - return token.update() - }) - .then((token) => { - expect(token.name).to.be.equal('Update Production Name') - expect(token.description).to.be.equal('Update Production description') - expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Update a Management Token from uid', done => { - const token = makeManagementToken(tokenUID) - Object.assign(token, createManagementToken2.token) - token.update() - .then((token) => { - expect(token.name).to.be.equal(createManagementToken2.token.name) - expect(token.description).to.be.equal(createManagementToken2.token.description) - expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module) - expect(token.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Delete a Management Token from uid', done => { - makeManagementToken(tokenUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Management Token deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeManagementToken (uid = null) { - return client.stack({ api_key: stack.api_key }).managementToken(uid) -} diff --git a/test/api/mock/berries.jfif b/test/api/mock/berries.jfif deleted file mode 100644 index f0e4c1a0..00000000 Binary files a/test/api/mock/berries.jfif and /dev/null differ diff --git a/test/api/mock/branch.js b/test/api/mock/branch.js deleted file mode 100644 index 6c2187ae..00000000 --- a/test/api/mock/branch.js +++ /dev/null @@ -1,14 +0,0 @@ -const branch = { - uid: 'main', - source: 'master' -} - -const devBranch = { - uid: 'merge_test', - source: 'staging' -} - -export { - branch, - devBranch -} diff --git a/test/api/mock/content-type.js b/test/api/mock/content-type.js deleted file mode 100644 index 2e4a7713..00000000 --- a/test/api/mock/content-type.js +++ /dev/null @@ -1,179 +0,0 @@ -const singlepageCT = { - content_type: - { - options: - { - is_page: true, - singleton: true, - title: 'title', - sub_title: [] - }, - title: 'Single Page', - uid: 'single_page', - schema: [ - { - display_name: 'Title', - uid: 'title', - data_type: 'text', - mandatory: true, - unique: true, - field_metadata: - { - _default: true - } - }, - { - display_name: 'URL', - uid: 'url', - data_type: 'text', - mandatory: true, - field_metadata: { - _default: true, - instruction: '' - } - } - ] - }, - prevcreate: true -} - -const multiPageCT = { - content_type: - { - options: - { - is_page: true, - singleton: false, - title: 'title', - sub_title: [], - url_pattern: '/:title' - }, - title: 'Multi page', - uid: 'multi_page', - schema: - [ - { - display_name: 'Title', - uid: 'title', - data_type: 'text', - mandatory: true, - unique: true, - field_metadata: - { - _default: true - } - }, - { - display_name: 'URL', - uid: 'url', - data_type: 'text', - mandatory: false, - field_metadata: - { - _default: true - } - } - ] - }, - prevcreate: true -} - -const schema = [ - { - display_name: 'Title', - uid: 'title', - data_type: 'text', - mandatory: true, - unique: true, - field_metadata: - { - _default: true, - version: 3 - }, - non_localizable: false, - multiple: false, - fldUid: 'title' - }, - { - display_name: 'URL', - uid: 'url', - data_type: 'text', - mandatory: true, - field_metadata: - { - _default: true, - version: 3 - }, - non_localizable: false, - multiple: false, - unique: false, - fldUid: 'url' - }, - { - data_type: 'text', - display_name: 'Single line textbox', - abstract: 'Name, title, email address, any short text', - uid: 'single_line', - field_metadata: - { - description: '', - default_value: '' - }, - class: 'high-lighter', - format: '', - error_messages: { format: '' }, - fldUid: 'single_line' - }, - { - data_type: 'text', - display_name: 'Multi line textbox', - abstract: 'Descriptions, paragraphs, long text', - uid: 'multi_line', - field_metadata: - { - description: '', - default_value: '', - multiline: true - }, - class: 'high-lighter', - format: '', - error_messages: - { - format: '' - }, - fldUid: 'multi_line' - }, - { - data_type: 'text', - display_name: 'Markdown', - abstract: 'Input text in markdown language', - uid: 'markdown', - field_metadata: - { - description: '', - markdown: true - }, - class: 'high-lighter', - fldUid: 'markdown' - }, - { - data_type: 'blocks', - display_name: 'Modular Blocks', - abstract: 'Create content dynamically', - blocks: - [ - { - title: 'Block1', - uid: 'block1', - blockType: 'custom', - autoEdit: true, - schema: - [ - { data_type: 'file', display_name: 'File', abstract: 'Upload images, videos, docs, etc.', uid: 'file', icon_class: 'icon-file-text-alt', class: 'high-lighter', size: { min: '', max: '' }, extensions: '', field_metadata: { description: '', rich_text_type: 'standard' }, fldUid: 'modular_blocks > block1 > file' }, { data_type: 'link', display_name: 'Link', abstract: 'Add links to text', uid: 'link', icon_class: 'icon-link', class: 'high-lighter', field_metadata: { description: '', default_value: { title: '', url: '' } }, fldUid: 'modular_blocks > block1 > link' }] }], - multiple: true, - uid: 'modular_blocks', - field_metadata: {}, - class: 'high-lighter', - fldUid: 'modular_blocks' }] - -export { singlepageCT, multiPageCT, schema } diff --git a/test/api/mock/contentType.json b/test/api/mock/contentType.json deleted file mode 100644 index df456dd6..00000000 --- a/test/api/mock/contentType.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "options": - { - "is_page": true, - "singleton": false, - "title": "title", - "sub_title": [], - "url_pattern": "/:title" - }, - "title": "Multi page from JSON", - "uid": "multi_page_from_json", - "schema": - [ - { - "display_name": "Title", - "uid": "title", - "data_type": "text", - "mandatory": true, - "unique": true, - "field_metadata": - { - "_default": true - } - }, - { - "display_name": "URL", - "uid": "url", - "data_type": "text", - "mandatory": false, - "field_metadata": - { - "_default": true - } - } - ] - } \ No newline at end of file diff --git a/test/api/mock/customUpload.html b/test/api/mock/customUpload.html deleted file mode 100644 index cfeb9844..00000000 --- a/test/api/mock/customUpload.html +++ /dev/null @@ -1,28 +0,0 @@ - -
- - - - - - - - - \ No newline at end of file diff --git a/test/api/mock/deliveryToken.js b/test/api/mock/deliveryToken.js deleted file mode 100644 index dfea15e6..00000000 --- a/test/api/mock/deliveryToken.js +++ /dev/null @@ -1,28 +0,0 @@ -const createDeliveryToken = { - token: { - name: 'Test', - description: 'This is a demo token.', - scope: [{ - module: 'environment', - environments: ['development'], - acl: { - read: true - } - }] - } -} -const createDeliveryToken2 = { - token: { - name: 'Test production token', - description: 'This is a demo token.', - scope: [{ - module: 'environment', - environments: ['production'], - acl: { - read: true - } - }] - } -} - -export { createDeliveryToken, createDeliveryToken2 } diff --git a/test/api/mock/entry.js b/test/api/mock/entry.js deleted file mode 100644 index 16249e58..00000000 --- a/test/api/mock/entry.js +++ /dev/null @@ -1,7 +0,0 @@ -const entryFirst = { title: 'First page', url: '', single_line: 'First Single Line', multi_line: 'First Multi line', markdown: 'Mark Down list\n 1. List item\n 2. List item 2', modular_blocks: [], tags: [] } - -const entrySecond = { title: 'Second page', url: '', single_line: 'Second Single Line', multi_line: 'Second Multi line', markdown: 'Mark Down list\n 1. List item\n 2. List item 2', modular_blocks: [], tags: ['second'] } - -const entryThird = { title: 'Third page', url: '', single_line: 'Third Single Line', multi_line: 'Third Multi line', markdown: 'Mark Down list\n 1. List item\n 2. List item 2', modular_blocks: [], tags: ['third'] } - -export { entryFirst, entrySecond, entryThird } diff --git a/test/api/mock/entry.json b/test/api/mock/entry.json deleted file mode 100644 index 60515666..00000000 --- a/test/api/mock/entry.json +++ /dev/null @@ -1 +0,0 @@ -{ "title": "First page json", "url": "", "single_line": "First Single Line", "multi_line": "First Multi line", "markdown": "Mark Down list\n 1. List item\n 2. List item 2", "modular_blocks": [], "tags": [] } \ No newline at end of file diff --git a/test/api/mock/environment.js b/test/api/mock/environment.js deleted file mode 100644 index bab8c786..00000000 --- a/test/api/mock/environment.js +++ /dev/null @@ -1,32 +0,0 @@ -const environmentCreate = { - environment: { - name: 'development', - servers: [ - { - name: 'default' - } - ], - urls: [ - { - locale: 'en-us', - url: 'http://example.com/' - } - ], - deploy_content: true - } -} -const environmentProdCreate = { - environment: { - name: 'production', - servers: [], - urls: [ - { - locale: 'en-us', - url: 'http://example.com/' - } - ], - deploy_content: true - } -} - -export { environmentCreate, environmentProdCreate } diff --git a/test/api/mock/extension.js b/test/api/mock/extension.js deleted file mode 100644 index 536bbc4a..00000000 --- a/test/api/mock/extension.js +++ /dev/null @@ -1,91 +0,0 @@ -const customFieldURL = { - extension: { - tags: [ - 'tag1', - 'tag2' - ], - data_type: 'text', - title: 'New Custom Field URL', - src: 'https://www.sample.com', - multiple: false, - config: '{}', - type: 'field' - } -} -const customFieldSRC = { - extension: { - tags: [ - 'tag1', - 'tag2' - ], - data_type: 'text', - title: 'New Custom Field source code', - srcdoc: 'Source code of the extension', - multiple: false, - config: '{}', - type: 'field' - } -} - -const customWidgetURL = { - extension: { - tags: [ - 'tag1', - 'tag2' - ], - data_type: 'text', - title: 'New Widget URL', - src: 'https://www.sample.com', - config: '{}', - type: 'widget', - scope: { - content_types: ['single_page'] - } - } -} - -const customWidgetSRC = { - extension: { - tags: [ - 'tag1', - 'tag2' - ], - title: 'New Widget SRC', - srcdoc: 'Source code of the widget', - config: '{}', - type: 'widget', - scope: { - content_types: ['$all'] - } - } -} - -const customDashboardURL = { - extension: { - tags: [ - 'tag' - ], - title: 'New Dashboard Widget URL', - src: 'https://www.sample.com', - config: '{}', - type: 'dashboard', - enable: true, - default_width: 'half' - } -} - -const customDashboardSRC = { - extension: { - tags: [ - 'tag1', - 'tag2' - ], - type: 'dashboard', - title: 'New Dashboard Widget SRC', - srcdoc: 'xyz', - config: '{}', - enable: true, - default_width: 'half' - } -} -export { customFieldURL, customFieldSRC, customWidgetURL, customWidgetSRC, customDashboardURL, customDashboardSRC } diff --git a/test/api/mock/globalfield.js b/test/api/mock/globalfield.js deleted file mode 100644 index 22f07718..00000000 --- a/test/api/mock/globalfield.js +++ /dev/null @@ -1,28 +0,0 @@ -const createGlobalField = { - global_field: { - title: 'First', - uid: 'first', - schema: [{ - display_name: 'Name', - uid: 'name', - data_type: 'text' - }, { - data_type: 'text', - display_name: 'Rich text editor', - uid: 'description', - field_metadata: { - allow_rich_text: true, - description: '', - multiline: false, - rich_text_type: 'advanced', - options: [], - version: 3 - }, - multiple: false, - mandatory: false, - unique: false - }] - } -} - -export { createGlobalField } diff --git a/test/api/mock/globalfield.json b/test/api/mock/globalfield.json deleted file mode 100644 index 56b6de61..00000000 --- a/test/api/mock/globalfield.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "title": "Upload", - "uid": "upload", - "schema": [ - { - "display_name": "Name", - "uid": "name", - "data_type": "text", - "multiple": false, - "mandatory": false, - "unique": false, - "non_localizable": false - }, - { - "display_name": "Add", - "uid": "add", - "data_type": "text", - "multiple": false, - "mandatory": false, - "unique": false, - "non_localizable": false - }, - { - "display_name": "std", - "uid": "std", - "data_type": "text", - "multiple": false, - "mandatory": false, - "unique": false, - "non_localizable": false - } - ], - "description": "" - } \ No newline at end of file diff --git a/test/api/mock/managementToken.js b/test/api/mock/managementToken.js deleted file mode 100644 index bf399d6f..00000000 --- a/test/api/mock/managementToken.js +++ /dev/null @@ -1,72 +0,0 @@ -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 - } -} -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 - } -} - -export { createManagementToken, createManagementToken2 } diff --git a/test/api/mock/release.js b/test/api/mock/release.js deleted file mode 100644 index 9bb45e77..00000000 --- a/test/api/mock/release.js +++ /dev/null @@ -1,10 +0,0 @@ -const releaseCreate = { - release: { - name: 'First release', - description: 'Adding release date 2020-21-07', - locked: false, - archived: false - } -} - -export { releaseCreate } diff --git a/test/api/mock/role.js b/test/api/mock/role.js deleted file mode 100644 index c0d299df..00000000 --- a/test/api/mock/role.js +++ /dev/null @@ -1,53 +0,0 @@ -const role = { - role: - { - name: 'test', - description: 'Test from CMA Js', - rules: - [ - { - module: 'environment', - environments: [], - acl: { read: true } - }, - { - module: 'locale', - locales: [], - acl: { read: true } - }, - { - module: 'taxonomy', - taxonomies: ['taxonomy_testing1'], - terms: ['taxonomy_testing1.term_test1'], - content_types: [ - { - uid: '$all', - acl: { - read: true, - sub_acl: { - read: true, - create: true, - update: true, - delete: true, - publish: true - } - } - } - ], - acl: { - read: true, - sub_acl: { - read: true, - create: true, - update: true, - delete: true, - publish: true - } - } - } - ], - uid: 'role_uid' - } -} - -export default role diff --git a/test/api/mock/taxonomy.json b/test/api/mock/taxonomy.json deleted file mode 100644 index 51df5308..00000000 --- a/test/api/mock/taxonomy.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "taxonomy": { - "uid": "UID", - "name": "name", - "description": "test" - }, - "terms": [] -} \ No newline at end of file diff --git a/test/api/mock/upload.html b/test/api/mock/upload.html deleted file mode 100644 index cfeb9844..00000000 --- a/test/api/mock/upload.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/test/api/mock/variantGroup.js b/test/api/mock/variantGroup.js deleted file mode 100644 index 8081e4a5..00000000 --- a/test/api/mock/variantGroup.js +++ /dev/null @@ -1,82 +0,0 @@ -const createVariantGroup = { - 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' -} -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 -} - -export { createVariantGroup, createVariantGroup1, createVariantGroup2 } diff --git a/test/api/mock/variants.js b/test/api/mock/variants.js deleted file mode 100644 index 178c7cc3..00000000 --- a/test/api/mock/variants.js +++ /dev/null @@ -1,50 +0,0 @@ -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' - } -} - -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' -} -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 -} - -export { variant, variant1, variant2 } diff --git a/test/api/mock/webhook.js b/test/api/mock/webhook.js deleted file mode 100644 index 86af1eb4..00000000 --- a/test/api/mock/webhook.js +++ /dev/null @@ -1,40 +0,0 @@ -const webhook = { - webhook: { - name: 'Test', - destinations: [{ - target_url: 'http://example.com', - http_basic_auth: 'basic', - http_basic_password: 'test', - custom_header: [{ - header_name: 'Custom', - value: 'testing' - }] - }], - channels: [ - 'assets.create' - ], - retry_policy: 'manual', - disabled: false - } -} - -const updateWebhook = { - webhook: { - name: 'Updated webhook', - destinations: [{ - target_url: 'http://example.com', - http_basic_auth: 'basic', - http_basic_password: 'test', - custom_header: [{ - header_name: 'Custom', - value: 'testing' - }] - }], - channels: [ - 'assets.create' - ], - retry_policy: 'manual', - disabled: true - } -} -export { webhook, updateWebhook } diff --git a/test/api/mock/webhook.json b/test/api/mock/webhook.json deleted file mode 100644 index 5667abc9..00000000 --- a/test/api/mock/webhook.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "Upload webhook", - "destinations": [{ - "target_url": "http://example.com", - "http_basic_auth": "basic", - "http_basic_password": "test", - "custom_header": [{ - "header_name": "Custom", - "value": "testing" - }] - }], - "channels": [ - "assets.create" - ], - "retry_policy": "manual", - "disabled": "true" -} \ No newline at end of file diff --git a/test/api/mock/workflow.js b/test/api/mock/workflow.js deleted file mode 100644 index 198cacbd..00000000 --- a/test/api/mock/workflow.js +++ /dev/null @@ -1,8 +0,0 @@ -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'] } } - -export { firstWorkflow, secondWorkflow, finalWorkflow, firstPublishRules, secondPublishRules } diff --git a/test/api/organization-test.js b/test/api/organization-test.js deleted file mode 100644 index d6d7bba2..00000000 --- a/test/api/organization-test.js +++ /dev/null @@ -1,108 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var user = {} -var client = {} -var organization = {} - -describe('Organization api test', () => { - setup(() => { - user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - }) - - it('Fetch all organizations', done => { - client.organization().fetchAll() - .then((response) => { - for (const index in response.items) { - const organizations = response.items[index] - expect(organizations.name).to.not.equal(null, 'Organization name cannot be null') - expect(organizations.uid).to.not.equal(null, 'Organization uid cannot be null') - } - done() - }) - .catch(done) - }) - - it('Get Current user info test', done => { - client.getUser({ include_orgs: true, include_orgs_roles: true, include_stack_roles: true, include_user_settings: true }).then((user) => { - 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 - } - } - done() - }) - .catch(done) - }) - - it('Fetch organization', done => { - client.organization(organization).fetch() - .then((organizations) => { - expect(organizations.name).to.be.equal('SDK org', 'Organization name dose not match') - done() - }) - .catch(done) - }) - - it('Get all stacks in an Organization', done => { - client.organization(organization).stacks() - .then((response) => { - for (const index in response.items) { - const stack = response.items[index] - expect(stack.name).to.not.equal(null, 'Organization name cannot be null') - expect(stack.uid).to.not.equal(null, 'Organization uid cannot be null') - } - done() - }) - .catch(done) - }) - // need to test with transfer ownership - // it('Transfer Organization Ownership', done => { - // organization.transferOwnership('em@em.com') - // .then((data) => { - // expect(data.notice).to.be.equal('Email has been successfully sent to the user.', 'Message does not match') - // done() - // }) - // .catch((error) => { - // console.log(error) - // expect(error).to.be.equal(null, 'Failed Transfer Organization Ownership') - // done() - // }) - // }) - - it('Get all roles in an organization', done => { - organization.roles() - .then((roles) => { - for (const i in roles.items) { - expect(roles.items[i].uid).to.not.equal(null, 'Role uid cannot be null') - expect(roles.items[i].name).to.not.equal(null, 'Role name cannot be null') - expect(roles.items[i].org_uid).to.be.equal(organization.uid, 'Role org_uid not match') - } - done() - }) - .catch(done) - }) - - it('Get all invitations in an organization', done => { - organization.getInvitations({ include_count: true }) - .then((response) => { - expect(response.count).to.not.equal(null, 'Failed Transfer Organization Ownership') - for (const i in response.items) { - expect(response.items[i].uid).to.not.equal(null, 'User uid cannot be null') - expect(response.items[i].email).to.not.equal(null, 'User name cannot be null') - expect(response.items[i].user_uid).to.not.equal(null, 'User name cannot be null') - expect(response.items[i].org_uid).to.not.equal(null, 'User name cannot be null') - } - done() - }) - .catch(done) - }) - - // addUser - // Resend invitation -}) diff --git a/test/api/release-test.js b/test/api/release-test.js deleted file mode 100644 index ccdb3fa8..00000000 --- a/test/api/release-test.js +++ /dev/null @@ -1,226 +0,0 @@ -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { releaseCreate } from './mock/release.js' -import { expect } from 'chai' -import { cloneDeep } from 'lodash' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { multiPageCT } from './mock/content-type' - -var client = {} -var stack = {} -var releaseUID = '' -let entries = {} -const itemToDelete = {} -describe('Relases api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - entries = jsonReader('entry.json') - client = contentstackClient(user.authtoken) - }) - - it('Create a Release', done => { - makeRelease() - .create(releaseCreate) - .then((release) => { - 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() - }) - .catch(done) - }) - - it('Fetch a Release from Uid', done => { - makeRelease(releaseUID) - .fetch() - .then((release) => { - 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() - }) - .catch(done) - }) - - it('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' - } - makeRelease(releaseUID) - .item() - .create({ item }) - .then((release) => { - 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() - }) - .catch(done) - }) - - it('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' - }, - { - version: entries[2]._version, - uid: entries[2].uid, - content_type_uid: multiPageCT.content_type.uid, - action: 'publish', - locale: 'en-us' - } - ] - makeRelease(releaseUID) - .item() - .create({ items }) - .then((release) => { - 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() - }) - .catch(done) - }) - - it('Fetch a Release items from Uid', done => { - makeRelease(releaseUID) - .item() - .findAll() - .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() - }) - .catch(done) - }) - - it('Delete specific item', done => { - makeRelease(releaseUID) - .item() - .delete({ items: [itemToDelete] }) - .then((release) => { - 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(2) - done() - }) - .catch(done) - }) - - it('Delete all items', done => { - makeRelease(releaseUID) - .item() - .delete() - .then((release) => { - 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(0) - done() - }) - .catch(done) - }) - - it('Fetch and Update a Release from Uid', done => { - makeRelease(releaseUID) - .fetch() - .then((release) => { - release.name = 'Update release name' - return release.update() - }) - .then((release) => { - 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() - }) - .catch(done) - }) - - it('Update a Release from Uid', done => { - var relaseObject = makeRelease(releaseUID) - Object.assign(relaseObject, cloneDeep(releaseCreate.release)) - relaseObject - .update() - .then((release) => { - 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() - }) - .catch(done) - }) - - it('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() - }) - .catch(done) - }) - - it('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() - }) - .catch(done) - }) - - it('Clone specific Releases with Uid ', done => { - makeRelease(releaseUID) - .clone({ name: 'New Clone Name', description: 'New Desc' }) - .then((release) => { - 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) - }) - - it('Delete specific Releases with Uid ', done => { - makeRelease(releaseUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Release deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeRelease (uid = null) { - return client.stack({ api_key: stack.api_key }).release(uid) -} diff --git a/test/api/role-test.js b/test/api/role-test.js deleted file mode 100644 index a5e37e5c..00000000 --- a/test/api/role-test.js +++ /dev/null @@ -1,139 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import role from './mock/role' -import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -var stack = {} -var client = {} -var roleUID = '' - -describe('Role api test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Get all role in stack', done => { - getRole() - .fetchAll() - .then((roles) => { - jsonWrite(roles.items, 'roles.json') - for (const index in roles.items) { - const role1 = roles.items[index] - expect(role1.uid).to.not.equal(null, 'Role uid cannot be null') - } - done() - }) - .catch(done) - }) - - it('Get 1 role in stack with limit', done => { - getRole() - .fetchAll({ limit: 1 }) - .then((roles) => { - expect(roles.items.length).to.not.equal(1, 'Role fetch with limit 1 not work') - done() - }) - .catch(done) - }) - - it('Get 2 role in stack with skip first', done => { - getRole() - .fetchAll({ skip: 1 }) - .then((roles) => { - expect(roles.items.lenth).to.not.equal(1, 'Role fetch with limit 1 not work') - done() - }) - .catch(done) - }) - - it('Create new role in stack', done => { - getRole() - .create(role) - .then((roles) => { - roleUID = roles.uid - expect(roles.name).to.be.equal(role.role.name, 'Role name not match') - expect(roles.description).to.be.equal(role.role.description, 'Role description not match') - expect(roles.rules.length).to.be.equal(3, 'Role rule length not match') - done() - }) - .catch(done) - }) - - it('Get role in stack', done => { - getRole(roleUID) - .fetch() - .then((roles) => { - jsonWrite(roles, 'role.json') - expect(roles.name).to.be.equal(role.role.name, 'Role name not match') - expect(roles.description).to.be.equal(role.role.description, 'Role description not match') - expect(roles.stack.api_key).to.be.equal(stack.api_key, 'Role stack uid not match') - done() - }) - .catch(done) - }) - - it('Update role in stack', done => { - getRole(roleUID) - .fetch({ include_rules: true, include_permissions: true }) - .then((roles) => { - roles.name = 'Update test name' - roles.description = 'Update description' - return roles.update() - }) - .then((roles) => { - expect(roles.name).to.be.equal('Update test name', 'Role name not match') - expect(roles.description).to.be.equal('Update description', 'Role description not match') - done() - }) - .catch(done) - }) - - it('Get all Roles with query', done => { - getRole() - .query() - .find() - .then((response) => { - for (const index in response.items) { - const role = response.items[index] - expect(role.name).to.not.equal(null) - expect(role.uid).to.not.equal(null) - } - done() - }) - .catch(done) - }) - - it('Get query Role', done => { - getRole() - .query({ query: { name: 'Developer' } }) - .find() - .then((response) => { - for (const index in response.items) { - const stack = response.items[index] - expect(stack.name).to.be.equal('Developer') - } - done() - }) - .catch(done) - }) - - it('Find one role', done => { - getRole() - .query({ name: 'Developer' }) - .findOne() - .then((response) => { - const stack = response.items[0] - expect(response.items.length).to.be.equal(1) - expect(stack.name).to.be.not.equal(null) - done() - }) - .catch(done) - }) -}) - -// Helper -function getRole (uid = null) { - return client.stack({ api_key: stack.api_key }).role(uid) -} diff --git a/test/api/stack-share.js b/test/api/stack-share.js deleted file mode 100644 index a61d5cad..00000000 --- a/test/api/stack-share.js +++ /dev/null @@ -1,34 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -var stack = {} -var client = {} - -describe('Stack Share/Unshare', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - it('Share stack test', done => { - const role = jsonReader('role.json') - client.stack({ api_key: stack.api_key }) - .share(['test@test.com'], { 'test@test.com': [role.uid] }) - .then((response) => { - expect(response.notice).to.be.equal('The invitation has been sent successfully.') - done() - }) - .catch(done) - }) - - it('unshare stack test', done => { - client.stack({ api_key: stack.api_key }) - .unShare('test@test.com') - .then((response) => { - expect(response.notice).to.be.equal('The stack has been successfully unshared.') - done() - }) - .catch(done) - }) -}) diff --git a/test/api/stack-test.js b/test/api/stack-test.js deleted file mode 100644 index 07e3701e..00000000 --- a/test/api/stack-test.js +++ /dev/null @@ -1,158 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite' -import dotenv from 'dotenv' -import { contentstackClient } from '../utility/ContentstackClient.js' -dotenv.config() - -var orgID = process.env.ORGANIZATION -var user = {} -var client = {} - -var stacks = {} -describe('Stack api Test', () => { - setup(() => { - user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - }) - const newStack = { - stack: - { - name: 'My New Stack', - description: 'My new test stack', - master_locale: 'en-us' - } - } - - it('Create Stack', done => { - client.stack() - .create(newStack, { organization_uid: orgID }) - .then((stack) => { - jsonWrite(stack, 'stack.json') - expect(stack.org_uid).to.be.equal(orgID) - expect(stack.api_key).to.not.equal(null) - expect(stack.name).to.be.equal(newStack.stack.name) - expect(stack.description).to.be.equal(newStack.stack.description) - done() - stacks = jsonReader('stack.json') - }) - .catch(done) - }) - - it('Fetch Stack details', done => { - client.stack({ api_key: stacks.api_key }) - .fetch() - .then((stack) => { - expect(stack.org_uid).to.be.equal(orgID) - expect(stack.api_key).to.not.equal(null) - expect(stack.name).to.be.equal(newStack.stack.name) - expect(stack.description).to.be.equal(newStack.stack.description) - done() - }) - .catch(done) - }) - - it('Update Stack details', done => { - const name = 'My New Stack Update Name' - const description = 'My New description stack' - client.stack({ api_key: stacks.api_key }) - .fetch().then((stack) => { - stack.name = name - stack.description = description - return stack.update() - }).then((stack) => { - expect(stack.name).to.be.equal(name) - expect(stack.description).to.be.equal(description) - done() - }) - .catch(done) - }) - - it('Get all users of stack', done => { - client.stack({ api_key: stacks.api_key }) - .users() - .then((response) => { - expect(response[0].uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get stack settings', done => { - client.stack({ api_key: stacks.api_key }) - .settings() - .then((response) => { - expect(response.stack_variable).to.be.equal(undefined, 'Stack variable must be blank') - expect(response.discrete_variables.access_token).to.not.equal(null, 'Stack variable must not be blank') - expect(response.discrete_variables.secret_key).to.not.equal(null, 'Stack variable must not be blank') - done() - }) - .catch(done) - }) - - it('Add stack settings', done => { - client.stack({ api_key: stacks.api_key }) - .addSettings({ samplevariable: 'too' }) - .then((response) => { - expect(response.stack_variables.samplevariable).to.be.equal('too', 'samplevariable must set to \'too\' ') - done() - }) - .catch(done) - }) - - it('Reset stack settings', done => { - client.stack({ api_key: stacks.api_key }) - .resetSettings() - .then((response) => { - expect(response.stack_variable).to.be.equal(undefined, 'Stack variable must be blank') - expect(response.discrete_variables.access_token).to.not.equal(null, 'Stack variable must not be blank') - expect(response.discrete_variables.secret_key).to.not.equal(null, 'Stack variable must not be blank') - done() - }) - .catch(done) - }) - - it('Get all stack', done => { - client.stack() - .query() - .find() - .then((response) => { - for (const index in response.items) { - const stack = response.items[index] - expect(stack.name).to.not.equal(null) - expect(stack.uid).to.not.equal(null) - expect(stack.owner_uid).to.not.equal(null) - } - done() - }) - .catch(done) - }) - - it('Get query stack', done => { - client.stack() - .query({ query: { name: 'My New Stack Update Name' } }) - .find() - .then((response) => { - expect(response.items.length).to.be.equal(1) - for (const index in response.items) { - const stack = response.items[index] - expect(stack.name).to.be.equal('My New Stack Update Name') - } - done() - }) - .catch(done) - }) - - it('Find one stack', done => { - client.stack() - .query({ query: { name: 'My New Stack Update Name' } }) - .findOne() - .then((response) => { - const stack = response.items[0] - expect(response.items.length).to.be.equal(1) - expect(stack.name).to.be.equal('My New Stack Update Name') - done() - }) - .catch(done) - }) -}) diff --git a/test/api/taxonomy-test.js b/test/api/taxonomy-test.js deleted file mode 100644 index 86bbe597..00000000 --- a/test/api/taxonomy-test.js +++ /dev/null @@ -1,110 +0,0 @@ -import { expect } from 'chai' -import path from 'path' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} -var stack = {} - -const taxonomy = { - uid: 'taxonomy_testing1', - name: 'taxonomy testing', - description: 'Description for Taxonomy testing' -} - -const importTaxonomy = { taxonomy: path.join(__dirname, './mock/taxonomy.json') } - -var taxonomyUID = '' -var taxonomyDelUID = 'taxonomy_testing' - -describe('taxonomy api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Create taxonomy', done => { - makeTaxonomy() - .create(taxonomy) - .then((taxonomyResponse) => { - expect(taxonomyResponse.name).to.be.equal(taxonomy.name) - done() - }) - .catch(done) - }) - - it('Import taxonomy', done => { - makeTaxonomy() - .import(importTaxonomy) - .then((taxonomyResponse) => { - expect(taxonomyResponse.name).to.be.equal('name') - done() - }) - .catch(done) - }) - - it('Export taxonomy', done => { - makeTaxonomy(taxonomyUID) - .export({}) - .then((taxonomyResponse) => { - expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) - expect(taxonomyResponse.name).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Fetch taxonomy from uid', done => { - makeTaxonomy(taxonomyUID) - .fetch() - .then((taxonomyResponse) => { - expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) - expect(taxonomyResponse.name).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Update taxonomy from uid', done => { - makeTaxonomy(taxonomyUID) - .fetch() - .then((taxonomyResponse) => { - taxonomyResponse.name = 'Updated Name' - return taxonomyResponse.update() - }) - .then((taxonomyResponse) => { - expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) - expect(taxonomyResponse.name).to.be.equal('Updated Name') - done() - }) - .catch(done) - }) - - it('Delete taxonomy from uid', done => { - makeTaxonomy(taxonomyDelUID) - .delete() - .then((taxonomyResponse) => { - expect(taxonomyResponse.notice).to.be.equal('Taxonomy deleted successfully.') - done() - }) - .catch(done) - }) - - it('Query to get all taxonomies', async () => { - makeTaxonomy() - .query() - .find() - .then((response) => { - response.items.forEach((taxonomyResponse) => { - expect(taxonomyResponse.uid).to.be.not.equal(null) - expect(taxonomyResponse.name).to.be.not.equal(null) - }) - }) - }) -}) - -function makeTaxonomy (uid = null) { - return client.stack({ api_key: stack.api_key }).taxonomy(uid) -} diff --git a/test/api/team-stack-role-mapping-test.js b/test/api/team-stack-role-mapping-test.js deleted file mode 100644 index c94bc318..00000000 --- a/test/api/team-stack-role-mapping-test.js +++ /dev/null @@ -1,65 +0,0 @@ -import { describe, it, beforeEach } from 'mocha' -import { expect } from 'chai' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -let client = {} - -const stackApiKey = 'stackApiKey' -const organizationUid = 'organizationUid' -const teamUid = 'teamUid' - -describe('Teams API Test', () => { - beforeEach(() => { - const user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - }) - it('should fetch all stackRoleMappings', done => { - makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => { - expect(response.stackRoleMappings).to.be.not.equal(undefined) - done() - }) - .catch(done) - }) - it('should add roles', done => { - const stackRoleMappings = { - stackApiKey: 'stackApiKey', - roles: [ - 'role_uid' - ] - } - makestackRoleMappings(organizationUid, teamUid).add(stackRoleMappings).then((response) => { - expect(response.stackRoleMapping).not.to.be.equal(undefined) - expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0]) - expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackRoleMappings.stackApiKey) - done() - }) - .catch(done) - }) - it('should update roles', done => { - const stackRoleMappings = { - roles: [ - 'role_uid1', - 'role_uid2' - ] - } - makestackRoleMappings(organizationUid, teamUid, stackApiKey).update(stackRoleMappings).then((response) => { - expect(response.stackRoleMapping).not.to.be.equal(undefined) - expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0]) - expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackApiKey) - done() - }) - .catch(done) - }) - it('should delete roles', done => { - makestackRoleMappings(organizationUid, teamUid, stackApiKey).delete().then((response) => { - expect(response.status).to.be.equal(204) - done() - }) - .catch(done) - }) -}) - -function makestackRoleMappings (organizationUid, teamUid, stackApiKey = null) { - return client.organization(organizationUid).teams(teamUid).stackRoleMappings(stackApiKey) -} diff --git a/test/api/team-test.js b/test/api/team-test.js deleted file mode 100644 index 4cbb6408..00000000 --- a/test/api/team-test.js +++ /dev/null @@ -1,69 +0,0 @@ -import { describe, it, beforeEach } from 'mocha' -import { expect } from 'chai' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -let client = {} - -const organizationUid = 'organizationUid' -const teamUid = 'teamUid' -const deleteUid = 'deleteUid' - -describe('Teams API Test', () => { - beforeEach(() => { - const user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - }) - it('should get all the teams when correct organization uid is passed', async () => { - const response = await makeTeams(organizationUid).fetchAll() - expect(response.items[0].organizationUid).to.be.equal(organizationUid) - expect(response.items[0].name).not.to.be.equal(null) - expect(response.items[0].created_by).not.to.be.equal(null) - expect(response.items[0].updated_by).not.to.be.equal(null) - }) - it('should fetch the team when correct organization uid and team uid is passed', async () => { - const response = await makeTeams(organizationUid, teamUid).fetch() - expect(response.uid).to.be.equal(teamUid) - expect(response.organizationUid).to.be.equal(organizationUid) - 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) - }) - it('should create new team when required object is passed', async () => { - const response = await makeTeams(organizationUid).create({ - name: 'test_team', - users: [], - stackRoleMapping: [], - organizationRole: 'organizationRole' }) - expect(response.uid).not.to.be.equal(null) - expect(response.name).not.to.be.equal(null) - expect(response.stackRoleMapping).not.to.be.equal(null) - expect(response.organizationRole).not.to.be.equal(null) - }) - it('should delete team when correct organization uid and team uid is passed', async () => { - const response = await makeTeams(organizationUid, deleteUid).delete() - expect(response.status).to.be.equal(204) - }) - it('should update team when updating data is passed', async () => { - const updateData = { - name: 'name', - users: [ - { - email: 'abc@abc.com' - } - ], - organizationRole: '', - stackRoleMapping: [] - } - await makeTeams(organizationUid, teamUid).update(updateData) - .then((team) => { - expect(team.name).to.be.equal(updateData.name) - expect(team.createdByUserName).not.to.be.equal(undefined) - expect(team.updatedByUserName).not.to.be.equal(undefined) - }) - }) -}) - -function makeTeams (organizationUid, teamUid = null) { - return client.organization(organizationUid).teams(teamUid) -} diff --git a/test/api/team-users-test.js b/test/api/team-users-test.js deleted file mode 100644 index 30c5d41d..00000000 --- a/test/api/team-users-test.js +++ /dev/null @@ -1,47 +0,0 @@ -import { describe, it, beforeEach } from 'mocha' -import { expect } from 'chai' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -let client = {} - -const organizationUid = 'organizationUid' -const teamUid = 'teamUid' -const userId = 'userId' - -describe('Teams Users API Test', () => { - beforeEach(() => { - const user = jsonReader('loggedinuser.json') - client = contentstackClient(user.authtoken) - }) - it('should add the user when user\'s mail is passed', done => { - const usersMail = { - emails: ['email@email.com'] - } - makeUsers(organizationUid, teamUid).add(usersMail).then((response) => { - expect(response.status).to.be.equal(201) - done() - }) - .catch(done) - }) - it('should remove the user when uid is passed', done => { - makeUsers(organizationUid, teamUid, userId).remove().then((response) => { - expect(response.status).to.be.equal(204) - done() - }) - .catch(done) - }) - it('should fetch all users', async () => { - makeUsers(organizationUid, teamUid) - .fetchAll() - .then((response) => { - response.items.forEach((user) => { - expect(user.uidId).to.be.not.equal(null) - }) - }) - }) -}) - -function makeUsers (organizationUid, teamUid, userId = null) { - return client.organization(organizationUid).teams(teamUid).teamUsers(userId) -} diff --git a/test/api/terms-test.js b/test/api/terms-test.js deleted file mode 100644 index 79aab144..00000000 --- a/test/api/terms-test.js +++ /dev/null @@ -1,137 +0,0 @@ -import { describe, it, beforeEach } from 'mocha' -import { expect } from 'chai' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} -var stack = {} - -const taxonomyUid = '' -const termUid = '' -const term = { - term: { - uid: 'term_test', - name: 'Term test' - }, - parent_uid: null -} - -describe('Terms API Test', () => { - beforeEach(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Create term', async () => { - try { - 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) { - console.log(err) - } - }) - - it('Query and get all terms', async () => { - try { - 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) - } catch (err) { - console.log(err) - } - }) - - it('Fetch term from UID', async () => { - try { - 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) - } catch (err) { - console.log(err) - } - }) - - it('Update term', async () => { - try { - 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(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) - } catch (err) { - console.log(err) - } - }) - - it('Delete term from UID', async () => { - try { - const response = await makeTerms(termUid).delete() - expect(response.notice).to.be.equal('') - } catch (err) { - console.log(err) - } - }) - - it('Ancestors of the term given', async () => { - try { - 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) - expect(response.terms[0].updated_by).not.to.be.equal(null) - } catch (err) { - console.log(err) - } - }) - - it('Descendants of the term given', async () => { - try { - 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) - expect(response.terms.updated_by).not.to.be.equal(null) - } catch (err) { - console.log(err) - } - }) - it('search term', async () => { - const termString = '' - try { - const response = await makeTerms(taxonomyUid).search(termString) - expect(response.terms).to.be.an('array') - } catch (err) { - console.log(err) - } - }) - it('move term', async () => { - try { - const term = { - parent_uid: 'parent_uid', - order: 2 - } - await makeTerms(taxonomyUid, termUid).move({ term }) - .then((term) => { - term.parent_uid = 'parent_uid' - console.log(term.move()) - return term.move() - }) - } catch (err) { - console.log(err) - } - }) -}) - -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 deleted file mode 100644 index 94b46404..00000000 --- a/test/api/ungroupedVariants-test.js +++ /dev/null @@ -1,106 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -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' - } -} - -var variantsUID = '' -var deleteVariantsUID = '' -describe('Variants api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Variants create', done => { - makeVariants() - .create({ variants }) - .then((variantsResponse) => { - variantsUID = variantsResponse.uid - expect(variantsResponse.uid).to.be.not.equal(null) - expect(variantsResponse.name).to.be.equal(variants.name) - done() - }) - .catch(done) - }) - - it('Fetch variants from uid', done => { - makeVariants(variantsUID) - .fetch() - .then((variantsResponse) => { - expect(variantsResponse.uid).to.be.equal(variantsUID) - expect(variantsResponse.name).to.be.equal(variants.name) - done() - }) - .catch(done) - }) - - it('Query to get all variantss', done => { - makeVariants() - .query({ query: { name: variants.name } }) - .find() - .then((response) => { - response.items.forEach((variantsResponse) => { - expect(variantsResponse.uid).to.be.not.equal(null) - expect(variantsResponse.name).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query variants with name', done => { - makeVariants() - .query({ query: { name: variants.name } }) - .find() - .then((response) => { - response.items.forEach((variantsResponse) => { - expect(variantsResponse.uid).to.be.equal(variantsUID) - expect(variantsResponse.name).to.be.equal(variants.name) - }) - done() - }) - .catch(done) - }) - - it('Fetch By variants UIDs ', done => { - makeVariants() - .fetchByUIDs(['uid1', 'uid2']) - .then((response) => { - response.variants.forEach((variantsResponse) => { - expect(variantsResponse.uid).to.be.equal(variantsUID) - expect(variantsResponse.name).to.be.equal(variants.name) - }) - done() - }) - .catch(done) - }) - - it('Delete variants from uid', done => { - makeVariants(deleteVariantsUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Variants deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeVariants (uid = null) { - return client.stack({ api_key: stack.api_key }).variants(uid) -} diff --git a/test/api/user-test.js b/test/api/user-test.js deleted file mode 100644 index 5d7b9e5e..00000000 --- a/test/api/user-test.js +++ /dev/null @@ -1,77 +0,0 @@ -import { expect } from 'chai' -import { describe, it } from 'mocha' - -import { contentstackClient } from '../utility/ContentstackClient' -import axios from 'axios' -import { jsonWrite } from '../utility/fileOperations/readwrite' -import dotenv from 'dotenv' -dotenv.config() -var authtoken = '' -var loggedinUserID = '' -var client = contentstackClient() -describe('Contentstack User Session api Test', () => { - it('User login wrong credentials', done => { - contentstackClient().login({ email: process.env.EMAIL, password: process.env.PASSWORD }) - .then((response) => { - done() - }).catch((error) => { - const jsonMessage = JSON.parse(error.message) - const payload = JSON.parse(jsonMessage.request.data) - expect(jsonMessage.status).to.be.equal(422, 'Status code does not match') - expect(jsonMessage.errorMessage).to.not.equal(null, 'Error message not proper') - expect(jsonMessage.errorCode).to.be.equal(104, 'Error code does not match') - expect(payload.user.email).to.be.equal(process.env.EMAIL, 'Email id does not match') - expect(payload.user.password).to.be.equal('contentstack', 'Password does not match') - done() - }) - }) - - it('User Login test', done => { - client.login({ email: process.env.EMAIL, password: process.env.PASSWORD }, { include_orgs: true, include_orgs_roles: true, include_stack_roles: true, include_user_settings: true }).then((response) => { - jsonWrite(response.user, 'loggedinuser.json') - expect(response.notice).to.be.equal('Login Successful.', 'Login success messsage does not match.') - done() - }) - .catch(done) - }) - - it('User logout test', done => { - client.logout() - .then((response) => { - expect(axios.defaults.headers.common.authtoken).to.be.equal(undefined) - expect(response.notice).to.be.equal('You\'ve logged out successfully.') - done() - }) - .catch(done) - }) - - it('User login with credentials', done => { - client.login({ email: process.env.EMAIL, password: process.env.PASSWORD }, { include_orgs: true, include_orgs_roles: true, include_stack_roles: true, include_user_settings: true }).then((response) => { - loggedinUserID = response.user.uid - jsonWrite(response.user, 'loggedinuser.json') - expect(response.notice).to.be.equal('Login Successful.', 'Login success messsage does not match.') - done() - }) - .catch(done) - }) - - it('Get Current user info test', done => { - client.getUser().then((user) => { - authtoken = user.authtoken - expect(user.uid).to.be.equal(loggedinUserID) - done() - }) - .catch(done) - }) - - it('Get user info from authtoken', done => { - contentstackClient(authtoken) - .getUser() - .then((user) => { - expect(user.uid).to.be.equal(loggedinUserID) - expect(true).to.be.equal(true) - done() - }) - .catch(done) - }) -}) diff --git a/test/api/variantGroup-test.js b/test/api/variantGroup-test.js deleted file mode 100644 index 695953f9..00000000 --- a/test/api/variantGroup-test.js +++ /dev/null @@ -1,136 +0,0 @@ -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 { 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) - }) - - it('Add a Variant Group', done => { - makeVariantGroup() - .create(createVariantGroup) - .then((variantGroup) => { - expect(variantGroup.name).to.be.equal(createVariantGroup.name) - expect(variantGroup.description).to.be.equal(createVariantGroup.description) - expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup.scope[0].module) - expect(variantGroup.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Add a Variant Group for production', done => { - makeVariantGroup() - .create(createVariantGroup2) - .then((variantGroup) => { - tokenUID = variantGroup.uid - expect(variantGroup.name).to.be.equal(createVariantGroup2.name) - expect(variantGroup.description).to.be.equal(createVariantGroup2.description) - expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup2.scope[0].module) - expect(variantGroup.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get a Variant Group from uid', done => { - makeVariantGroup(tokenUID) - .fetch() - .then((variantGroup) => { - expect(variantGroup.name).to.be.equal(createVariantGroup1.name) - expect(variantGroup.description).to.be.equal(createVariantGroup1.description) - expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup1.scope[0].module) - expect(variantGroup.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Query to get all Variant Group', done => { - makeVariantGroup() - .query() - .find() - .then((tokens) => { - tokens.items.forEach((variantGroup) => { - expect(variantGroup.name).to.be.not.equal(null) - expect(variantGroup.description).to.be.not.equal(null) - expect(variantGroup.scope[0].module).to.be.not.equal(null) - expect(variantGroup.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query to get a Variant Group from name', done => { - makeVariantGroup() - .query({ query: { name: createVariantGroup.name } }) - .find() - .then((tokens) => { - tokens.items.forEach((variantGroup) => { - expect(variantGroup.name).to.be.equal(createVariantGroup.name) - expect(variantGroup.description).to.be.equal(createVariantGroup.description) - expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup.scope[0].module) - expect(variantGroup.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Fetch and update a Variant Group from uid', done => { - makeVariantGroup(tokenUID) - .fetch() - .then((variantGroup) => { - variantGroup.name = 'Update Production Name' - variantGroup.description = 'Update Production description' - variantGroup.scope = createVariantGroup2.scope - return variantGroup.update() - }) - .then((variantGroup) => { - expect(variantGroup.name).to.be.equal('Update Production Name') - expect(variantGroup.description).to.be.equal('Update Production description') - expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup2.scope[0].module) - expect(variantGroup.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Update a Variant Group from uid', done => { - const variantGroup = makeVariantGroup(tokenUID) - Object.assign(variantGroup, createVariantGroup2.variantGroup) - variantGroup.update() - .then((variantGroup) => { - expect(variantGroup.name).to.be.equal(createVariantGroup2.name) - expect(variantGroup.description).to.be.equal(createVariantGroup2.description) - expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup2.scope[0].module) - expect(variantGroup.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Delete a Variant Group from uid', done => { - makeVariantGroup(tokenUID) - .delete() - .then((data) => { - expect(data.notice).to.be.equal('Variant Group deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeVariantGroup (uid = null) { - return client.stack({ api_key: stack.api_key }).variantGroup(uid) -} diff --git a/test/api/variants-test.js b/test/api/variants-test.js deleted file mode 100644 index bebc332d..00000000 --- a/test/api/variants-test.js +++ /dev/null @@ -1,112 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { variant, variant2 } from './mock/variants.js' -import { contentstackClient } from '../utility/ContentstackClient.js' - -var client = {} - -var stack = {} -var tokenUID = '' -describe('Variants api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Add a Variants', done => { - makeVariants() - .create(variant) - .then((variants) => { - expect(variants.name).to.be.equal(variant.name) - expect(variants.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Add a Variants for production', done => { - makeVariants() - .create(variant2) - .then((variants) => { - tokenUID = variants.uid - expect(variants.name).to.be.equal(variant2.name) - expect(variants.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get a Variants from uid', done => { - makeVariants(tokenUID) - .fetch() - .then((variants) => { - expect(variants.name).to.be.equal(variant2.name) - expect(variants.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Query to get all Variants', done => { - makeVariants() - .query() - .find() - .then((tokens) => { - tokens.items.forEach((variants) => { - expect(variants.name).to.be.not.equal(null) - expect(variants.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Query to get a Variants from name', done => { - makeVariants() - .query({ query: { name: variant.name } }) - .find() - .then((tokens) => { - tokens.items.forEach((variants) => { - expect(variants.name).to.be.equal(variant.name) - expect(variants.uid).to.be.not.equal(null) - }) - done() - }) - .catch(done) - }) - - it('Fetch and update a Variants from uid', done => { - makeVariants(tokenUID) - .fetch() - .then((variants) => { - variants.name = 'Update Production Name' - variants.description = 'Update Production description' - variants.scope = variant2.scope - return variants.update() - }) - .then((variants) => { - expect(variants.name).to.be.equal('Update Production Name') - expect(variants.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Update a Variants from uid', done => { - const variants = makeVariants(tokenUID) - Object.assign(variants, variant2.variants) - variants.update() - .then((variants) => { - expect(variants.name).to.be.equal(variant2.name) - expect(variants.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) -}) - -function makeVariants (uid = null) { - return client.stack({ api_key: stack.api_key }).variantGroup('uid').variants(uid) -} diff --git a/test/api/webhook-test.js b/test/api/webhook-test.js deleted file mode 100644 index 9816fdcd..00000000 --- a/test/api/webhook-test.js +++ /dev/null @@ -1,149 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import path from 'path' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { webhook, updateWebhook } from './mock/webhook' -import { cloneDeep } from 'lodash' -import { contentstackClient } from '../utility/ContentstackClient.js' -var client = {} - -var stack = {} -var webhookUid = '' -describe('Webhook api Test', () => { - setup(() => { - const user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - }) - - it('Create Webhook', done => { - makeWebhook() - .create(webhook) - .then((response) => { - webhookUid = response.uid - expect(response.uid).to.be.not.equal(null) - expect(response.name).to.be.equal(webhook.webhook.name) - expect(response.destinations[0].target_url).to.be.equal(webhook.webhook.destinations[0].target_url) - expect(response.destinations[0].http_basic_auth).to.be.equal(webhook.webhook.destinations[0].http_basic_auth) - expect(response.destinations[0].http_basic_password).to.be.equal(webhook.webhook.destinations[0].http_basic_password) - expect(response.channels[0]).to.be.equal(webhook.webhook.channels[0]) - expect(response.retry_policy).to.be.equal(webhook.webhook.retry_policy) - expect(response.disabled).to.be.equal(webhook.webhook.disabled) - done() - }) - .catch(done) - }) - - it('Fetch Webhook', done => { - makeWebhook(webhookUid) - .fetch() - .then((response) => { - expect(response.uid).to.be.equal(webhookUid) - expect(response.name).to.be.equal(webhook.webhook.name) - expect(response.destinations[0].target_url).to.be.equal(webhook.webhook.destinations[0].target_url) - expect(response.destinations[0].http_basic_auth).to.be.equal(webhook.webhook.destinations[0].http_basic_auth) - expect(response.destinations[0].http_basic_password).to.be.equal(webhook.webhook.destinations[0].http_basic_password) - expect(response.channels[0]).to.be.equal(webhook.webhook.channels[0]) - expect(response.retry_policy).to.be.equal(webhook.webhook.retry_policy) - expect(response.disabled).to.be.equal(webhook.webhook.disabled) - done() - }) - .catch(done) - }) - - it('Fetch and update Webhook', done => { - makeWebhook(webhookUid) - .fetch() - .then((webhookRes) => { - Object.assign(webhookRes, cloneDeep(updateWebhook.webhook)) - return webhookRes.update() - }) - .then((response) => { - expect(response.uid).to.be.equal(webhookUid) - expect(response.name).to.be.equal(updateWebhook.webhook.name) - expect(response.destinations[0].target_url).to.be.equal(updateWebhook.webhook.destinations[0].target_url) - expect(response.destinations[0].http_basic_auth).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_auth) - expect(response.destinations[0].http_basic_password).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_password) - expect(response.channels[0]).to.be.equal(updateWebhook.webhook.channels[0]) - expect(response.retry_policy).to.be.equal(updateWebhook.webhook.retry_policy) - expect(response.disabled).to.be.equal(updateWebhook.webhook.disabled) - done() - }) - .catch(done) - }) - - it('Update Webhook', done => { - var webhookObject = makeWebhook(webhookUid) - Object.assign(webhookObject, cloneDeep(updateWebhook.webhook)) - webhookObject.update() - .then((response) => { - expect(response.uid).to.be.equal(webhookUid) - expect(response.name).to.be.equal(updateWebhook.webhook.name) - expect(response.destinations[0].target_url).to.be.equal(updateWebhook.webhook.destinations[0].target_url) - expect(response.destinations[0].http_basic_auth).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_auth) - expect(response.destinations[0].http_basic_password).to.be.equal(updateWebhook.webhook.destinations[0].http_basic_password) - expect(response.channels[0]).to.be.equal(updateWebhook.webhook.channels[0]) - expect(response.retry_policy).to.be.equal(updateWebhook.webhook.retry_policy) - expect(response.disabled).to.be.equal(updateWebhook.webhook.disabled) - done() - }) - .catch(done) - }) - - it('Import Webhook', done => { - makeWebhook().import({ - webhook: path.join(__dirname, './mock/webhook.json') - }) - .then((response) => { - expect(response.uid).to.be.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get executions of a webhook', done => { - const asset = { - upload: path.join(__dirname, './mock/webhook.json') - } - client.stack({ api_key: stack.api_key }).asset().create(asset) - .then((assetFile) => { - makeWebhook(webhookUid).executions() - .then((response) => { - response.webhooks.forEach(webhookResponse => { - expect(webhookResponse.uid).to.be.not.equal(null) - expect(webhookResponse.status).to.be.equal(200) - expect(webhookResponse.event_data.module).to.be.equal('asset') - expect(webhookResponse.event_data.api_key).to.be.equal(stack.api_key) - - const webhookasset = webhookResponse.event_data.data.asset - expect(webhookasset.uid).to.be.equal(assetFile.uid) - expect(webhookasset.filename).to.be.equal(assetFile.filename) - expect(webhookasset.url).to.be.equal(assetFile.url) - expect(webhookasset.title).to.be.equal(assetFile.title) - - expect(webhookResponse.webhooks[0]).to.be.equal(webhookUid) - expect(webhookResponse.channel[0]).to.be.equal('assets.create') - }) - done() - }) - .catch(done) - }).catch(done) - }) - - it('Get all Webhook', done => { - makeWebhook().fetchAll() - .then((collection) => { - collection.items.forEach(webhookResponse => { - expect(webhookResponse.uid).to.be.not.equal(null) - expect(webhookResponse.name).to.be.not.equal(null) - expect(webhookResponse.org_uid).to.be.equal(stack.org_uid) - }) - done() - }) - .catch(done) - }) -}) - -function makeWebhook (uid = null) { - return client.stack({ api_key: stack.api_key }).webhook(uid) -} diff --git a/test/api/workflow-test.js b/test/api/workflow-test.js deleted file mode 100644 index c37cf592..00000000 --- a/test/api/workflow-test.js +++ /dev/null @@ -1,485 +0,0 @@ -import { expect } from 'chai' -import { describe, it, setup } from 'mocha' -import { jsonReader } from '../utility/fileOperations/readwrite' -import { contentstackClient } from '../utility/ContentstackClient.js' -import { firstWorkflow, secondWorkflow, finalWorkflow, firstPublishRules, secondPublishRules } from './mock/workflow' -import { cloneDeep } from 'lodash' -var client = {} -var environment = {} - -var roles = {} -var stack = {} -var user = {} -var workflowUid = '' -var publishRuleUid = '' - -describe('Workflow api Test', () => { - setup(async () => { - user = jsonReader('loggedinuser.json') - stack = jsonReader('stack.json') - client = contentstackClient(user.authtoken) - environment = jsonReader('environments.json') - roles = jsonReader('roles.json') - }) - - it('Create Workflow Content type Multi page from JSON', done => { - const workflow = { ...firstWorkflow } - makeWorkflow() - .create({ workflow }) - .then(workflowResponse => { - workflowUid = workflowResponse.uid - expect(workflowResponse.name).to.be.equal(firstWorkflow.name) - expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) - expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) - done() - }) - .catch(done) - }) - - it('Create Workflow Content type Multi page', done => { - const workflow = { ...secondWorkflow } - makeWorkflow() - .create({ workflow }) - .then(workflowResponse => { - expect(workflowResponse.name).to.be.equal(secondWorkflow.name) - expect(workflowResponse.content_types.length).to.be.equal(secondWorkflow.content_types.length) - expect(workflowResponse.workflow_stages.length).to.be.equal(secondWorkflow.workflow_stages.length) - done() - }) - .catch(done) - }) - - it('Create Workflow Content type single page', done => { - const workflow = { ...finalWorkflow } - makeWorkflow() - .create({ workflow }) - .then(workflowResponse => { - expect(workflowResponse.name).to.be.equal(finalWorkflow.name) - expect(workflowResponse.content_types.length).to.be.equal(finalWorkflow.content_types.length) - expect(workflowResponse.workflow_stages.length).to.be.equal(finalWorkflow.workflow_stages.length) - done() - }) - .catch(done) - }) - - it('Fetch Workflow from UID', done => { - makeWorkflow(workflowUid) - .fetch() - .then(workflowResponse => { - workflowUid = workflowResponse.uid - expect(workflowResponse.name).to.be.equal(firstWorkflow.name) - expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) - expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) - done() - }) - .catch(done) - }) - - it('Update Workflow from UID', done => { - const workflowObj = makeWorkflow(workflowUid) - Object.assign(workflowObj, firstWorkflow) - workflowObj.name = 'Updated name' - - workflowObj - .update() - .then(workflowResponse => { - workflowUid = workflowResponse.uid - expect(workflowResponse.name).to.be.equal('Updated name') - expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) - expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) - done() - }) - .catch(done) - }) - - it('Fetch and update Workflow from UID', done => { - makeWorkflow(workflowUid) - .fetch() - .then(workflowResponse => { - workflowResponse.name = firstWorkflow.name - return workflowResponse.update() - }) - .then(workflowResponse => { - expect(workflowResponse.name).to.be.equal(firstWorkflow.name) - expect(workflowResponse.content_types.length).to.be.equal(firstWorkflow.content_types.length) - expect(workflowResponse.workflow_stages.length).to.be.equal(firstWorkflow.workflow_stages.length) - done() - }) - .catch(done) - }) - it('Fetch all workflow', done => { - makeWorkflow() - .fetchAll() - .then(collection => { - expect(collection.items.length).to.be.equal(3) - done() - }) - .catch(done) - }) - - it('Fetch all workflow and update', done => { - makeWorkflow() - .fetchAll() - .then(collection => { - const updatedWorkflow = collection.items[0] - updatedWorkflow.name = 'Updated name' - return updatedWorkflow.update() - }) - .then((update) => { - expect(update.name).to.be.equal('Updated name') - done() - }) - .catch(done) - }) - - it('Fetch all workflow include count', done => { - makeWorkflow() - .fetchAll({ include_count: true }) - .then(collection => { - expect(collection.count).to.be.equal(3) - done() - }) - .catch(done) - }) - - it('Fetch all workflow skip and limit', done => { - makeWorkflow() - .fetchAll({ skip: 1, limit: 1 }) - .then(collection => { - expect(collection.items.length).to.be.equal(1) - done() - }) - .catch(done) - }) - - it('Enable Workflow from uid', done => { - makeWorkflow(workflowUid) - .enable() - .then(response => { - expect(response.notice).to.be.equal('Workflow enabled successfully.') - done() - }) - .catch(done) - }) - - it('Disable Workflow from uid', done => { - makeWorkflow(workflowUid) - .disable() - .then(response => { - expect(response.notice).to.be.equal('Workflow disabled successfully.') - done() - }) - .catch(done) - }) - - it('Create Publish rules', done => { - const publishingRule = cloneDeep(firstPublishRules) - publishingRule.environment = environment[0].uid - publishingRule.approvers = { - users: [user.uid], - roles: [roles[0].uid] - } - makeWorkflow() - .publishRule() - .create({ publishing_rule: publishingRule }) - .then(publishRule => { - publishRuleUid = publishRule.uid - expect(publishRule.actions.length).to.be.equal(publishingRule.actions.length) - expect(publishRule.environment).to.be.equal(publishingRule.environment) - expect(publishRule.content_types.length).to.be.equal(publishingRule.content_types.length) - expect(publishRule.content_types[0]).to.be.equal(publishingRule.content_types[0]) - expect(publishRule.approvers.users[0]).to.be.equal(user.uid) - done() - }) - .catch(done) - }) - - it('Create second Publish rules', done => { - const publishingRule = cloneDeep(secondPublishRules) - publishingRule.environment = environment[1].uid - publishingRule.approvers = { - users: [user.uid], - roles: [roles[1].uid] - } - makeWorkflow() - .publishRule() - .create({ publishing_rule: publishingRule }) - .then(publishRule => { - // publishRequestUid = publishRule.uid - expect(publishRule.actions.length).to.be.equal(publishingRule.actions.length) - expect(publishRule.environment).to.be.equal(publishingRule.environment) - expect(publishRule.content_types.length).to.be.equal(publishingRule.content_types.length) - expect(publishRule.content_types[0]).to.be.equal(publishingRule.content_types[0]) - expect(publishRule.approvers.users[0]).to.be.equal(user.uid) - done() - }) - .catch(done) - }) - - it('Create Single page Publish rules', done => { - const publishingRule = cloneDeep(secondPublishRules) - publishingRule.content_types = ['single_page'] - publishingRule.environment = environment[1].uid - publishingRule.approvers = { - users: [user.uid], - roles: [roles[1].uid] - } - makeWorkflow() - .publishRule() - .create({ publishing_rule: publishingRule }) - .then(publishRule => { - expect(publishRule.actions.length).to.be.equal(publishingRule.actions.length) - expect(publishRule.environment).to.be.equal(publishingRule.environment) - expect(publishRule.content_types.length).to.be.equal(publishingRule.content_types.length) - expect(publishRule.content_types[0]).to.be.equal(publishingRule.content_types[0]) - expect(publishRule.approvers.users[0]).to.be.equal(user.uid) - done() - }) - .catch(done) - }) - - it('Create second Publish rules should fail', done => { - const publishingRule = cloneDeep(secondPublishRules) - publishingRule.environment = environment[1].uid - publishingRule.approvers = { - users: [user.uid], - roles: [roles[1].uid] - } - makeWorkflow() - .publishRule() - .create({ publishing_rule: publishingRule }) - .then(publishRule => { - expect(publishRule).to.be.equal(undefined) - done() - }) - .catch(error => { - const jsonMessage = JSON.parse(error.message) - expect(jsonMessage.status).to.be.equal(422) - expect(jsonMessage.statusText).to.be.equal('Unprocessable Entity') - expect(jsonMessage.errorMessage).to.be.equal('Publish rule could not be created. Please try again.') - expect(jsonMessage.statusText).to.be.equal('Unprocessable Entity') - expect(jsonMessage.errors.publishing_rule[0]).to.be.equal('publishing rule is already set for multi_page and en-at for publish action(s).') - done() - }) - .catch(done) - }) - - it('Fetch Publish rules', done => { - makeWorkflow() - .publishRule(publishRuleUid) - .fetch() - .then(publishRule => { - expect(publishRule.actions.length).to.be.equal(firstPublishRules.actions.length) - expect(publishRule.environment).to.be.equal(environment[0].uid) - expect(publishRule.content_types.length).to.be.equal(firstPublishRules.content_types.length) - expect(publishRule.content_types[0]).to.be.equal(firstPublishRules.content_types[0]) - expect(publishRule.approvers.users[0]).to.be.equal(user.uid) - done() - }) - .catch(done) - }) - - it('Update Publish rules', done => { - makeWorkflow() - .publishRule(publishRuleUid) - .fetch() - .then(publishRule => { - publishRule.approvers = { - users: [user.uid], - roles: [roles[1].uid] - } - delete publishRule.status - return publishRule.update() - }) - .then(publishRule => { - expect(publishRule.actions.length).to.be.equal(firstPublishRules.actions.length) - expect(publishRule.environment).to.be.equal(environment[0].uid) - expect(publishRule.content_types.length).to.be.equal(firstPublishRules.content_types.length) - expect(publishRule.content_types[0]).to.be.equal(firstPublishRules.content_types[0]) - expect(publishRule.approvers.users[0]).to.be.equal(user.uid) - expect(publishRule.approvers.roles[0]).to.be.equal(roles[1].uid) - done() - }) - .catch(done) - }) - - it('Fetch All the PublishRules', done => { - makeWorkflow() - .publishRule() - .fetchAll() - .then(response => { - expect(response.items.length).to.be.equal(3) - done() - }) - .catch(done) - }) - - it('Fetch All the PublishRules include count', done => { - makeWorkflow() - .publishRule() - .fetchAll({ include_count: true }) - .then(response => { - expect(response.count).to.be.equal(3) - done() - }) - .catch(done) - }) - - it('Fetch All the PublishRules skip', done => { - makeWorkflow() - .publishRule() - .fetchAll({ skip: 1 }) - .then(response => { - expect(response.items.length).to.be.equal(2) - done() - }) - .catch(done) - }) - - it('Fetch All the PublishRules limit', done => { - makeWorkflow() - .publishRule() - .fetchAll({ limit: 1 }) - .then(response => { - expect(response.items.length).to.be.equal(1) - done() - }) - .catch(done) - }) - - it('Fetch All the PublishRules Content type', done => { - const contentTypes = 'multi_page_from_json,multi_page' - makeWorkflow() - .publishRule() - .fetchAll({ content_types: contentTypes }) - .then(response => { - expect(response.items.length).to.be.equal(2) - expect(contentTypes).to.contain(response.items[0].content_types[0]) - expect(contentTypes).to.contain(response.items[1].content_types[0]) - done() - }) - .catch(done) - }) - - it('Get Publish rules by content type', done => { - makeWorkflow() - .contentType('multi_page') - .getPublishRules({ action: 'publish' }) - .then(response => { - expect(response.items.length).to.be.equal(1) - const publishRule = response.items[0] - expect(publishRule.action).to.be.equal('publish') - expect(publishRule.environment).to.be.equal(environment[1].uid) - expect(publishRule.approvers[0]).to.be.equal(user.uid) - done() - }) - .catch(done) - }) - - it('Get unpublish rules by content type', done => { - makeWorkflow() - .contentType('multi_page') - .getPublishRules({ action: 'unpublish' }) - .then(response => { - expect(response.items.length).to.be.equal(0) - done() - }) - .catch(done) - }) - - it('Get publish rules by content type specific locale not present', done => { - makeWorkflow() - .contentType('multi_page') - .getPublishRules({ action: 'publish', locale: 'en-us' }) - .then(response => { - expect(response.items.length).to.be.equal(0) - done() - }) - .catch(done) - }) - - it('Get publish rules by content type specific locale', done => { - makeWorkflow() - .contentType('multi_page') - .getPublishRules({ action: 'publish', locale: 'en-at' }) - .then(response => { - expect(response.items.length).to.be.equal(1) - const publishRule = response.items[0] - expect(publishRule.action).to.be.equal('publish') - expect(publishRule.environment).to.be.equal(environment[1].uid) - expect(publishRule.approvers[0]).to.be.equal(user.uid) - done() - }) - .catch(done) - }) - - it('Get publish rules by content type specific environment not present', done => { - makeWorkflow() - .contentType('multi_page') - .getPublishRules({ action: 'publish', environment: environment[0].uid }) - .then(response => { - expect(response.items.length).to.be.equal(0) - done() - }) - .catch(done) - }) - - it('Get publish rules by content type specific environment', done => { - makeWorkflow() - .contentType('multi_page') - .getPublishRules({ action: 'publish', environment: environment[1].uid }) - .then(response => { - expect(response.items.length).to.be.equal(1) - const publishRule = response.items[0] - expect(publishRule.action).to.be.equal('publish') - expect(publishRule.environment).to.be.equal(environment[1].uid) - expect(publishRule.approvers[0]).to.be.equal(user.uid) - done() - }) - .catch(done) - }) - - // it('Request Publish entry', done => { - // const publishing_rule = { - // uid: publishRequestUid, - // action: 'publish', - // status: 0, - // notify: false, - // comment: "Please review the publish" - // } - // client.stack({ api_key: stack.api_key }) - // .contentType(multiPageCT.content_type.uid) - // .entry(entries[0].uid) - // .publishRequest({publishing_rule}) - // .then(response => { - // console.log(response) - // done() - // }) - // .catch(done) - // }) - - it('Delete Publish rule from UID', done => { - makeWorkflow() - .publishRule(publishRuleUid) - .delete() - .then(response => { - expect(response.notice).to.be.equal('Publish rule deleted successfully.') - done() - }) - .catch(done) - }) - - it('Delete Workflow from UID', done => { - makeWorkflow(workflowUid) - .delete() - .then(response => { - expect(response.notice).to.be.equal('Workflow deleted successfully.') - done() - }) - .catch(done) - }) -}) - -function makeWorkflow (uid = null) { - return client.stack({ api_key: stack.api_key }).workflow(uid) -} diff --git a/test/sanity-check/utility/ContentstackClient.js b/test/sanity-check/utility/ContentstackClient.js index a91c1171..6736e206 100644 --- a/test/sanity-check/utility/ContentstackClient.js +++ b/test/sanity-check/utility/ContentstackClient.js @@ -1,6 +1,15 @@ import * as contentstack from '../../../lib/contentstack.js' import dotenv from 'dotenv' dotenv.config() + +const requiredVars = ['HOST', 'EMAIL', 'PASSWORD', 'ORGANIZATION', 'API_KEY'] +const missingVars = requiredVars.filter((key) => !process.env[key]) + +if (missingVars.length > 0) { + console.error(`\x1b[31mError: Missing environment variables - ${missingVars.join(', ')}`) + process.exit(1) +} + function contentstackClient (authtoken = null) { var params = { host: process.env.HOST, defaultHostName: process.env.DEFAULTHOST } if (authtoken) { diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a66cd167..00000000 --- a/test/test.js +++ /dev/null @@ -1,33 +0,0 @@ -require('./api/user-test') -require('./api/organization-test') -require('./api/stack-test') -require('./api/app-test') -require('./api/hosting-test') -require('./api/app-request-test') -require('./api/authorization-test') -require('./api/app-delete-test') -require('./api/branch-test') -require('./api/branchAlias-test') -require('./api/bulkOperation-test') -require('./api/locale-test') -require('./api/environment-test') -require('./api/deliveryToken-test') -require('./api/role-test') -require('./api/stack-share') -require('./api/contentType-test') -require('./api/asset-test') -require('./api/extension-test') -require('./api/entry-test') -require('./api/webhook-test') -require('./api/workflow-test') -require('./api/globalfield-test') -require('./api/release-test') -require('./api/label-test') -require('./api/contentType-delete-test') -require('./api/delete-test') -require('./api/taxonomy-test') -require('./api/terms-test') -require('./api/team-test') -require('./api/team-users-test') -require('./api/team-stack-role-mapping-test') -require('./api/managementToken-test') diff --git a/test/typescript/asset.ts b/test/typescript/asset.ts index 0c15de5e..0dbefb46 100644 --- a/test/typescript/asset.ts +++ b/test/typescript/asset.ts @@ -9,7 +9,7 @@ export function createAsset(stack: Stack) { describe('Asset create', () => { test('Asset Upload', done => { const asset = { - upload: path.join(__dirname, '../api/mock/customUpload.html'), + upload: path.join(__dirname, '../sanity-check/mock/customUpload.html'), title: 'customasset', description: 'Custom Asset Desc', tags: ['custom'] @@ -45,7 +45,7 @@ export function createAsset(stack: Stack) { test('Upload asset in folder', done => { const asset = { - upload: path.join(__dirname, '../api/mock/customUpload.html'), + upload: path.join(__dirname, '../sanity-check/mock/customUpload.html'), title: 'customasset in Folder', description: 'Custom Asset Desc in Folder', parent_uid: folderUID, @@ -93,7 +93,7 @@ export function replaceAsset(stack: Stack) { describe('Asset replace', () => { test('Replace Asset', done => { const asset = { - upload: path.join(__dirname, '../api/mock/upload.html') + upload: path.join(__dirname, '../sanity-check/mock/upload.html') } stack.asset(assetUID) diff --git a/test/typescript/contentType.ts b/test/typescript/contentType.ts index c0af4225..3f851375 100644 --- a/test/typescript/contentType.ts +++ b/test/typescript/contentType.ts @@ -29,7 +29,7 @@ export function createContentType(contentType: ContentTypes) { test('Import Content type', done => { contentType.import({ - content_type: path.join(__dirname, '../api/mock/contentType.json') + content_type: path.join(__dirname, '../sanity-check/mock/contentType.json') }) .then((response) => { expect(response.uid).to.be.not.equal(null) diff --git a/test/typescript/entry.ts b/test/typescript/entry.ts index 57b576b2..070eff77 100644 --- a/test/typescript/entry.ts +++ b/test/typescript/entry.ts @@ -197,7 +197,7 @@ export function importEntry(stack: Stack){ describe('Import Entry', () => { test('Entry import from path', done => { stack.contentType(multiPageCT.content_type.uid).entry() - .import({ entry: path.join(__dirname, '../api/mock/entry.json')}) + .import({ entry: path.join(__dirname, '../sanity-check/mock/entry.json')}) .then((response) => { expect(response.uid).to.be.not.equal(null) done() diff --git a/test/typescript/extension.ts b/test/typescript/extension.ts index 50bd9b2d..f00c2904 100644 --- a/test/typescript/extension.ts +++ b/test/typescript/extension.ts @@ -1,6 +1,6 @@ import { expect } from "chai" import { Extensions } from "../../types/stack/extension"; -import { customFieldURL, customFieldSRC, customWidgetURL, customWidgetSRC, customDashboardURL, customDashboardSRC } from "../api/mock/extension"; +import { customFieldURL, customFieldSRC, customWidgetURL, customWidgetSRC, customDashboardURL, customDashboardSRC } from "../sanity-check/mock/extension"; var customFieldUID = '' var customWidgetUID = '' diff --git a/test/typescript/globalField.ts b/test/typescript/globalField.ts index 85fd8d3d..6e44e634 100644 --- a/test/typescript/globalField.ts +++ b/test/typescript/globalField.ts @@ -23,7 +23,7 @@ export function createGlobalField(globalField: GlobalFields) { test('Import global field', done => { globalField.import({ - global_field: path.join(__dirname, '../api/mock/globalfield.json') + global_field: path.join(__dirname, '../sanity-check/mock/globalfield.json') }) .then((response) => { expect(response.uid).to.be.not.equal(null) diff --git a/test/unit/asset-test.js b/test/unit/asset-test.js index bf4cb3b3..e8a4f22b 100644 --- a/test/unit/asset-test.js +++ b/test/unit/asset-test.js @@ -113,7 +113,7 @@ describe('Contentstack Asset test', () => { } }) makeAsset() - .create({ upload: path.join(__dirname, '../api/mock/customUpload.html') }) + .create({ upload: path.join(__dirname, '../sanity-check/mock/customUpload.html') }) .then((asset) => { checkAsset(asset) done() @@ -128,7 +128,7 @@ describe('Contentstack Asset test', () => { ...assetMock } }) - const assetUpload = { upload: path.join(__dirname, '../api/mock/customUpload.html'), tags: 'tags' } + const assetUpload = { upload: path.join(__dirname, '../sanity-check/mock/customUpload.html'), tags: 'tags' } const form = createFormData(assetUpload)() var boundary = form.getBoundary() @@ -151,7 +151,7 @@ describe('Contentstack Asset test', () => { } }) const assetUpload = { - upload: path.join(__dirname, '../api/mock/customUpload.html'), + upload: path.join(__dirname, '../sanity-check/mock/customUpload.html'), title: 'customasset', description: 'Custom Asset Desc', tags: ['Custom'], @@ -186,7 +186,7 @@ describe('Contentstack Asset test', () => { parent_uid: 'UID' } }) - const filePath = path.join(__dirname, '../api/mock/customUpload.html') + const filePath = path.join(__dirname, '../sanity-check/mock/customUpload.html') const fileBuffer = fs.readFileSync(filePath) const assetUpload = { upload: fileBuffer, // Buffer upload @@ -223,7 +223,7 @@ describe('Contentstack Asset test', () => { } }) const assetUpload = { - upload: path.join(__dirname, '../api/mock/customUpload.html'), + upload: path.join(__dirname, '../sanity-check/mock/customUpload.html'), title: 'customasset', description: 'Custom Asset Desc', tags: ['Custom'], diff --git a/test/unit/concurrency-Queue-test.js b/test/unit/concurrency-Queue-test.js index 981ec556..de3e2197 100644 --- a/test/unit/concurrency-Queue-test.js +++ b/test/unit/concurrency-Queue-test.js @@ -377,7 +377,7 @@ describe('Concurrency queue test', () => { const fuc = (pathcontent) => { return () => { const formData = new FormData() - const uploadStream = createReadStream(path.join(__dirname, '../api/mock/upload.html')) + const uploadStream = createReadStream(path.join(__dirname, '../sanity-check/mock/upload.html')) formData.append('asset[upload]', uploadStream) return formData } diff --git a/test/unit/contentType-test.js b/test/unit/contentType-test.js index 4ce44dd2..a1be2162 100644 --- a/test/unit/contentType-test.js +++ b/test/unit/contentType-test.js @@ -241,7 +241,7 @@ describe('Contentstack ContentType test', () => { ...contentTypeMock } }) - const contentTypeUpload = { content_type: path.join(__dirname, '../api/mock/contentType.json') } + const contentTypeUpload = { content_type: path.join(__dirname, '../sanity-check/mock/contentType.json') } const form = createFormData(contentTypeUpload)() var boundary = form.getBoundary() @@ -263,7 +263,7 @@ describe('Contentstack ContentType test', () => { ...contentTypeMock } }) - const contentTypeUpload = { content_type: path.join(__dirname, '../api/mock/contentType.json') } + const contentTypeUpload = { content_type: path.join(__dirname, '../sanity-check/mock/contentType.json') } const form = createFormData(contentTypeUpload)() var boundary = form.getBoundary() diff --git a/test/unit/entry-test.js b/test/unit/entry-test.js index 0df9c293..afcebe21 100644 --- a/test/unit/entry-test.js +++ b/test/unit/entry-test.js @@ -222,7 +222,7 @@ describe('Contentstack Entry test', () => { ...entryMock } }) - const entryUpload = { entry: path.join(__dirname, '../api/mock/entry.json') } + const entryUpload = { entry: path.join(__dirname, '../sanity-check/mock/entry.json') } const form = createFormData(entryUpload.entry)() var boundary = form.getBoundary() @@ -245,7 +245,7 @@ describe('Contentstack Entry test', () => { } }) makeEntry() - .import({ entry: path.join(__dirname, '../api/mock/entry.json'), overwrite: true }) + .import({ entry: path.join(__dirname, '../sanity-check/mock/entry.json'), overwrite: true }) .then((entry) => { checkEntry(entry) done() @@ -261,7 +261,7 @@ describe('Contentstack Entry test', () => { } }) makeEntry() - .import({ entry: path.join(__dirname, '../api/mock/entry.json'), locale: 'en-us' }) + .import({ entry: path.join(__dirname, '../sanity-check/mock/entry.json'), locale: 'en-us' }) .then((entry) => { checkEntry(entry) done() diff --git a/test/unit/extension-test.js b/test/unit/extension-test.js index 4a133747..14e4e66c 100644 --- a/test/unit/extension-test.js +++ b/test/unit/extension-test.js @@ -170,7 +170,7 @@ describe('Contentstack Extension test', () => { } }) - const extensionUpload = { upload: path.join(__dirname, '../api/mock/customUpload.html') } + const extensionUpload = { upload: path.join(__dirname, '../sanity-check/mock/customUpload.html') } const form = createExtensionFormData(extensionUpload)() var boundary = form.getBoundary() @@ -195,7 +195,7 @@ describe('Contentstack Extension test', () => { } }) - const extensionUpload = { upload: path.join(__dirname, '../api/mock/customUpload.html'), tags: 'tag1, tag2' } + const extensionUpload = { upload: path.join(__dirname, '../sanity-check/mock/customUpload.html'), tags: 'tag1, tag2' } const form = createExtensionFormData(extensionUpload)() var boundary = form.getBoundary() @@ -225,7 +225,7 @@ describe('Contentstack Extension test', () => { tags: extensionMock.tags, enable: true, default_width: extensionMock.default_width, - upload: path.join(__dirname, '../api/mock/customUpload.html'), + upload: path.join(__dirname, '../sanity-check/mock/customUpload.html'), scope: {}, multiple: true } diff --git a/test/unit/globalField-test.js b/test/unit/globalField-test.js index f9c2f912..361fbb60 100644 --- a/test/unit/globalField-test.js +++ b/test/unit/globalField-test.js @@ -174,7 +174,7 @@ describe('Contentstack GlobalField test', () => { } }) const gfUpload = { - global_field: path.join(__dirname, '../api/mock/globalfield.json') + global_field: path.join(__dirname, '../sanity-check/mock/globalfield.json') } const form = createFormData(gfUpload)() var boundary = form.getBoundary() @@ -198,7 +198,7 @@ describe('Contentstack GlobalField test', () => { } }) const gfUpload = { - global_field: path.join(__dirname, '../api/mock/globalfield.json') + global_field: path.join(__dirname, '../sanity-check/mock/globalfield.json') } const form = createFormData(gfUpload)() var boundary = form.getBoundary() @@ -395,7 +395,7 @@ describe('Contentstack GlobalField test (API Version 3.2)', () => { } }) const gfUpload = { - global_field: path.join(__dirname, '../api/mock/globalfield.json') + global_field: path.join(__dirname, '../sanity-check/mock/globalfield.json') } const form = createFormData(gfUpload)() var boundary = form.getBoundary() @@ -421,7 +421,7 @@ describe('Contentstack GlobalField test (API Version 3.2)', () => { } }) const gfUpload = { - global_field: path.join(__dirname, '../api/mock/globalfield.json') + global_field: path.join(__dirname, '../sanity-check/mock/globalfield.json') } const form = createFormData(gfUpload)() var boundary = form.getBoundary() diff --git a/test/unit/mock/objects.js b/test/unit/mock/objects.js index 5aea75b5..7376088c 100644 --- a/test/unit/mock/objects.js +++ b/test/unit/mock/objects.js @@ -1,5 +1,5 @@ import cloneDeep from 'lodash/cloneDeep' -import { singlepageCT } from '../../api/mock/content-type' +import { singlepageCT } from '../../sanity-check/mock/content-type' import { expect } from 'chai' const errorMock = { diff --git a/test/unit/taxonomy-test.js b/test/unit/taxonomy-test.js index 879b56cf..67a59090 100644 --- a/test/unit/taxonomy-test.js +++ b/test/unit/taxonomy-test.js @@ -152,7 +152,7 @@ describe('Contentstack Taxonomy test', () => { ...taxonomyMock } }) - const taxonomyUpload = { taxonomy: path.join(__dirname, '../api/mock/taxonomy.json') } + const taxonomyUpload = { taxonomy: path.join(__dirname, '../sanity-check/mock/taxonomy.json') } const form = createFormData(taxonomyUpload)() var boundary = form.getBoundary() diff --git a/test/unit/webhook-test.js b/test/unit/webhook-test.js index 6b2bff63..b328f225 100644 --- a/test/unit/webhook-test.js +++ b/test/unit/webhook-test.js @@ -303,7 +303,7 @@ describe('Contentstack Webhook test', () => { ...webhookMock } }) - const webhookUpload = { webhook: path.join(__dirname, '../api/mock/customUpload.html') } + const webhookUpload = { webhook: path.join(__dirname, '../sanity-check/mock/customUpload.html') } const form = createFormData(webhookUpload)() var boundary = form.getBoundary() diff --git a/test/utility/ContentstackClient.js b/test/utility/ContentstackClient.js deleted file mode 100644 index b9340524..00000000 --- a/test/utility/ContentstackClient.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as contentstack from '../../lib/contentstack.js' -import dotenv from 'dotenv' -dotenv.config() -function contentstackClient (authtoken = null) { - var params = { host: process.env.HOST, defaultHostName: process.env.DEFAULTHOST } - if (authtoken) { - params.authtoken = authtoken - } - return contentstack.client(params) -} - -export { contentstackClient } diff --git a/test/utility/fileOperations/readwrite.js b/test/utility/fileOperations/readwrite.js deleted file mode 100644 index c06fe895..00000000 --- a/test/utility/fileOperations/readwrite.js +++ /dev/null @@ -1,35 +0,0 @@ -import fs from 'fs' -import path from 'path' -const dataFiles = './test/utility/dataFiles/' -export function jsonReader (fileName) { - if (!fs.existsSync(`${dataFiles}${fileName}`)) { - return - } - const fileContents = fs.readFileSync(`${dataFiles}${fileName}`, 'utf8') - try { - const object = JSON.parse(fileContents) - return object - } catch (err) { - return err - } -} - -export function jsonWrite (json, fileName) { - const jsonString = JSON.stringify(json) - ensureDirectoryExistence(`${dataFiles}${fileName}`) - fs.writeFileSync(`${dataFiles}${fileName}`, jsonString) -} - -function ensureDirectoryExistence (filePath) { - var dirname = path.dirname(filePath) - if (!fs.existsSync(dirname)) { - ensureDirectoryExistence(dirname) - fs.mkdirSync(dirname) - } -} - -export function writeDownloadedFile (response, fileName) { - const filePath = path.resolve(dataFiles, fileName) - ensureDirectoryExistence(`${dataFiles}${fileName}`) - response.data.pipe(fs.createWriteStream(filePath)) -}