diff --git a/.talismanrc b/.talismanrc index 41223457..80cd6c29 100644 --- a/.talismanrc +++ b/.talismanrc @@ -6,4 +6,14 @@ fileignoreconfig: checksum: 9d0340f9359927d477fe8ab4650642c068c592be63fb817651d866849e0dbbc2 - filename: .husky/pre-commit checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193 -version: "" \ No newline at end of file +version: "" +fileignoreconfig: +- filename: test/unit/globalField-test.js + checksum: 25185e3400a12e10a043dc47502d8f30b7e1c4f2b6b4d3b8b55cdc19850c48bf +version: "1.0" +fileignoreconfig: +- filename: lib/stack/index.js + checksum: 6aab5edf85efb17951418b4dc4402889cd24c8d786c671185074aeb4d50f0242 +- filename: test/sanity-check/api/stack-test.js + checksum: 198d5cf7ead33b079249dc3ecdee61a9c57453e93f1073ed0341400983e5aa53 +version: "1.0" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 726e69b2..b638938a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [v1.21.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.3) (2025-05-26) + - Enhancement + - Update addSettings Method to Support Generic Stack Settings Update + ## [v1.21.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.2) (2025-05-19) - Enhancement - Added preview token generation. diff --git a/lib/app/authorization/index.js b/lib/app/authorization/index.js deleted file mode 100644 index 66e3cd60..00000000 --- a/lib/app/authorization/index.js +++ /dev/null @@ -1,107 +0,0 @@ -import cloneDeep from 'lodash/cloneDeep' -import error from '../../core/contentstackError' - -export function Authorization (http, data, params) { - http.defaults.versioningStrategy = undefined - this.params = params || {} - if (data) { - if (data.organization_uid) { - this.params = { - organization_uid: data.organization_uid - } - } - if (data.app_uid) { - this.urlPath = `/manifests/${data.app_uid}/authorizations` - /** - * @description List all user authorizations made to an authorized app under a particular organization - * @memberof Authorization - * @func findAll - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('manifest_uid').authorization().findAll() - * .then((response) => console.log(response)) - */ - this.findAll = async (param = {}) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) }, - params: { - ...cloneDeep(param) - } - } - - const response = await http.get(this.urlPath, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description Revoke all users tokens issued to an authorized app for the particular organization - * @memberof Authorization - * @func revokeAll - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('manifest_uid').authorization().revokeAll() - * .then((response) => console.log(response)) - */ - this.revokeAll = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.delete(this.urlPath, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description Revoke user token issued to an authorized app for the particular organization - * @memberof Authorization - * @func revoke - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('manifest_uid').authorization().revoke('authorization_uid') - * .then((response) => console.log(response)) - */ - this.revoke = async (authorizationUid) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.delete(`${this.urlPath}/${authorizationUid}`, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - } - } -} diff --git a/lib/app/hosting/deployment.js b/lib/app/hosting/deployment.js deleted file mode 100644 index 073d4dae..00000000 --- a/lib/app/hosting/deployment.js +++ /dev/null @@ -1,189 +0,0 @@ -import cloneDeep from 'lodash/cloneDeep' -import ContentstackCollection from '../../contentstackCollection' -import error from '../../core/contentstackError' - -export function Deployment (http, data, params) { - http.defaults.versioningStrategy = undefined - - if (data && data.app_uid) { - this.params = params || {} - this.urlPath = `/manifests/${data.app_uid}/hosting/deployments` - if (data.organization_uid) { - this.params = { - organization_uid: data.organization_uid - } - } - if (data.data) { - Object.assign(this, cloneDeep(data.data)) - if (this.organization_uid) { - this.params = { - organization_uid: this.organization_uid - } - } - } - if (this.uid) { - this.urlPath = `/manifests/${data.app_uid}/hosting/deployments/${this.uid}` - /** - * @descriptionThe The GET deployment call is used to get all the details of an deployment of an app - * @memberof Deployment - * @func fetch - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().deployment('deployment_uid').fetch() - * .then((data) => {}) - */ - this.fetch = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.get(`${this.urlPath}`, headers) - if (response.data) { - const content = response.data.data - return new Deployment(http, { data: content, app_uid: data.app_uid }, this.params) - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @descriptionThe The list deployment logs call is used to list logs of a deployment. - * @memberof Deployment - * @func logs - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().deployment('deployment_uid').logs() - * .then((data) => {}) - */ - this.logs = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.get(`${this.urlPath}/logs`, headers) - if (response.data) { - return response.data.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @descriptionThe The create signed download url call is used to get the download url of the deployment source code. - * @memberof signedDownloadUrl - * @func logs - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().deployment('deployment_uid').signedDownloadUrl() - * .then((data) => {}) - */ - this.signedDownloadUrl = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.post(`${this.urlPath}/signedDownloadUrl`, {}, headers) - if (response.data) { - return response.data.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - } else { - /** - * @descriptionThe The create hosting deployments call is used to deploy the uploaded file in hosting - * @memberof Deployment - * @func create - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().deployment().create() - * .then((data) => {}) - */ - this.create = async ({ uploadUid, fileType, withAdvancedOptions }) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - if (withAdvancedOptions) { - headers.params = { - with_advanced_options: withAdvancedOptions - } - } - const response = await http.post(`${this.urlPath}`, { upload_uid: uploadUid, file_type: fileType }, headers) - if (response.data) { - const content = response.data.data - return new Deployment(http, { data: content, app_uid: data.app_uid }, this.params) - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @descriptionThe The list deployments call is used to get all the available deployments made for an app. - * @memberof Deployment - * @func findAll - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().deployment().create() - * .then((data) => {}) - */ - this.findAll = async (param = {}) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) }, - params: { ...cloneDeep(param) } - } - - const response = await http.get(`${this.urlPath}`, headers) - if (response.data) { - const content = response.data - const collection = new ContentstackCollection(response, http) - collection.items = DeploymentCollection(http, content, data.app_uid, this.params) - return collection - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - } - } -} - -export function DeploymentCollection (http, data, appUid, param) { - const obj = cloneDeep(data.data) || [] - return obj.map((content) => { - return new Deployment(http, { data: content, app_uid: appUid }, param) - }) -} diff --git a/lib/app/hosting/index.js b/lib/app/hosting/index.js deleted file mode 100644 index 4fb57e96..00000000 --- a/lib/app/hosting/index.js +++ /dev/null @@ -1,186 +0,0 @@ -import cloneDeep from 'lodash/cloneDeep' -import error from '../../core/contentstackError' -import { Deployment } from './deployment' - -export function Hosting (http, data, params) { - http.defaults.versioningStrategy = undefined - - this.params = params || {} - if (data && data.app_uid) { - this.urlPath = `/manifests/${data.app_uid}/hosting` - if (data.organization_uid) { - this.params = { - organization_uid: data.organization_uid - } - } - - /** - * @description The get hosting call is used to fetch to know whether the hosting is enabled or not. - * @memberof Hosting - * @func isEnable - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().isEnable() - * .then((data) => {}) - */ - this.isEnable = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.get(this.urlPath, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description The toggle hosting call is used to enable the hosting of an app. - * @memberof Hosting - * @func enable - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().enable() - * .then((data) => {}) - */ - this.enable = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.patch(`${this.urlPath}/enable`, {}, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description The toggle hosting call is used to disable the hosting of an app. - * @memberof Hosting - * @func disable - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().disable() - * .then((data) => {}) - */ - this.disable = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.patch(`${this.urlPath}/disable`, {}, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @descriptionThe create signed upload url call is used to create an signed upload url for the files in hosting. - * @memberof Hosting - * @func createUploadUrl - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().createUploadUrl() - * .then((data) => {}) - */ - this.createUploadUrl = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.post(`${this.urlPath}/signedUploadUrl`, { }, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @descriptionThe The GET latest live deployment call is used to get details of latest deployment of the source file. - * @memberof Hosting - * @func latestLiveDeployment - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().latestLiveDeployment() - * .then((data) => {}) - */ - this.latestLiveDeployment = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.get(`${this.urlPath}/latestLiveDeployment`, headers) - if (response.data) { - const content = response.data.data - return new Deployment(http, { data: content, app_uid: data.app_uid }, this.params) - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description Create instance of Hosting deployment. - * @memberof Hosting - * @func deployment - * @returns {Deployment} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting().deployment() - * - */ - this.deployment = (uid = null) => { - const content = { app_uid: data.app_uid } - if (uid) { - content.data = { - uid - } - } - - return new Deployment(http, content, this.params) - } - } -} diff --git a/lib/app/index.js b/lib/app/index.js deleted file mode 100644 index 4de9d815..00000000 --- a/lib/app/index.js +++ /dev/null @@ -1,433 +0,0 @@ -import cloneDeep from 'lodash/cloneDeep' -import error from '../core/contentstackError' -import { create, deleteEntity, fetch, fetchAll, update } from '../entity' -import { Authorization } from './authorization' -import { Hosting } from './hosting' -import { Installation, InstallationCollection } from './installation' -import ContentstackCollection from '../contentstackCollection' - -export function App (http, data) { - http.defaults.versioningStrategy = undefined - this.urlPath = '/manifests' - this.params = {} - if (data) { - if (data.organization_uid) { - this.params = { - organization_uid: data.organization_uid - } - } - if (data.data) { - Object.assign(this, cloneDeep(data.data)) - if (this.organization_uid) { - this.params = { - organization_uid: this.organization_uid - } - } - this.urlPath = `/manifests/${this.uid}` - - /** - * @description The update manifest call is used to update the app details such as name, description, icon, and so on. - * @memberof App - * @func update - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * const updateApp = { - * name: 'APP_NAME', - * description: 'APP_DESCRIPTION', - * target_type: 'stack'/'organization', - * } - * const app = client.organization('organization_uid').app('manifest_uid') - * app = Object.assign(app, updateApp) - * app.update() - * .then((app) => console.log(app)) - * - */ - this.update = update(http, undefined, this.params) - - /** - * @description The get manifest call is used to fetch details of a particular app with its ID. - * @memberof App - * @func fetch - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('manifest_uid').fetch() - * .then((app) => console.log(app)) - * - */ - this.fetch = fetch(http, 'data', this.params) - - /** - * @description The delete manifest call is used to delete the app. - * @memberof App - * @func delete - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('manifest_uid').delete() - * .then((response) => console.log(response)) - */ - this.delete = deleteEntity(http, false, this.params) - - /** - * @description The get oauth call is used to fetch the OAuth details of the app. - * @memberof App - * @func fetchOAuth - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('manifest_uid').fetchOAuth() - * .then((oAuthConfig) => console.log(oAuthConfig)) - */ - this.fetchOAuth = async (param = {}) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) }, - params: { - ...cloneDeep(param) - } - } || {} - - const response = await http.get(`${this.urlPath}/oauth`, headers) - if (response.data) { - return response.data.data || {} - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description The change oauth details call is used to update the OAuth details, (redirect url and permission scope) of an app. - * @memberof App - * @func updateOAuth - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * const config = { - * redirect_uri: 'REDIRECT_URI', - * app_token_config: { - * enabled: true, - * scopes: ['scope1', 'scope2'] - * }, - * user_token_config: { - * enabled: true, - * scopes: ['scope1', 'scope2'] - * } - * } - * client.organization('organization_uid').app('manifest_uid').updateOAuth({ config }) - * .then((oAuthConfig) => console.log(oAuthConfig)) - */ - this.updateOAuth = async ({ config, param = {} }) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) }, - params: { - ...cloneDeep(param) - } - } || {} - - const response = await http.put(`${this.urlPath}/oauth`, config, headers) - if (response.data) { - return response.data.data || {} - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description The hosting will allow you get, update, deploy manifest. - * @memberof App - * @func updateOAuth - * @returns {Promise} - * @returns {Hosting} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').hosting() - */ - this.hosting = () => { - return new Hosting(http, { app_uid: this.uid }, this.params) - } - - /** - * @description The install call is used to initiate the installation of the app - * @memberof App - * @func install - * @param {String} param.targetType - The target on which app needs to be installed, stack or ogranization. - * @param {String} param.targetUid - The uid of the target, on which the app will be installed - * @returns Promise - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').install({ targetUid: 'STACK_API_KEY', targetType: 'stack' }) - * .then((installation) => console.log(installation)) - */ - this.install = async ({ targetUid, targetType }) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } || {} - - const response = await http.post(`${this.urlPath}/install`, { target_type: targetType, target_uid: targetUid }, headers) - if (response.data) { - return new Installation(http, response.data, this.params) || {} - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description The Installation will allow you to fetch, update and delete of the app installation. - * @memberof App - * @func installation - * @param {String} uid Installation uid - * @returns Installation - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').installation().findAll() - * .then((installations) => console.log(installations)) - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').installation('installation_uid').fetch() - * .then((installation) => console.log(installation)) - */ - this.installation = (uid = null) => { - return new Installation(http, uid ? { data: { uid } } : { app_uid: this.uid }, this.params) - } - /** - * @description The GET app requests of an app call is used to retrieve all requests of an app. - * @returns Promise - * @memberof App - * @func getRequests - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').getRequests() - * .then((response) => console.log(response)) - * - */ - this.getRequests = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.get(`${this.urlPath}/requests`, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description The App authorization allow to authorize app for specific scope. - * @returns Promise - * @param {string} param.responseType Desired grant type - * @param {string} param.clientId Client id of the app - * @param {string} param.redirectUri Redirect URL of the app - * @param {string} param.scope Scopes of the app - * @param {string} param.state Local state provided by the client - * - * @memberof App - * @func authorize - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').authorize() - * .then((response) => console.log(response)) - * - */ - this.authorize = async ({ responseType, clientId, redirectUri, scope, state }) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - const content = { - response_type: responseType, - client_id: clientId, - redirect_uri: redirectUri, - scope: scope - } - if (state) { - content.state = state - } - const response = await http.post(`${this.urlPath}/authorize`, content, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description The Authorization will allow you to get all authorization, revoke specific or all authorization - * @memberof App - * @func authorization - * @returns {Authorization} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * client.organization('organization_uid').app('manifest_uid').authorization() - */ - this.authorization = () => { - return new Authorization(http, { app_uid: this.uid }, this.params) - } - - /** - * @description The list installation call is used to retrieve all installations of your Contentstack organization. - * @memberof App - * @func listInstallations - * @returns {Promise>} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').listInstallations() - * .then((collection) => console.log(collection)) - * - */ - this.listInstallations = async () => { - try { - const headers = { - headers: { ...cloneDeep(this.params), ...cloneDeep(this.headers) } - } - const response = await http.get(`manifests/${this.uid}/installations`, headers) - if (response.data) { - return new ContentstackCollection(response, http, this.stackHeaders, InstallationCollection) - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - } else { - /** - * @description The create manifest call is used for creating a new app/manifest in your Contentstack organization. - * @memberof App - * @func create - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * const app = { - * name: 'APP_NAME', - * description: 'APP_DESCRIPTION', - * target_type: 'stack'/'organization', - * webhook: // optional - * { - * target_url: 'TARGET_URL', - * channel: 'CHANNEL' - * }, - * oauth: // optional - * { - * redirect_uri: 'REDIRECT_URI', - * enabled: true, - * } - * } - * - * client.organization('organization_uid').app().create(app) - * .then((app) => console.log(app)) - * - */ - this.create = create({ http, params: this.params }) - - /** - * @description The get all manifest call is used to fetch all the apps in your Contentstack organization. - * @memberof App - * @func findAll - * @returns {Promise>} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app().fetchAll() - * .then((collection) => console.log(collection)) - * - */ - this.findAll = fetchAll(http, AppCollection, this.params) - - /** - * @description To get the apps list of authorized apps for the particular organization - * @memberof Organization - * @func authorizedApps - * @param {number} skip - Offset for skipping content in the response. - * @param {number} limit - Limit on api response to provide content in list. - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client() - * - * client.organization('organization_uid').authorizedApps({ skip: 10 }) - * .then((roles) => console.log(roles)) - * - */ - this.findAllAuthorized = async (param = {}) => { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - headers.params = { ...param } - try { - const response = await http.get(`/authorized-apps`, headers) - if (response.data) { - return response.data - } else { - return error(response) - } - } catch (err) { - return error(err) - } - } - } - } - return this -} - -export function AppCollection (http, data) { - const obj = cloneDeep(data.data) || [] - return obj.map((appData) => { - return new App(http, { data: appData }) - }) -} diff --git a/lib/app/installation/index.js b/lib/app/installation/index.js deleted file mode 100644 index b84453cf..00000000 --- a/lib/app/installation/index.js +++ /dev/null @@ -1,253 +0,0 @@ -import cloneDeep from 'lodash/cloneDeep' -import error from '../../core/contentstackError' -import { deleteEntity, fetch, fetchAll, update } from '../../entity' - -export function Installation (http, data, params = {}) { - this.params = params - if (data.data) { - Object.assign(this, cloneDeep(data.data)) - if (this.installation_uid) { - this.uid = this.installation_uid - } - if (this.organization_uid) { - this.params = { - organization_uid: this.organization_uid - } - } - this.urlPath = `/installations/${this.uid}` - - /** - * @description The GET installation call is used to retrieve a specific installation of an app. - * @memberof Installation - * @func fetch - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation('installation_uid').fetch() - * .then((installation) => console.log(installation)) - * - */ - this.fetch = fetch(http, 'data', this.params) - - /** - * @description The Update installation call is used to update information of an installation. - * @memberof Installation - * @func update - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * const updateInstallation = { - * name: 'APP_NAME', - * description: 'APP_DESCRIPTION', - * target_type: 'stack'/'organization', - * } - * - * const installation = client.organization('organization_uid').app('app_uid').installation('installation_uid') - * installation = Object.assign(installation, updateInstallation) - * installation.update() - * .then((installation) => console.log(installation)) - */ - this.update = update(http, 'data', this.params) - - /** - * @description The Uninstall installation call is used to uninstall the installation. - * @memberof Installation - * @func uninstall - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation('installation_uid').uninstall() - * .then((response) => console.log(response)) - */ - this.uninstall = deleteEntity(http, false, this.params) - - /** - * @description To fetch organization level app installation configuration. - * @memberof Installation - * @func configuration - * @param {*} param - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation('installation_uid').configuration() - * .then((response) => console.log(response)) - */ - this.configuration = async (param = {}) => { - try { - const headers = { - headers: { ...cloneDeep(params) }, - params: { - ...cloneDeep(param) - } - } || {} - const response = await http.get(`${this.urlPath}/configuration`, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description To update organization level app installation configuration. - * @memberof Installation - * @func setConfiguration - * @param {*} config Config that needs to be updated - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation('installation_uid').setConfiguration({}) - * .then((response) => console.log(response)) - */ - this.setConfiguration = async (config) => { - try { - const headers = { - headers: { ...cloneDeep(params) } - } || {} - const response = await http.put(`${this.urlPath}/configuration`, config, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description To fetch server side organization level config required for the app. - * @memberof Installation - * @func getServerConfig - * @param {*} param - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation('installation_uid').serverConfig() - * .then((response) => console.log(response)) - */ - this.serverConfig = async (param = {}) => { - try { - const headers = { - headers: { ...cloneDeep(params) }, - params: { - ...cloneDeep(param) - } - } || {} - const response = await http.get(`${this.urlPath}/server-configuration`, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description To update server side organization level config required for the app. - * @memberof Installation - * @func setServerConfig - * @param {*} config Config that needs to be updated - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation('installation_uid').setServerConfig({}) - * .then((response) => console.log(response)) - */ - this.setServerConfig = async (config) => { - try { - const headers = { - headers: { ...cloneDeep(params) } - } || {} - const response = await http.put(`${this.urlPath}/server-configuration`, config, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - - /** - * @description To fetch installation data of an app configuration. - * @memberof Installation - * @func installationData - * @returns {Promise} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation('installation_uid').installationData() - * .then((response) => console.log(response)) - */ - this.installationData = async () => { - try { - const headers = { - headers: { ...cloneDeep(params) } - } || {} - const response = await http.get(`${this.urlPath}/installationData`, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - } else { - if (data.app_uid) { - this.urlPath = `manifests/${data.app_uid}/installations` - /** - * @description The find installation call is used to retrieve all installations of your Contentstack organization. - * @memberof Installation - * @func findAll - * @returns {Promise>} - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').installation().fetchAll() - * .then((collection) => console.log(collection)) - * - */ - this.findAll = fetchAll(http, InstallationCollection, this.params) - } - } - return this -} - -export function InstallationCollection (http, data) { - const obj = cloneDeep(data.data) || [] - return obj.map((installationData) => { - return new Installation(http, { data: installationData }) - }) -} diff --git a/lib/app/request/index.js b/lib/app/request/index.js deleted file mode 100644 index 7372c739..00000000 --- a/lib/app/request/index.js +++ /dev/null @@ -1,110 +0,0 @@ -import cloneDeep from 'lodash/cloneDeep' -import error from '../../core/contentstackError' - -export function AppRequest (http, data, param) { - http.defaults.versioningStrategy = undefined - this.params = param || {} - - if (data) { - if (data.organization_uid) { - this.params = { - organization_uid: data.organization_uid - } - } - /** - * @description The Delete app request call is used to delete an app request of an app in target_uid. - * @param {string} requestUID The ID of the request to be deleted - * @returns Promise - * @memberof AppRequest - * @func delete - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').request().delete('request_uid`) - * .then((response) => console.log(response)) - * - */ - this.delete = async (requestUid) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.delete(`/requests/${requestUid}`, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description The Create call is used to create a app request for an app. - * @param {string} appUid The uid for the app for request - * @param {string} targetUid The uid of the target, on which the app will be installed - * @returns Promise - * @memberof AppRequest - * @func create - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').request().create({ appUid: 'app_uid', targetUid: 'target_uid' }) - * .then((response) => console.log(response)) - * - */ - this.create = async ({ appUid, targetUid }) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) } - } - - const response = await http.post(`/requests`, { app_uid: appUid, target_uid: targetUid }, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - /** - * @description The GET all app requests call is used to retrieve all requests of all apps in an organization. - * @param {object} param object for query params - * @returns Promise - * @memberof AppRequest - * @func findAll - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').request().findAll() - * .then((response) => console.log(response)) - * - */ - this.findAll = async (param = {}) => { - try { - const headers = { - headers: { ...cloneDeep(this.params) }, - params: { ...param } - } - - const response = await http.get(`/requests`, headers) - if (response.data) { - return response.data - } else { - throw error(response) - } - } catch (err) { - throw error(err) - } - } - } -} diff --git a/lib/organization/index.js b/lib/organization/index.js index 98ce0f5a..49c26fa8 100644 --- a/lib/organization/index.js +++ b/lib/organization/index.js @@ -5,8 +5,6 @@ import ContentstackCollection from '../contentstackCollection' import { RoleCollection } from '../stack/roles' import { StackCollection } from '../stack' import { UserCollection } from '../user' -import { App } from '../app' -import { AppRequest } from '../app/request' import { Teams } from './teams' /** * Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users. Organization allows easy management of projects as well as users within the Organization. Read more about Organizations.. @@ -222,39 +220,6 @@ export function Organization (http, data) { return error(err) } } - - /** - * @description Market place application information - * @memberof Organization - * @func app - * @param {String} uid: The ID of the app that you want to fetch details of. - * @returns {App} Instance of App - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').app('app_uid').fetch() - * .then((app) => console.log(app)) - */ - this.app = (uid = null) => { - return new App(http, uid !== null ? { data: { uid, organization_uid: this.uid } } : { organization_uid: this.uid }) - } - - /** - * @description The Create request call is used to create a app request for an app. - * @returns Request - * - * @example - * import * as contentstack from '@contentstack/management' - * const client = contentstack.client({ authtoken: 'TOKEN'}) - * - * client.organization('organization_uid').appRequest() - * - */ - this.appRequest = () => { - return new AppRequest(http, { organization_uid: this.organization_uid }, this.params) - } } else { /** * @description The Get all organizations call lists all organizations related to the system user in the order that they were created. diff --git a/lib/stack/globalField/index.js b/lib/stack/globalField/index.js index 32c14838..57192ea6 100644 --- a/lib/stack/globalField/index.js +++ b/lib/stack/globalField/index.js @@ -10,13 +10,17 @@ import { createReadStream } from 'fs' */ export function GlobalField (http, data = {}) { - this.stackHeaders = data.stackHeaders - if (data.api_version) { - this.stackHeaders.api_version = data.api_version + const rawHeaders = data.stackHeaders || {} + + this.stackHeaders = { + ...cloneDeep(rawHeaders), + ...(data.apiVersion ? { api_version: data.apiVersion } : {}), + ...(data.branch ? { branch: data.branch } : {}) } + this.urlPath = `/global_fields` - if (data.global_field) { + if (data.global_field && data.global_field.uid) { Object.assign(this, cloneDeep(data.global_field)) this.urlPath = `/global_fields/${this.uid}` /** diff --git a/lib/stack/index.js b/lib/stack/index.js index 3ced19ee..c954e81c 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -154,7 +154,7 @@ export function Stack (http, data) { * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * - * client.stack({ api_key: 'api_key'}).globalField().create() + * client.stack({ api_key: 'api_key'}).globalField().create(data) * .then((globalField) => console.log(globalField)) * * client.stack({ api_key: 'api_key'}).globalField('globalField_uid').fetch() @@ -164,12 +164,27 @@ export function Stack (http, data) { * .then((globalField) => console.log(globalField)) * */ - // eslint-disable-next-line camelcase - this.globalField = (globalFieldUid = null, api_version = '3.0') => { + + this.globalField = (uidOrOptions = null, option = {}) => { + let globalFieldUid = null + let apiVersion = '3.0' + let branch = 'main' + const stackHeaders = { ...this.stackHeaders } + if (typeof uidOrOptions === 'object' && uidOrOptions !== null) { + option = uidOrOptions + } else { + globalFieldUid = uidOrOptions + } + if (option?.api_version) { + apiVersion = option.api_version + } + if (option?.branch) { + branch = option.branch + } const data = { - stackHeaders: this.stackHeaders, - // eslint-disable-next-line camelcase - api_version: api_version + stackHeaders, + apiVersion, + branch } if (globalFieldUid) { data.global_field = { uid: globalFieldUid } @@ -633,10 +648,17 @@ export function Stack (http, data) { */ this.addSettings = async (stackVariables = {}) => { try { - const response = await http.post(`${this.urlPath}/settings`, { stack_settings: { stack_variables: stackVariables } }, - { headers: { - ...cloneDeep(this.stackHeaders) - } }) + const payloadBody = ( + 'stack_variables' in stackVariables || + 'live_preview' in stackVariables || + 'rte' in stackVariables + ) + ? { stack_settings: stackVariables } + : { stack_settings: { stack_variables: stackVariables } } + + const response = await http.post(`${this.urlPath}/settings`, payloadBody, { headers: { + ...cloneDeep(this.stackHeaders) + } }) if (response.data) { return response.data.stack_settings } else { diff --git a/package-lock.json b/package-lock.json index 82a6b51d..32aa93f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/management", - "version": "1.21.2", + "version": "1.21.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.21.2", + "version": "1.21.3", "license": "MIT", "dependencies": { "assert": "^2.1.0", diff --git a/package.json b/package.json index 0dba89bc..d2e6a11a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.21.2", + "version": "1.21.3", "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", @@ -41,7 +41,7 @@ "format": "eslint --fix lib test", "prepare": "npm run build", "pretest": "rimraf coverage && npm run lint", - "precommit": "npm run lint", + "pre-commit": "npm run lint && husky install && husky && chmod +x .husky/pre-commit && ./.husky/pre-commit", "prepush": "npm run test:unit", "generate:docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --readme README.md --verbose", "husky-check": "npx husky && chmod +x .husky/pre-commit" diff --git a/test/sanity-check/api/globalfield-test.js b/test/sanity-check/api/globalfield-test.js index eb5ad12a..1f369b68 100644 --- a/test/sanity-check/api/globalfield-test.js +++ b/test/sanity-check/api/globalfield-test.js @@ -3,7 +3,7 @@ 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 { createGlobalField, createNestedGlobalFieldForReference, createNestedGlobalField } from '../mock/globalfield' import { contentstackClient } from '../utility/ContentstackClient.js' import dotenv from 'dotenv' @@ -117,113 +117,113 @@ describe('Global Field api Test', () => { .catch(done) }) - // it("should get all nested global fields from Query", (done) => { - // makeGlobalField({ api_version: '3.2' }) - // .query() - // .find() - // .then((collection) => { - // collection.items.forEach((globalField) => { - // expect(globalField.uid).to.be.not.equal(null); - // expect(globalField.title).to.be.not.equal(null); - // }); - // done(); - // }) - // .catch(done); - // }); + it('should get all nested global fields from Query', (done) => { + makeGlobalField({ api_version: '3.2' }) + .query() + .find() + .then((collection) => { + collection.items.forEach((globalField) => { + expect(globalField.uid).to.be.not.equal(null) + expect(globalField.title).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) - // it('should create nested global field for reference', done => { - // makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalFieldForReference) - // .then(globalField => { - // expect(globalField.uid).to.be.equal(createNestedGlobalFieldForReference.global_field.uid); - // done(); - // }) - // .catch(err => { - // console.error('Error:', err.response?.data || err.message); - // done(err); - // }); - // }); + it('should create nested global field for reference', done => { + makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalFieldForReference) + .then(globalField => { + expect(globalField.uid).to.be.equal(createNestedGlobalFieldForReference.global_field.uid) + done() + }) + .catch(err => { + console.error('Error:', err.response?.data || err.message) + done(err) + }) + }) - // it('should create nested global field', done => { - // makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalField) - // .then(globalField => { - // expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid); - // done(); - // }) - // .catch(err => { - // console.error('Error:', err.response?.data || err.message); - // done(err); - // }); - // }); + it('should create nested global field', done => { + makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalField) + .then(globalField => { + expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid) + done() + }) + .catch(err => { + console.error('Error:', err.response?.data || err.message) + done(err) + }) + }) - // it('should fetch nested global field', done => { - // makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' }).fetch() - // .then(globalField => { - // expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid); - // done(); - // }) - // .catch(err => { - // console.error('Error:', err.response?.data || err.message); - // done(err); - // }); - // }); + it('should fetch nested global field', done => { + makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' }).fetch() + .then(globalField => { + expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid) + done() + }) + .catch(err => { + console.error('Error:', err.response?.data || err.message) + done(err) + }) + }) - // it('should fetch and update nested global Field', done => { - // makeGlobalField(createGlobalField.global_field.uid, { api_version: '3.2' }).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('should fetch and update nested global Field', done => { + makeGlobalField(createGlobalField.global_field.uid, { api_version: '3.2' }).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('should update nested global Field', done => { - // const globalField = makeGlobalField(createGlobalField.global_field.uid, { api_version: '3.2' }) - // 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('should update nested global Field', done => { + const globalField = makeGlobalField(createGlobalField.global_field.uid, { api_version: '3.2' }) + 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("should delete nested global field", (done) => { - // makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' }) - // .delete() - // .then((data) => { - // expect(data.notice).to.be.equal("Global Field deleted successfully."); - // done(); - // }) - // .catch((err) => { - // console.error("Error:", err.response?.data || err.message); - // done(err); - // }); - // }); + it('should delete nested global field', (done) => { + makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' }) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Global Field deleted successfully.') + done() + }) + .catch((err) => { + console.error('Error:', err.response?.data || err.message) + done(err) + }) + }) - // it("should delete nested global reference field", (done) => { - // makeGlobalField(createNestedGlobalFieldForReference.global_field.uid, { api_version: '3.2' }) - // .delete() - // .then((data) => { - // expect(data.notice).to.be.equal("Global Field deleted successfully."); - // done(); - // }) - // .catch((err) => { - // console.error("Error:", err.response?.data || err.message); - // done(err); - // }); - // }); + it('should delete nested global reference field', (done) => { + makeGlobalField(createNestedGlobalFieldForReference.global_field.uid, { api_version: '3.2' }) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Global Field deleted successfully.') + done() + }) + .catch((err) => { + console.error('Error:', err.response?.data || err.message) + done(err) + }) + }) it('should delete global Field', (done) => { makeGlobalField(createGlobalField.global_field.uid) diff --git a/test/sanity-check/api/stack-test.js b/test/sanity-check/api/stack-test.js index 76082f43..ce52ec83 100644 --- a/test/sanity-check/api/stack-test.js +++ b/test/sanity-check/api/stack-test.js @@ -91,7 +91,70 @@ describe('Stack api Test', () => { .catch(done) }) - it('should add stack settings', done => { + it('should set stack_variables correctly', done => { + const variables = { + stack_variables: { + enforce_unique_urls: true, + sys_rte_allowed_tags: 'style,figure,script', + sys_rte_skip_format_on_paste: 'GD:font-size', + samplevariable: 'too' + } + } + + client.stack({ api_key: stacks.api_key }) + .addSettings(variables) + .then((response) => { + const vars = response.stack_variables + expect(vars.enforce_unique_urls).to.equal(true) + expect(vars.sys_rte_allowed_tags).to.equal('style,figure,script') + expect(vars.sys_rte_skip_format_on_paste).to.equal('GD:font-size') + expect(vars.samplevariable).to.equal('too') + done() + }) + .catch(done) + }) + + it('should set rte settings correctly', done => { + const variables = { + rte: { + cs_breakline_on_enter: true, + cs_only_breakline: true + } + } + + client.stack({ api_key: stacks.api_key }) + .addSettings(variables) + .then((response) => { + const rte = response.rte + expect(rte.cs_breakline_on_enter).to.equal(true) + expect(rte.cs_only_breakline).to.equal(true) + done() + }) + .catch(done) + }) + + it('should set live_preview settings correctly', done => { + const variables = { + live_preview: { + enabled: true, + 'default-env': '', + 'default-url': 'https://preview.example.com' + } + } + + client.stack({ api_key: stacks.api_key }) + .addSettings(variables) + .then((response) => { + const preview = response.live_preview + expect(preview.enabled).to.equal(true) + expect(preview['default-env']).to.equal('') + expect(preview['default-url']).to.equal('https://preview.example.com') + done() + }) + .catch(done) + }) + + it('should add simple stack variable', done => { client.stack({ api_key: stacks.api_key }) .addSettings({ samplevariable: 'too' }) .then((response) => { @@ -101,6 +164,47 @@ describe('Stack api Test', () => { .catch(done) }) + it('should add stack settings', done => { + const variables = { + stack_variables: { + enforce_unique_urls: true, + sys_rte_allowed_tags: 'style,figure,script', + sys_rte_skip_format_on_paste: 'GD:font-size', + samplevariable: 'too' + }, + rte: { + cs_breakline_on_enter: true, + cs_only_breakline: true + }, + live_preview: { + enabled: true, + 'default-env': '', + 'default-url': 'https://preview.example.com' + } + } + + client.stack({ api_key: stacks.api_key }) + .addSettings(variables).then((response) => { + const vars = response.stack_variables + expect(vars.enforce_unique_urls).to.equal(true, 'enforce_unique_urls must be true') + expect(vars.sys_rte_allowed_tags).to.equal('style,figure,script', 'sys_rte_allowed_tags must match') + expect(vars.sys_rte_skip_format_on_paste).to.equal('GD:font-size', 'sys_rte_skip_format_on_paste must match') + expect(vars.samplevariable).to.equal('too', 'samplevariable must be "too"') + + const rte = response.rte + expect(rte.cs_breakline_on_enter).to.equal(true, 'cs_breakline_on_enter must be true') + expect(rte.cs_only_breakline).to.equal(true, 'cs_only_breakline must be true') + + const preview = response.live_preview + expect(preview.enabled).to.equal(true, 'live_preview.enabled must be true') + expect(preview['default-env']).to.equal('', 'default-env must match') + expect(preview['default-url']).to.equal('https://preview.example.com', 'default-url must match') + + done() + }) + .catch(done) + }) + it('should reset stack settings', done => { client.stack({ api_key: stacks.api_key }) .resetSettings() diff --git a/test/unit/app-request-test.js b/test/unit/app-request-test.js deleted file mode 100644 index 8f3ead05..00000000 --- a/test/unit/app-request-test.js +++ /dev/null @@ -1,130 +0,0 @@ -import Axios from 'axios' -import { expect } from 'chai' -import { describe, it } from 'mocha' -import MockAdapter from 'axios-mock-adapter' -import { appMock } from './mock/objects' -import { AppRequest } from '../../lib/app/request' -import { requestMock } from './mock/request-mock' - -describe('Contentstack apps request test', () => { - it('test request without contents', () => { - const request = makeAppRequest() - expect(request.create).to.be.equal(undefined) - expect(request.delete).to.be.equal(undefined) - expect(request.findAll).to.be.equal(undefined) - }) - it('test request without app uid', () => { - const request = makeAppRequest({}) - expect(request.create).to.not.equal(undefined) - expect(request.delete).to.not.equal(undefined) - expect(request.findAll).to.not.equal(undefined) - }) - - it('test request with app uid and org uid', () => { - const organizationUid = 'ORG_UID' - const request = makeAppRequest({ organization_uid: organizationUid }) - expect(request.create).to.not.equal(undefined) - expect(request.delete).to.not.equal(undefined) - expect(request.findAll).to.not.equal(undefined) - expect(request.params.organization_uid).to.be.equal(organizationUid) - }) - - it('test find all request for organization', (done) => { - const mock = new MockAdapter(Axios) - mock.onGet(`/requests`).reply(200, { - data: [requestMock] - }) - - makeAppRequest({}) - .findAll() - .then((response) => { - expect(response.data).to.not.equal(undefined) - const requests = response.data - requests.forEach(request => { - checkRequest(request) - }) - done() - }) - .catch(done) - }) - it('test create request for app uid', (done) => { - const mock = new MockAdapter(Axios) - mock.onPost(`/requests`).reply(200, { - data: { ...requestMock } - }) - - makeAppRequest({}) - .create({ appUid: appMock.uid, targetUid: requestMock.target_uid }) - .then((response) => { - checkRequest(response.data) - done() - }) - .catch(done) - }) - it('test delete request for organization', (done) => { - const mock = new MockAdapter(Axios) - mock.onDelete(`/requests/${requestMock.uid}`).reply(200, { - - }) - - makeAppRequest({}) - .delete(requestMock.uid) - .then((request) => { - expect(request).to.not.equal(undefined) - done() - }) - .catch(done) - }) - it('test find all request for organization fail request', (done) => { - const mock = new MockAdapter(Axios) - mock.onGet(`/requests`).reply(400, { - - }) - - makeAppRequest({}) - .findAll() - .then(done) - .catch((error) => { - expect(error).to.not.equal(undefined) - done() - }) - }) - it('test create request for app uid fail request', (done) => { - const mock = new MockAdapter(Axios) - mock.onPost(`/requests`).reply(400, { - - }) - - makeAppRequest({}) - .create({ appUid: 'app_uid', targetUid: requestMock.target_uid }) - .then(done) - .catch((error) => { - expect(error).to.not.equal(undefined) - done() - }) - }) - it('test delete request for organization fail request', (done) => { - const mock = new MockAdapter(Axios) - mock.onDelete(`/requests/${requestMock.uid}`).reply(400, { - - }) - - makeAppRequest({}) - .delete(requestMock.uid) - .then(done) - .catch((error) => { - expect(error).to.not.equal(undefined) - done() - }) - }) -}) - -function makeAppRequest (data, param) { - return new AppRequest(Axios, data, param) -} - -function checkRequest (request) { - expect(request.organization_uid).to.be.equal(requestMock.organization_uid) - expect(request.target_uid).to.be.equal(requestMock.target_uid) - expect(request.uid).to.be.equal(requestMock.uid) -} diff --git a/test/unit/apps-test.js b/test/unit/apps-test.js deleted file mode 100644 index c0d56211..00000000 --- a/test/unit/apps-test.js +++ /dev/null @@ -1,434 +0,0 @@ -import Axios from 'axios' -import { expect } from 'chai' -import { App } from '../../lib/app' -import { describe, it } from 'mocha' -import MockAdapter from 'axios-mock-adapter' -import { appMock, installationMock, noticeMock, oAuthMock } from './mock/objects' -import { requestMock } from './mock/request-mock' - -describe('Contentstack apps test', () => { - it('App without app uid', done => { - const app = makeApp({}) - expect(app.urlPath).to.be.equal('/manifests') - expect(app.create).to.not.equal(undefined) - expect(app.findAll).to.not.equal(undefined) - expect(app.findAllAuthorized).to.not.equal(undefined) - expect(app.fetch).to.be.equal(undefined) - expect(app.update).to.be.equal(undefined) - expect(app.delete).to.be.equal(undefined) - expect(app.fetchOAuth).to.be.equal(undefined) - expect(app.updateOAuth).to.be.equal(undefined) - expect(app.hosting).to.be.equal(undefined) - expect(app.install).to.be.equal(undefined) - expect(app.installation).to.be.equal(undefined) - expect(app.getRequests).to.be.equal(undefined) - expect(app.authorize).to.be.equal(undefined) - done() - }) - - it('App with app uid', done => { - const uid = 'APP_UID' - const app = makeApp({ data: { uid } }) - expect(app.urlPath).to.be.equal(`/manifests/${uid}`) - expect(app.create).to.be.equal(undefined) - expect(app.findAll).to.be.equal(undefined) - expect(app.findAllAuthorized).to.be.equal(undefined) - expect(app.fetch).to.not.equal(undefined) - expect(app.update).to.not.equal(undefined) - expect(app.delete).to.not.equal(undefined) - expect(app.fetchOAuth).to.not.equal(undefined) - expect(app.updateOAuth).to.not.equal(undefined) - expect(app.hosting).to.not.equal(undefined) - expect(app.install).to.not.equal(undefined) - expect(app.installation).to.not.equal(undefined) - expect(app.listInstallations).to.not.equal(undefined) - expect(app.getRequests).to.not.equal(undefined) - expect(app.authorize).to.not.equal(undefined) - expect(app.hosting()).to.not.equal(undefined) - expect(app.installation()).to.not.equal(undefined) - expect(app.installation(uid)).to.not.equal(undefined) - expect(app.authorization()).to.not.equal(undefined) - done() - }) - - it('App with app uid and org uid', done => { - const uid = 'APP_UID' - const organizationUid = 'ORG_UID' - const app = makeApp({ data: { uid, organization_uid: organizationUid }, organization_uid: organizationUid }) - expect(app.urlPath).to.be.equal(`/manifests/${uid}`) - expect(app.create).to.be.equal(undefined) - expect(app.findAll).to.be.equal(undefined) - expect(app.findAllAuthorized).to.be.equal(undefined) - expect(app.fetch).to.not.equal(undefined) - expect(app.update).to.not.equal(undefined) - expect(app.delete).to.not.equal(undefined) - expect(app.fetchOAuth).to.not.equal(undefined) - expect(app.updateOAuth).to.not.equal(undefined) - expect(app.hosting).to.not.equal(undefined) - expect(app.install).to.not.equal(undefined) - expect(app.installation).to.not.equal(undefined) - expect(app.getRequests).to.not.equal(undefined) - expect(app.authorize).to.not.equal(undefined) - done() - }) - - it('Create app test', done => { - const mock = new MockAdapter(Axios) - mock.onPost('/manifests').reply(200, { - data: { - ...appMock - } - }) - - makeApp({}) - .create({}) - .then((app) => { - checkApp(app) - done() - }) - .catch(done) - }) - - it('Update app test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPut(`/manifests/${uid}`).reply(200, { - data: { - ...appMock - } - }) - - makeApp({ data: { uid } }) - .update() - .then((app) => { - checkApp(app) - done() - }) - .catch(done) - }) - - it('Get app from UID test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onGet(`/manifests/${uid}`).reply(200, { - data: { - ...appMock - } - }) - - makeApp({ data: { uid } }) - .fetch() - .then((app) => { - checkApp(app) - done() - }) - .catch(done) - }) - - it('Delete app from UID test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onDelete(`/manifests/${uid}`).reply(200, { - ...noticeMock - }) - - makeApp({ data: { uid } }) - .delete() - .then((response) => { - expect(response.notice).to.not.equal(undefined) - expect(response.notice).to.be.equal(noticeMock.notice) - done() - }) - .catch(done) - }) - - it('Get all apps in organization test', done => { - const mock = new MockAdapter(Axios) - mock.onGet(`/manifests`).reply(200, { - data: [appMock] - }) - - makeApp({}) - .findAll() - .then((apps) => { - checkApp(apps.items[0]) - done() - }) - .catch(done) - }) - - it('Get app installation test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onGet(`manifests/${uid}/installations`).reply(200, { - data: [installationMock] - }) - - makeApp({ data: { uid } }) - .listInstallations() - .then((installations) => { - installations.items.forEach(installation => { - expect(installation.status).to.be.equal(installationMock.status) - expect(installation.uid).to.be.equal(installationMock.uid) - expect(installation.organization_uid).to.be.equal(installationMock.organization_uid) - expect(installation.target.type).to.be.equal(installationMock.target.type) - expect(installation.target.uid).to.be.equal(installationMock.target.uid) - }) - }) - .catch(done) - - // Failing test - mock.onGet(`manifests/${uid}/installations`).reply(400, {}) - makeApp({ data: { uid } }) - .listInstallations() - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('Get all authorized apps in organization test', done => { - const content = { - visibility: 'private', - description: 'This is a test App.', - name: 'New App', - org_id: 'org_uid', - created_at: '2021-07-20T13:34:54.791Z', - updated_at: '2021-07-27T14:05:19.452Z', - id: 'id' - } - const mock = new MockAdapter(Axios) - mock.onGet(`/authorized-apps`).reply(200, { - data: [ - content - ] - }) - - makeApp({}) - .findAllAuthorized() - .then((response) => { - expect(response.data[0].visibility).to.be.equal(content.visibility) - expect(response.data[0].description).to.be.equal(content.description) - expect(response.data[0].name).to.be.equal(content.name) - expect(response.data[0].org_id).to.be.equal(content.org_id) - expect(response.data[0].created_at).to.be.equal(content.created_at) - expect(response.data[0].updated_at).to.be.equal(content.updated_at) - expect(response.data[0].id).to.be.equal(content.id) - done() - }) - .catch(done) - }) - - it('Get oAuth configuration test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onGet(`/manifests/${uid}/oauth`).reply(200, { - data: { - ...oAuthMock - } - }) - - makeApp({ data: { uid } }) - .fetchOAuth() - .then((oAuthConfig) => { - expect(oAuthConfig.client_id).to.be.equal(oAuthMock.client_id) - expect(oAuthConfig.client_secret).to.be.equal(oAuthMock.client_secret) - expect(oAuthConfig.redirect_uri).to.be.equal(oAuthMock.redirect_uri) - expect(oAuthConfig.app_token_config.enabled).to.be.equal(oAuthMock.app_token_config.enabled) - expect(oAuthConfig.user_token_config.enabled).to.be.equal(oAuthMock.user_token_config.enabled) - done() - }) - .catch(done) - }) - - it('Get oAuth configuration failing test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onGet(`/manifests/${uid}/oauth`).reply(400, {}) - - makeApp({ data: { uid } }) - .fetchOAuth() - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('Update oAuth configuration test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPut(`/manifests/${uid}/oauth`).reply(200, { - data: { - ...oAuthMock - } - }) - const config = { ...oAuthMock } - makeApp({ data: { uid } }) - .updateOAuth({ config }) - .then((oAuthConfig) => { - expect(oAuthConfig.client_id).to.be.equal(oAuthMock.client_id) - expect(oAuthConfig.client_secret).to.be.equal(oAuthMock.client_secret) - expect(oAuthConfig.redirect_uri).to.be.equal(oAuthMock.redirect_uri) - expect(oAuthConfig.app_token_config.enabled).to.be.equal(oAuthMock.app_token_config.enabled) - expect(oAuthConfig.user_token_config.enabled).to.be.equal(oAuthMock.user_token_config.enabled) - done() - }) - .catch(done) - }) - - it('Update oAuth configuration failing test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPut(`/manifests/${uid}/oauth`).reply(400, {}) - - const config = { ...oAuthMock } - makeApp({ data: { uid } }) - .updateOAuth({ config }) - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('app install test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPost(`/manifests/${uid}/install`).reply(200, { - data: { - ...installationMock - } - }) - const targetUid = 'target_uid' - const targetType = 'target_type' - makeApp({ data: { uid } }) - .install({ targetUid, targetType }) - .then((installation) => { - expect(installation.status).to.be.equal(installationMock.status) - expect(installation.manifest.name).to.be.equal(installationMock.manifest.name) - expect(installation.target.uid).to.be.equal(installationMock.target.uid) - expect(installation.organization_uid).to.be.equal(installationMock.organization_uid) - expect(installation.uid).to.be.equal(installationMock.uid) - }) - .catch(done) - - // Failing test - mock.onPost(`/manifests/${uid}/install`).reply(400, {}) - makeApp({ data: { uid } }) - .install({ targetUid, targetType }) - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('test fetch request for app uid', (done) => { - const uid = appMock.uid - const mock = new MockAdapter(Axios) - mock.onGet(`/manifests/${appMock.uid}/requests`).reply(200, { - data: { ...requestMock } - }) - - makeApp({ data: { uid } }) - .getRequests() - .then((response) => { - const request = response.data - expect(request.organization_uid).to.be.equal(requestMock.organization_uid) - expect(request.target_uid).to.be.equal(requestMock.target_uid) - expect(request.uid).to.be.equal(requestMock.uid) - done() - }) - .catch(done) - }) - it('test authorize app', (done) => { - const uid = appMock.uid - const mock = new MockAdapter(Axios) - mock.onPost(`/manifests/${appMock.uid}/authorize`).reply(200, { - data: { redirect_uri: 'uri' } - }) - - makeApp({ data: { uid } }) - .authorize({ responseType: 'type', clientId: 'id', redirectUri: 'uri', scope: 'scope' }) - .then((response) => { - expect(response.data.redirect_uri).to.be.equal('uri') - done() - }) - .catch(done) - }) - it('test authorize app fail request', (done) => { - const uid = appMock.uid - const mock = new MockAdapter(Axios) - mock.onPost(`/manifests/${appMock.uid}/authorize`).reply(400, { - - }) - - makeApp({ data: { uid } }) - .authorize({ state: 'state', responseType: 'type', clientId: 'id', redirectUri: 'uri', scope: 'scope' }) - .then(done) - .catch((error) => { - expect(error).to.not.equal(undefined) - done() - }) - }) - it('test fetch request for app uid fail request', (done) => { - const uid = appMock.uid - const mock = new MockAdapter(Axios) - mock.onGet(`/manifests/${appMock.uid}/requests`).reply(400, { - - }) - - makeApp({ data: { uid } }) - .getRequests() - .then(done) - .catch((error) => { - expect(error).to.not.equal(undefined) - done() - }) - }) - it('test authorize app fail request', (done) => { - const uid = appMock.uid - const mock = new MockAdapter(Axios) - mock.onPost(`/manifests/${appMock.uid}/requests`).reply(400, { - - }) - - makeApp({ data: { uid } }) - .getRequests() - .then(done) - .catch((error) => { - expect(error).to.not.equal(undefined) - done() - }) - }) - it('Get all authorized apps in organization fail request', done => { - const mock = new MockAdapter(Axios) - mock.onGet(`/authorized-apps`).reply(400, { - - }) - - makeApp({}) - .findAllAuthorized() - .then(done) - .catch((error) => { - expect(error).to.not.equal(undefined) - done() - }) - }) -}) - -function checkApp (app) { - expect(app.urlPath).to.be.equal('/manifests/UID') - expect(app.created_at).to.be.equal('created_at_date') - expect(app.updated_at).to.be.equal('updated_at_date') - expect(app.uid).to.be.equal('UID') - expect(app.name).to.be.equal('Name of the app') - expect(app.description).to.be.equal('Description of the app') - expect(app.organization_uid).to.be.equal('org_uid') -} - -function makeApp (data) { - return new App(Axios, data) -} diff --git a/test/unit/authorization-test.js b/test/unit/authorization-test.js deleted file mode 100644 index 850694b8..00000000 --- a/test/unit/authorization-test.js +++ /dev/null @@ -1,160 +0,0 @@ -import Axios from 'axios' -import { expect } from 'chai' -import { describe, it } from 'mocha' -import MockAdapter from 'axios-mock-adapter' -import { Authorization } from '../../lib/app/authorization' - -const uid = 'APP_UID' -const orgUid = 'org_uid' -const authUid = 'AUTH_UID' - -describe('Contentstack apps authorization test', () => { - it('Authorization without content', () => { - const authorization = makeAuthorization() - expect(authorization.findAll).to.be.equal(undefined) - expect(authorization.revokeAll).to.be.equal(undefined) - expect(authorization.revoke).to.be.equal(undefined) - expect(authorization.params).to.not.equal(undefined) - }) - - it('Authorization without app uid', () => { - const authorization = makeAuthorization({}) - expect(authorization.findAll).to.be.equal(undefined) - expect(authorization.revokeAll).to.be.equal(undefined) - expect(authorization.revoke).to.be.equal(undefined) - expect(authorization.params).to.not.equal(undefined) - }) - it('Authorization with app uid', () => { - const authorization = makeAuthorization({ app_uid: uid }) - expect(authorization.urlPath).to.be.equal(`/manifests/${uid}/authorizations`) - expect(authorization.findAll).to.not.equal(undefined) - expect(authorization.revokeAll).to.not.equal(undefined) - expect(authorization.revoke).to.not.equal(undefined) - expect(authorization.params).to.not.equal(undefined) - }) - it('Authorization with app uid org uid as Param', () => { - const authorization = makeAuthorization({ app_uid: uid }, { organization_uid: orgUid }) - expect(authorization.urlPath).to.be.equal(`/manifests/${uid}/authorizations`) - expect(authorization.findAll).to.not.equal(undefined) - expect(authorization.revokeAll).to.not.equal(undefined) - expect(authorization.revoke).to.not.equal(undefined) - expect(authorization.params.organization_uid).to.be.equal(orgUid) - }) - it('Authorization with app uid, org uid as content', () => { - const authorization = makeAuthorization({ app_uid: uid, organization_uid: orgUid }) - expect(authorization.urlPath).to.be.equal(`/manifests/${uid}/authorizations`) - expect(authorization.findAll).to.not.equal(undefined) - expect(authorization.revokeAll).to.not.equal(undefined) - expect(authorization.revoke).to.not.equal(undefined) - expect(authorization.params.organization_uid).to.be.equal(orgUid) - }) - - it('test find all authorization for apps', done => { - const content = { - app_uid: 'app_uid', - organization_uid: 'org_uid', - scopes: [ - 'user.profile:read' - ], - created_at: '2021-09-09T05:03:10.473Z', - updated_at: '2021-09-09T05:03:10.473Z', - user: { - uid: 'uid' - } - } - const mock = new MockAdapter(Axios) - mock.onGet(`/manifests/${uid}/authorizations`).reply(200, { - data: [content] - }) - - makeAuthorization({ app_uid: uid }) - .findAll() - .then((response) => { - const result = response.data[0] - expect(result.app_uid).to.be.equal(content.app_uid) - expect(result.organization_uid).to.be.equal(content.organization_uid) - expect(result.scopes[0]).to.be.equal(content.scopes[0]) - expect(result.user.uid).to.be.equal(content.user.uid) - done() - }) - .catch(done) - }) - - it('test revoke all authorization for apps', done => { - const mock = new MockAdapter(Axios) - mock.onDelete(`/manifests/${uid}/authorizations`).reply(200, { - - }) - - makeAuthorization({ app_uid: uid }) - .revokeAll() - .then((response) => { - expect(response).to.not.equal(null) - done() - }) - .catch(done) - }) - - it('test revoke authorization for apps', done => { - const mock = new MockAdapter(Axios) - mock.onDelete(`/manifests/${uid}/authorizations/${authUid}`).reply(200, { - - }) - - makeAuthorization({ app_uid: uid }) - .revoke(authUid) - .then((response) => { - expect(response).to.not.equal(null) - done() - }) - .catch(done) - }) - - it('test find all authorization for apps fail request', done => { - const mock = new MockAdapter(Axios) - mock.onGet(`/manifests/${uid}/authorizations`).reply(400, { - }) - - makeAuthorization({ app_uid: uid }) - .findAll({}) - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('test revoke all authorization for apps fail request', done => { - const mock = new MockAdapter(Axios) - mock.onDelete(`/manifests/${uid}/authorizations`).reply(400, { - - }) - - makeAuthorization({ app_uid: uid }) - .revokeAll({}) - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('test revoke authorization for apps fail request', done => { - const mock = new MockAdapter(Axios) - mock.onDelete(`/manifests/${uid}/authorizations/${authUid}`).reply(400, { - - }) - - makeAuthorization({ app_uid: uid }) - .revoke(authUid) - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) -}) - -function makeAuthorization (data, param) { - return new Authorization(Axios, data, param) -} diff --git a/test/unit/deployment-test.js b/test/unit/deployment-test.js deleted file mode 100644 index a672d9f5..00000000 --- a/test/unit/deployment-test.js +++ /dev/null @@ -1,262 +0,0 @@ -import Axios from 'axios' -import { expect } from 'chai' -import { describe, it } from 'mocha' -import MockAdapter from 'axios-mock-adapter' -import { appMock } from './mock/objects' -import { latestLiveResponse, signedUrlResponse } from './mock/hosting-mock' -import { Deployment } from '../../lib/app/hosting/deployment' - -describe('Contentstack hosting test', () => { - it('test deployment without contents', done => { - const deployment = makeDeployment() - expect(deployment.create).to.be.equal(undefined) - expect(deployment.fetch).to.be.equal(undefined) - expect(deployment.findAll).to.be.equal(undefined) - expect(deployment.logs).to.be.equal(undefined) - expect(deployment.params).to.be.equal(undefined) - expect(deployment.signedDownloadUrl).to.be.equal(undefined) - expect(deployment.urlPath).to.be.equal(undefined) - done() - }) - it('test deployment without app uid', done => { - const deployment = makeDeployment({}) - expect(deployment.create).to.be.equal(undefined) - expect(deployment.fetch).to.be.equal(undefined) - expect(deployment.findAll).to.be.equal(undefined) - expect(deployment.logs).to.be.equal(undefined) - expect(deployment.params).to.be.equal(undefined) - expect(deployment.signedDownloadUrl).to.be.equal(undefined) - expect(deployment.urlPath).to.be.equal(undefined) - done() - }) - - it('test deployment with app uid', done => { - const uid = appMock.uid - const deployment = makeDeployment({ app_uid: uid }) - expect(deployment.create).to.not.equal(undefined) - expect(deployment.fetch).to.be.equal(undefined) - expect(deployment.findAll).to.not.equal(undefined) - expect(deployment.logs).to.be.equal(undefined) - expect(deployment.params.organization_uid).to.be.equal(undefined) - expect(deployment.signedDownloadUrl).to.be.equal(undefined) - expect(deployment.urlPath).to.be.equal(`/manifests/${uid}/hosting/deployments`) - done() - }) - - it('test deployment with app uid and org uid', done => { - const uid = appMock.uid - const organizationUid = appMock.organization_uid - const deployment = makeDeployment({ app_uid: uid, organization_uid: organizationUid }) - expect(deployment.create).to.not.equal(undefined) - expect(deployment.fetch).to.be.equal(undefined) - expect(deployment.findAll).to.not.equal(undefined) - expect(deployment.logs).to.be.equal(undefined) - expect(deployment.params.organization_uid).to.not.equal(undefined) - expect(deployment.signedDownloadUrl).to.be.equal(undefined) - expect(deployment.urlPath).to.be.equal(`/manifests/${uid}/hosting/deployments`) - done() - }) - - it('test deployment with deployment uid', done => { - const appUid = appMock.uid - const organizationUid = appMock.organization_uid - const uid = 'Deployment_uid' - const deployment = makeDeployment({ app_uid: appUid, organization_uid: organizationUid, data: { uid } }) - expect(deployment.create).to.be.equal(undefined) - expect(deployment.fetch).to.not.equal(undefined) - expect(deployment.findAll).to.be.equal(undefined) - expect(deployment.logs).to.not.equal(undefined) - expect(deployment.params.organization_uid).to.not.equal(undefined) - expect(deployment.signedDownloadUrl).to.not.equal(undefined) - expect(deployment.urlPath).to.be.equal(`/manifests/${appUid}/hosting/deployments/${uid}`) - done() - }) - - it('test get all deployment for hosting', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const organizationUid = appMock.organization_uid - mock.onGet(`manifests/${uid}/hosting/deployments`).reply(200, { - data: [latestLiveResponse.data] - }) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid }) - .findAll() - .then((deployments) => { - deployments.items.forEach(deployment => { - checkDeployment(deployment) - }) - done() - }) - .catch(done) - }) - - it('test create deployment from signed url', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const uploadUid = signedUrlResponse.data.upload_uid - const fileType = 'fileType' - const organizationUid = appMock.organization_uid - mock.onPost(`manifests/${uid}/hosting/deployments`).reply(200, { - data: { ...latestLiveResponse.data } - }) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid }) - .create({ uploadUid, fileType }) - .then((deployment) => { - checkDeployment(deployment) - done() - }) - .catch(done) - }) - it('test create deployment from signed url with advance options', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const uploadUid = signedUrlResponse.data.upload_uid - const fileType = 'fileType' - const organizationUid = appMock.organization_uid - mock.onPost(`manifests/${uid}/hosting/deployments`).reply(200, { - data: { ...latestLiveResponse.data } - }) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid }) - .create({ uploadUid, fileType, withAdvancedOptions: true }) - .then((deployment) => { - checkDeployment(deployment) - done() - }) - .catch(done) - }) - - it('test get deployment from uid', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const organizationUid = appMock.organization_uid - const deploymentUid = latestLiveResponse.data.uid - mock.onGet(`manifests/${uid}/hosting/deployments/${deploymentUid}`).reply(200, { - data: { ...latestLiveResponse.data } - }) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid, organization_uid: organizationUid } }) - .fetch() - .then((deployment) => { - checkDeployment(deployment) - done() - }) - .catch(done) - }) - - it('Failing test get deployment from uid', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const organizationUid = appMock.organization_uid - const deploymentUid = latestLiveResponse.data.uid - mock.onGet(`manifests/${uid}/hosting/deployments/${deploymentUid}`).reply(400, {}) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid, organization_uid: organizationUid } }) - .fetch() - .then() - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('test get deployment logs from uid', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const organizationUid = appMock.organization_uid - const deploymentUid = latestLiveResponse.data.uid - const content = { - message: 'No build command set', - stage: 'CREATING_BUILD', - timestamp: '2023-01-17T10:15:07.397Z' - } - mock.onGet(`manifests/${uid}/hosting/deployments/${deploymentUid}/logs`).reply(200, { - data: [content] - }) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid } }) - .logs() - .then((logs) => { - logs.forEach(log => { - expect(log.message).to.be.equal(content.message) - expect(log.stage).to.be.equal(content.stage) - expect(log.timestamp).to.be.equal(content.timestamp) - }) - done() - }) - .catch(done) - }) - - it('test get deployment logs from uid', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const organizationUid = appMock.organization_uid - const deploymentUid = latestLiveResponse.data.uid - mock.onGet(`manifests/${uid}/hosting/deployments/${deploymentUid}/logs`).reply(400, {}) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid } }) - .logs() - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) - - it('test get deployment logs from uid', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const organizationUid = appMock.organization_uid - const deploymentUid = latestLiveResponse.data.uid - const content = { - download_url: 'download_url', - expires_in: 900 - } - mock.onPost(`manifests/${uid}/hosting/deployments/${deploymentUid}/signedDownloadUrl`).reply(200, { - data: { ...content } - }) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid } }) - .signedDownloadUrl() - .then((download) => { - expect(download.download_url).to.be.equal(content.download_url) - expect(download.expires_in).to.be.equal(content.expires_in) - done() - }) - .catch(done) - }) - - it('Failing test get deployment logs from uid', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - const organizationUid = appMock.organization_uid - const deploymentUid = latestLiveResponse.data.uid - mock.onPost(`manifests/${uid}/hosting/deployments/${deploymentUid}/signedDownloadUrl`).reply(400, {}) - - makeDeployment({ app_uid: uid, organization_uid: organizationUid, data: { uid: deploymentUid } }) - .signedDownloadUrl() - .then(done) - .catch((error) => { - expect(error).to.not.equal(null) - done() - }) - }) -}) - -function makeDeployment (data, param = {}) { - return new Deployment(Axios, data, param) -} - -function checkDeployment (deployment) { - expect(deployment.created_at).to.be.equal(latestLiveResponse.data.created_at) - expect(deployment.deployment_number).to.be.equal(latestLiveResponse.data.deployment_number) - expect(deployment.deployment_url).to.be.equal(latestLiveResponse.data.deployment_url) - expect(deployment.environment).to.be.equal(latestLiveResponse.data.environment) - expect(deployment.latest).to.be.equal(latestLiveResponse.data.latest) - expect(deployment.preview_url).to.be.equal(latestLiveResponse.data.preview_url) - expect(deployment.status).to.be.equal(latestLiveResponse.data.status) - expect(deployment.uid).to.be.equal(latestLiveResponse.data.uid) - expect(deployment.updated_at).to.be.equal(latestLiveResponse.data.updated_at) -} diff --git a/test/unit/globalField-test.js b/test/unit/globalField-test.js index 8edaefa6..1764d196 100644 --- a/test/unit/globalField-test.js +++ b/test/unit/globalField-test.js @@ -10,7 +10,7 @@ describe('Contentstack GlobalField test', () => { it('GlobalField test without uid', (done) => { const globalField = makeGlobalField() expect(globalField.urlPath).to.be.equal('/global_fields') - expect(globalField.stackHeaders).to.be.equal(undefined) + expect(globalField.stackHeaders).to.deep.equal({}) expect(globalField.update).to.be.equal(undefined) expect(globalField.delete).to.be.equal(undefined) expect(globalField.fetch).to.be.equal(undefined) @@ -25,10 +25,9 @@ describe('Contentstack GlobalField test', () => { ...systemUidMock } }) - expect(globalField.urlPath).to.be.equal( - `/global_fields/${systemUidMock.uid}` - ) - expect(globalField.stackHeaders).to.be.equal(undefined) + + expect(globalField.urlPath).to.be.equal(`/global_fields/${systemUidMock.uid}`) + expect(globalField.stackHeaders).to.deep.equal({}) expect(globalField.update).to.not.equal(undefined) expect(globalField.delete).to.not.equal(undefined) expect(globalField.fetch).to.not.equal(undefined) @@ -218,10 +217,11 @@ describe('Contentstack GlobalField test', () => { describe('Contentstack GlobalField test (API Version 3.2)', () => { it('GlobalField test without uid', (done) => { const globalField = makeGlobalField({ - stackHeaders: stackHeadersMock, - api_version: '3.2' }) - expect(globalField.urlPath).to.be.equal('/global_fields') - expect(globalField.stackHeaders.api_version).to.be.equal('3.2') + stackHeaders: { api_key: 'api_key', api_version: '3.2' } + }) + + expect(globalField.urlPath).to.equal('/global_fields') + expect(globalField.stackHeaders.api_version).to.equal('3.2') expect(globalField.stackHeaders).to.deep.equal({ api_key: 'api_key', api_version: '3.2' }) done() }) @@ -231,8 +231,7 @@ describe('Contentstack GlobalField test (API Version 3.2)', () => { global_field: { ...systemUidMock }, - stackHeaders: stackHeadersMock, - api_version: '3.2' + stackHeaders: { api_key: 'api_key', api_version: '3.2' } }) expect(globalField.urlPath).to.be.equal( `/global_fields/${systemUidMock.uid}` @@ -251,8 +250,7 @@ describe('Contentstack GlobalField test (API Version 3.2)', () => { global_field: { ...systemUidMock }, - stackHeaders: stackHeadersMock, - api_version: '3.2' + stackHeaders: { api_key: 'api_key', api_version: '3.2' } }) expect(globalField.urlPath).to.be.equal( `/global_fields/${systemUidMock.uid}` diff --git a/test/unit/hosting-test.js b/test/unit/hosting-test.js deleted file mode 100644 index 973e4ce3..00000000 --- a/test/unit/hosting-test.js +++ /dev/null @@ -1,163 +0,0 @@ -import Axios from 'axios' -import { expect } from 'chai' -import { describe, it } from 'mocha' -import MockAdapter from 'axios-mock-adapter' -import { appMock } from './mock/objects' -import { Hosting } from '../../lib/app/hosting' -import { latestLiveResponse, signedUrlResponse } from './mock/hosting-mock' - -describe('Contentstack hosting test', () => { - it('Hosting without contents', done => { - const hosting = makeHosting() - expect(hosting).to.not.equal(undefined) - expect(hosting.createUploadUrl).to.be.equal(undefined) - expect(hosting.deployment).to.be.equal(undefined) - expect(hosting.disable).to.be.equal(undefined) - expect(hosting.enable).to.be.equal(undefined) - expect(hosting.isEnable).to.be.equal(undefined) - expect(hosting.latestLiveDeployment).to.be.equal(undefined) - expect(hosting.params).to.not.equal(undefined) - expect(hosting.urlPath).to.be.equal(undefined) - done() - }) - it('Hosting without app uid', done => { - const hosting = makeHosting({}) - expect(hosting).to.not.equal(undefined) - expect(hosting.createUploadUrl).to.be.equal(undefined) - expect(hosting.deployment).to.be.equal(undefined) - expect(hosting.disable).to.be.equal(undefined) - expect(hosting.enable).to.be.equal(undefined) - expect(hosting.isEnable).to.be.equal(undefined) - expect(hosting.latestLiveDeployment).to.be.equal(undefined) - expect(hosting.params).to.not.equal(undefined) - expect(hosting.urlPath).to.be.equal(undefined) - done() - }) - - it('Hosting with app uid', done => { - const appUid = 'APP_UID' - const hosting = makeHosting({ app_uid: appUid }) - expect(hosting).to.not.equal(undefined) - expect(hosting.createUploadUrl).to.not.equal(undefined) - expect(hosting.deployment).to.not.equal(undefined) - expect(hosting.disable).to.not.equal(undefined) - expect(hosting.enable).to.not.equal(undefined) - expect(hosting.isEnable).to.not.equal(undefined) - expect(hosting.latestLiveDeployment).to.not.equal(undefined) - expect(hosting.params).to.not.equal(undefined) - expect(hosting.urlPath).to.be.equal(`/manifests/${appUid}/hosting`) - expect(hosting.deployment()).to.not.equal(undefined) - expect(hosting.deployment('uid')).to.not.equal(undefined) - done() - }) - - it('Hosting with app uid and org uid', done => { - const appUid = 'APP_UID' - const organizationUid = 'ORG_UID' - const hosting = makeHosting({ app_uid: appUid, organization_uid: organizationUid }) - expect(hosting).to.not.equal(undefined) - expect(hosting.createUploadUrl).to.not.equal(undefined) - expect(hosting.deployment).to.not.equal(undefined) - expect(hosting.disable).to.not.equal(undefined) - expect(hosting.enable).to.not.equal(undefined) - expect(hosting.isEnable).to.not.equal(undefined) - expect(hosting.latestLiveDeployment).to.not.equal(undefined) - expect(hosting.params.organization_uid).to.be.equal(organizationUid) - expect(hosting.urlPath).to.be.equal(`/manifests/${appUid}/hosting`) - done() - }) - - it('test hosting is enable request', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onGet(`manifests/${uid}/hosting`).reply(200, { - data: { enabled: false } - }) - - makeHosting({ app_uid: uid }) - .isEnable() - .then((response) => { - expect(response.data.enabled).to.be.equal(false) - done() - }) - .catch(done) - }) - - it('test set hosting enable', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPatch(`manifests/${uid}/hosting/enable`).reply(200, { - data: { enabled: true } - }) - - makeHosting({ app_uid: uid }) - .enable() - .then((response) => { - expect(response.data.enabled).to.be.equal(true) - done() - }) - .catch(done) - }) - - it('test set hosting disble', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPatch(`manifests/${uid}/hosting/disable`).reply(200, { - data: { enabled: false } - }) - - makeHosting({ app_uid: uid }) - .disable() - .then((response) => { - expect(response.data.enabled).to.be.equal(false) - done() - }) - .catch(done) - }) - - it('test create signed url for hosting', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPost(`manifests/${uid}/hosting/signedUploadUrl`).reply(200, { - ...signedUrlResponse - }) - - makeHosting({ app_uid: uid }) - .createUploadUrl() - .then((response) => { - expect(response.data.upload_uid).to.be.equal(signedUrlResponse.data.upload_uid) - expect(response.data.upload_url).to.be.equal(signedUrlResponse.data.upload_url) - expect(response.data.expires_in).to.be.equal(signedUrlResponse.data.expires_in) - done() - }) - .catch(done) - }) - - it('test latest deployment for hosting', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onGet(`manifests/${uid}/hosting/latestLiveDeployment`).reply(200, { - ...latestLiveResponse - }) - - makeHosting({ app_uid: uid }) - .latestLiveDeployment() - .then((deployment) => { - expect(deployment.created_at).to.be.equal(latestLiveResponse.data.created_at) - expect(deployment.deployment_number).to.be.equal(latestLiveResponse.data.deployment_number) - expect(deployment.deployment_url).to.be.equal(latestLiveResponse.data.deployment_url) - expect(deployment.environment).to.be.equal(latestLiveResponse.data.environment) - expect(deployment.latest).to.be.equal(latestLiveResponse.data.latest) - expect(deployment.preview_url).to.be.equal(latestLiveResponse.data.preview_url) - expect(deployment.status).to.be.equal(latestLiveResponse.data.status) - expect(deployment.uid).to.be.equal(latestLiveResponse.data.uid) - expect(deployment.updated_at).to.be.equal(latestLiveResponse.data.updated_at) - done() - }) - .catch(done) - }) -}) - -function makeHosting (data, param = {}) { - return new Hosting(Axios, data, param) -} diff --git a/test/unit/index.js b/test/unit/index.js index 6cafbd0c..0e40df62 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -27,12 +27,6 @@ require('./environment-test') require('./locale-test') require('./deliveryToken-test') require('./entry-test') -require('./apps-test') -require('./installation-test') -require('./hosting-test') -require('./deployment-test') -require('./app-request-test') -require('./authorization-test') require('./auditLog-test') require('./taxonomy-test') require('./terms-test') diff --git a/test/unit/installation-test.js b/test/unit/installation-test.js deleted file mode 100644 index 811237dc..00000000 --- a/test/unit/installation-test.js +++ /dev/null @@ -1,249 +0,0 @@ -import Axios from 'axios' -import { expect } from 'chai' -import { App } from '../../lib/app' -import { describe, it } from 'mocha' -import MockAdapter from 'axios-mock-adapter' -import { appInstallMock, appMock, installationMock } from './mock/objects' -import { Installation } from '../../lib/app/installation' - -describe('Contentstack apps installation test', () => { - it('Installation without installation uid', done => { - const installation = makeInstallation({}) - expect(installation.urlPath).to.be.equal(undefined) - expect(installation.fetch).to.be.equal(undefined) - expect(installation.update).to.be.equal(undefined) - expect(installation.uninstall).to.be.equal(undefined) - expect(installation.findAll).to.be.equal(undefined) - expect(installation.installationData).to.be.equal(undefined) - expect(installation.configuration).to.be.equal(undefined) - expect(installation.setConfiguration).to.be.equal(undefined) - expect(installation.serverConfig).to.be.equal(undefined) - expect(installation.setServerConfig).to.be.equal(undefined) - done() - }) - - it('Installation with app uid', done => { - const uid = appMock.uid - const installation = makeInstallation({ app_uid: uid }) - expect(installation.urlPath).to.be.equal(`manifests/${uid}/installations`) - expect(installation.fetch).to.be.equal(undefined) - expect(installation.update).to.be.equal(undefined) - expect(installation.uninstall).to.be.equal(undefined) - expect(installation.installationData).to.be.equal(undefined) - expect(installation.configuration).to.be.equal(undefined) - expect(installation.setConfiguration).to.be.equal(undefined) - expect(installation.serverConfig).to.be.equal(undefined) - expect(installation.setServerConfig).to.be.equal(undefined) - expect(installation.findAll).to.not.equal(undefined) - done() - }) - - it('Installation with installation uid', done => { - const uid = installationMock.uid - const installation = makeInstallation({ data: { uid } }) - expect(installation.urlPath).to.be.equal(`/installations/${uid}`) - expect(installation.fetch).to.not.equal(undefined) - expect(installation.update).to.not.equal(undefined) - expect(installation.uninstall).to.not.equal(undefined) - expect(installation.installationData).to.not.equal(undefined) - expect(installation.configuration).to.not.equal(undefined) - expect(installation.setConfiguration).to.not.equal(undefined) - expect(installation.serverConfig).to.not.equal(undefined) - expect(installation.setServerConfig).to.not.equal(undefined) - expect(installation.findAll).to.be.equal(undefined) - done() - }) - - it('Params for installation', done => { - const installation = makeInstallation({}) - expect(installation.params).to.deep.equal({}) - done() - }) - - it('Organization uid params for installation', done => { - const organizationUid = 'org_uid' - const installation = makeInstallation({}, { organization_uid: organizationUid }) - expect(installation.params.organization_uid).to.be.equal(organizationUid) - done() - }) - - it('Params in data for installation', done => { - const organizationUid = 'org_uid' - const installation = makeInstallation({ data: { organization_uid: organizationUid } }) - expect(installation.params.organization_uid).to.be.equal(organizationUid) - done() - }) - - it('Install app test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onPost(`/manifests/${uid}/install`).reply(200, { - data: { - ...appInstallMock - } - }) - const app = new App(Axios, { data: { uid } }) - app - .install({ targetType: 'stack', targetUid: 'STACK_UID' }) - .then((installation) => { - expect(installation.status).to.be.equal(appInstallMock.status) - expect(installation.uid).to.be.equal(appInstallMock.installation_uid) - expect(installation.redirect_to).to.be.equal(appInstallMock.redirect_to) - expect(installation.redirect_uri).to.be.equal(appInstallMock.redirect_uri) - done() - }) - .catch(done) - }) - - it('Get app installation test', done => { - const mock = new MockAdapter(Axios) - const uid = appMock.uid - mock.onGet(`manifests/${uid}/installations`).reply(200, { - data: [installationMock] - }) - - makeInstallation({ app_uid: uid }) - .findAll() - .then((installations) => { - installations.items.forEach(installation => { - checkInstallation(installation) - }) - done() - }) - .catch(done) - }) - - it('Fetch Installation test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onGet(`/installations/${uid}`).reply(200, { - data: installationMock - }) - - makeInstallation({ data: { uid } }) - .fetch() - .then((installation) => { - checkInstallation(installation) - done() - }) - .catch(done) - }) - - it('Get installation installationData test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onGet(`/installations/${uid}/installationData`).reply(200, { - data: {} - }) - - makeInstallation({ data: { uid } }) - .installationData() - .then((data) => { - expect(data).to.not.equal(null) - done() - }) - .catch(done) - }) - - it('Get installation configuration test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onGet(`/installations/${uid}/configuration`).reply(200, { - data: {} - }) - - makeInstallation({ data: { uid } }) - .configuration() - .then((data) => { - expect(data).to.not.equal(null) - done() - }) - .catch(done) - }) - it('Set installation configuration test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onPut(`/installations/${uid}/configuration`).reply(200, { - data: {} - }) - - makeInstallation({ data: { uid } }) - .setConfiguration({}) - .then((data) => { - expect(data).to.not.equal(null) - done() - }) - .catch(done) - }) - it('Get installation server config test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onGet(`/installations/${uid}/server-configuration`).reply(200, { - data: {} - }) - - makeInstallation({ data: { uid } }) - .serverConfig() - .then((data) => { - expect(data).to.not.equal(null) - done() - }) - .catch(done) - }) - it('Get installation installationData test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onPut(`/installations/${uid}/server-configuration`).reply(200, { - data: {} - }) - - makeInstallation({ data: { uid } }) - .setServerConfig({}) - .then((data) => { - expect(data).to.not.equal(null) - done() - }) - .catch(done) - }) - - it('Update Installation test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onPut(`/installations/${uid}`).reply(200, { - data: installationMock - }) - makeInstallation({ data: { uid } }) - .update() - .then((installation) => { - checkInstallation(installation) - done() - }) - .catch(done) - }) - - it('Uninstall Installation test', done => { - const mock = new MockAdapter(Axios) - const uid = installationMock.uid - mock.onDelete(`/installations/${uid}`).reply(200, { - - }) - makeInstallation({ data: { uid } }) - .uninstall() - .then(() => { - done() - }) - .catch(done) - }) -}) - -function checkInstallation (installation) { - expect(installation.status).to.be.equal(installationMock.status) - expect(installation.uid).to.be.equal(installationMock.uid) - expect(installation.organization_uid).to.be.equal(installationMock.organization_uid) - expect(installation.target.type).to.be.equal(installationMock.target.type) - expect(installation.target.uid).to.be.equal(installationMock.target.uid) -} - -function makeInstallation (data, param = {}) { - return new Installation(Axios, data, param) -} diff --git a/test/unit/mock/hosting-mock.js b/test/unit/mock/hosting-mock.js deleted file mode 100644 index 19d5ad10..00000000 --- a/test/unit/mock/hosting-mock.js +++ /dev/null @@ -1,33 +0,0 @@ -const signedUrlResponse = { - data: { - upload_uid: 'upload_uid', - form_fields: [ - { - key: 'key', - value: 'value' - } - ], - upload_url: 'upload_url', - expires_in: 900 - } -} -const latestLiveResponse = { - data: - { - created_at: '2023-01-17T10:07:13.215Z', - deployment_number: 1, - deployment_url: 'deployment_url', - environment: 'environment', - latest: true, - preview_url: 'preview_url', - status: 'DEPLOYED', - uid: 'uid', - updated_at: '2023-01-17T10:15:11.360Z' - } - -} - -export { - signedUrlResponse, - latestLiveResponse -} diff --git a/test/unit/mock/objects.js b/test/unit/mock/objects.js index 7376088c..501d66fe 100644 --- a/test/unit/mock/objects.js +++ b/test/unit/mock/objects.js @@ -26,9 +26,11 @@ const variantBaseEntryMock = { const noticeMock = { notice: 'Notice' } + const systemUidMock = { uid: 'UID' } + const systemFieldsMock = { created_at: 'created_at_date', updated_at: 'updated_at_date', @@ -148,6 +150,7 @@ const roleMock = { ...adminRoleMock, admin: false } + const roleMockWithTaxonomy = { ...systemFieldsMock, ...systemFieldsUserMock, @@ -284,6 +287,7 @@ const releaseItemMock = { action: 'publish', locale: 'en-us' } + const releaseMock = { ...systemFieldsMock, ...systemFieldsUserMock, @@ -401,6 +405,7 @@ const contentTypeMock = { } ] } + const globalFieldMock = { ...systemFieldsMock, ...systemFieldsUserMock, @@ -460,6 +465,7 @@ const nestedGlobalFieldMock = { } ] } + const nestedGlobalFieldPayload = { global_field: { title: 'Nested Global Field 12345', @@ -549,6 +555,7 @@ const variantsEntriesMock = { base_entry_version: 1 } } + const variantsUpdateEntryMock = { title: 'title', url: '/url', @@ -562,6 +569,7 @@ const variantsUpdateEntryMock = { created_at: 'created_at_date', updated_at: 'updated_at_date' } + const variantsEntryMock = { title: 'title', url: '/url', @@ -695,146 +703,6 @@ const userAssignments = { } } -const appMock = { - framework_version: '1.0', - version: 1, - icon: 'icon', - description: 'Description of the app', - target_type: 'stack', - name: 'Name of the app', - ui_location: { - signed: true, - base_url: 'base_url', - locations: [ - { - type: 'cs.cm.stack.config', - meta: [ - { - signed: true, - path: '/config', - name: 'Configuration' - } - ] - }, - { - type: 'cs.cm.stack.custom_field', - meta: [ - { - signed: true, - path: '/custom-field', - name: 'Field', - data_type: 'text' - } - ] - } - ] - }, - webhook: { - signed: true, - name: 'Algolia', - enabled: true, - target_url: 'target_url', - channels: [ - ], - app_lifecycle_enabled: true, - retry_policy: 'manual' - }, - visibility: 'private', - organization_uid: 'org_uid', - created_at: 'created_at_date', - updated_at: 'updated_at_date', - uid: 'UID', - oauth: { - redirect_uri: 'redirect_url', - app_token_config: { - enabled: true, - scopes: [ - 'user:read', - 'user:write', - 'user.profile:read' - ] - }, - user_token_config: { - enabled: true, - scopes: [ - 'user.profile:read' - ] - } - } -} - -const oAuthMock = { - client_id: 'client_id', - client_secret: 'client_secret', - redirect_uri: 'http://localhost:5000/callback', - app_token_config: { - enabled: true, - scopes: [ - 'user:read', - 'user:write', - 'user.profile:read' - ] - }, - user_token_config: { - enabled: true, - scopes: [ - 'user.profile:read' - ] - } -} - -const appInstallMock = { - status: 'installed', - installation_uid: 'installationUID', - redirect_to: 'config', - redirect_uri: 'redirect_uri' -} - -const installationMock = { - status: 'installed', - manifest: { - framework_version: '1.0', - version: 1, - icon: '', - description: '', - target_type: 'stack', - name: 'Post man test 2', - visibility: 'private', - created_by: { - uid: 'user_uid', - first_name: 'user_name', - last_name: 'user_last_name' - }, - updated_by: { - uid: 'user_uid', - first_name: 'user_name', - last_name: 'user_last_name' - }, - organization_uid: 'org_uid', - created_at: 'date_time', - updated_at: 'date_time', - uid: 'installation_uid' - }, - created_by: { - uid: 'user_uid', - first_name: 'user_name', - last_name: 'user_last_name' - }, - updated_by: { - uid: 'user_uid', - first_name: 'user_name', - last_name: 'user_last_name' - }, - target: { - type: 'stack', - uid: '{{stackUid}}' - }, - organization_uid: 'org_uid', - created_at: 'date_time', - updated_at: 'date_time', - uid: 'installation_uid' -} - const globalFieldDiff = [{ uid: 'global_field_uid', title: 'Global Field Title', @@ -987,6 +855,7 @@ const taxonomyMock = { referenced_terms_count: 3, referenced_entries_count: 6 } + const termsMock = { taxonomy_uid: 'taxonomy_uid', uid: 'UID', @@ -1028,6 +897,7 @@ const termsMock = { referenced_entries_count: 4 }] } + const teamsMock = { uid: 'UID', name: 'name', @@ -1036,6 +906,7 @@ const teamsMock = { stackRoleMapping: [], organizationRole: 'organizationRole' } + const teamUsersMock = { users: ['user1', 'user2', 'UID'], addUser: { @@ -1215,10 +1086,6 @@ function checkSystemFields (object) { } export { - appMock, - oAuthMock, - appInstallMock, - installationMock, errorMock, noticeMock, stackMock, diff --git a/test/unit/mock/request-mock.js b/test/unit/mock/request-mock.js deleted file mode 100644 index ce1b4d9e..00000000 --- a/test/unit/mock/request-mock.js +++ /dev/null @@ -1,36 +0,0 @@ -const requestMock = { - organization_uid: 'org_uid', - manifest: { - uid: 'app_uid', - name: 'Awesome App', - description: '', - icon: '', - visibility: 'private', - target_type: 'stack', - organization_uid: 'org_uid', - framework_version: '1.0', - version: 1, - created_by: { - uid: 'user_uid', - first_name: 'John', - last_name: 'Doe' - }, - updated_by: { - uid: 'user_uid', - first_name: 'John', - last_name: 'Doe' - }, - created_at: '2022-02-11T08:43:59.837Z', - updated_at: '2022-02-11T08:43:59.837Z' - }, - requested_by: { - uid: 'user_request_uid', - first_name: 'sample', - last_name: 'user' - }, - target_uid: 'target_uid', - created_at: '2023-01-17T09:40:20.464Z', - updated_at: '2023-01-17T09:40:20.464Z', - uid: 'request_uid' -} -export { requestMock } diff --git a/test/unit/organization-test.js b/test/unit/organization-test.js index f2340ffd..5775a94f 100644 --- a/test/unit/organization-test.js +++ b/test/unit/organization-test.js @@ -297,8 +297,6 @@ function checknonAdminFunction (organization) { expect(organization.getInvitations).to.not.equal(undefined) expect(organization.resendInvitation).to.not.equal(undefined) expect(organization.roles).to.not.equal(undefined) - expect(organization.app()).to.not.equal(undefined) - expect(organization.appRequest()).to.not.equal(undefined) } function checkAdminFunction (organization) { diff --git a/types/app/authorization.d.ts b/types/app/authorization.d.ts deleted file mode 100644 index 299929f3..00000000 --- a/types/app/authorization.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { AnyProperty } from '../utility/fields'; - -export interface Authorization { - findAll(param?: AnyProperty): Promise - revokeAll(): Promise - revoke(authorizationUid: string): Promise -} \ No newline at end of file diff --git a/types/app/hosting.d.ts b/types/app/hosting.d.ts deleted file mode 100644 index 0dd07f87..00000000 --- a/types/app/hosting.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { AnyProperty, SystemFields } from '../utility/fields'; -import { ContentstackCollection } from '../contentstackCollection' -export interface Hosting { - isEnable(): Promise - enable(): Promise - disable(): Promise - createUploadUrl(): Promise - deployment(): Deployments - deployment(uid: string): Deployment - latestLiveDeployment(): Promise -} - -export interface UploadDetails { - upload_uid: string - form_fields: AnyProperty[] - upload_url: string - expires_in: number -} - -export interface Deployments { - create(data: { uploadUid: string , fileType: string, withAdvancedOptions?: boolean}): Promise - findAll(param?: AnyProperty): Promise> -} - -export interface Deployment extends SystemFields { - fetch(): Promise - logs(): Promise - signedDownloadUrl(): Promise -} - -export interface DownloadDetails { - download_url: string - expires_in: number -} -export interface DeploymentLog{ - message: string - stage: string - timestamp: string -} \ No newline at end of file diff --git a/types/app/index.d.ts b/types/app/index.d.ts deleted file mode 100644 index c8a0760f..00000000 --- a/types/app/index.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { ContentstackCollection } from "../contentstackCollection"; -import { AnyProperty, SystemFields } from "../utility/fields"; -import { Creatable, SystemFunction } from "../utility/operations"; -import { Pagination } from '../utility/pagination'; -import { Authorization } from './authorization'; -import { Hosting } from './hosting'; -import { Installation, Installations } from "./installation"; - -export interface App extends SystemFields, SystemFunction { - fetchOAuth(param?: AnyProperty): Promise - updateOAuth(data: { config: AppOAuth, param?: AnyProperty }): Promise - install(data: {targetUid: string, targetType: AppTarget}): Promise - installation(): Installations - installation(uid: string): Installation - hosting(): Hosting - authorize(param: { - responseType: string, - clientId: string, - redirectUri: string, - scope: string, - state: string }): Promise - authorization(): Authorization -} - -export interface Apps extends Creatable { - findAll(param?: AnyProperty): Promise> - findAllAuthorized(param?: Pagination & AnyProperty): Promise -} - -export interface AppData extends AnyProperty { - name: string - description?: string - icon?: string - target_type: AppTarget - ui_location?: UILocation - webhook?: AppWebhook | AppWebhookChannel - oauth?: AppOAuth -} - -export interface AppOAuth extends AnyProperty { - redirect_uri?: string - app_token_config?: TokenConfig - user_token_config?: UserTokenConfig -} - -export interface TokenConfig extends AnyProperty { - enabled: boolean - scopes: string[] -} -export interface UserTokenConfig extends TokenConfig { - allow_pkce: boolean -} - -export interface AppWebhookChannel extends AppWebhook { - target_url: string - channels: string[] -} - -export interface AppWebhook extends AnyProperty { - signed: boolean - name: string - enabled?: boolean - app_lifecycle_enabled?: boolean - retry_policy?: string -} - -export interface UILocation extends AnyProperty { - signed: boolean - base_url?: string - locations: Location[] -} - -export interface Location extends AnyProperty { - type: string - meta: LocationMeta[] -} - -export interface LocationMeta extends AnyProperty { - signed: boolean - path: string - name: string - data_type?: string -} - -export type AppTarget = - | 'stack' - | 'organization' \ No newline at end of file diff --git a/types/app/installation.d.ts b/types/app/installation.d.ts deleted file mode 100644 index e3f5e1b9..00000000 --- a/types/app/installation.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ContentstackCollection } from "../contentstackCollection"; -import { AnyProperty, SystemFields } from "../utility/fields"; - -export interface Installation extends SystemFields { - update(param?: AnyProperty): Promise - fetch(param?: AnyProperty): Promise - uninstall(param?: AnyProperty): Promise - configuration(param?: AnyProperty): Promise - setConfiguration(config: AnyProperty): Promise - serverConfig(param?: AnyProperty): Promise - setServerConfig(config: AnyProperty): Promise - installationData(): Promise -} - -export interface Installations { - findAll(param?: AnyProperty): Promise> -} \ No newline at end of file diff --git a/types/app/request.d.ts b/types/app/request.d.ts deleted file mode 100644 index d7a89a5f..00000000 --- a/types/app/request.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { AnyProperty } from '../utility/fields'; - -export interface AppRequest { - create(params: {appUid: string, targetUid: string}): Promise - delete(requestUid: string): Promise - findAll(param?: AnyProperty): Promise -} \ No newline at end of file diff --git a/types/organization.d.ts b/types/organization.d.ts index 3dc040c3..aa645b6f 100644 --- a/types/organization.d.ts +++ b/types/organization.d.ts @@ -5,8 +5,6 @@ import { Sorting } from './utility/sorting' import { Pagination } from './utility/pagination' import { AnyProperty, SystemFields } from './utility/fields' import { ContentstackCollection, Response } from './contentstackCollection' -import { App, Apps } from './app' -import { AppRequest } from './app/request' import { Team, Teams } from './teams' export interface Organizations { @@ -23,9 +21,6 @@ export interface Organization extends SystemFields { getInvitations(param?: Pagination & AnyProperty): Promise> resendInvitation(invitationUid: string): Promise roles(param?: Pagination & AnyProperty): Promise> - app(): Apps - app(uid: string): App - appRequest(): AppRequest teams(): Teams teams(uid: string): Team } diff --git a/types/stack/index.d.ts b/types/stack/index.d.ts index f0344b38..055ab895 100644 --- a/types/stack/index.d.ts +++ b/types/stack/index.d.ts @@ -63,8 +63,9 @@ export interface Stack extends SystemFields { globalField(): GlobalFields; globalField(uid: string, option?: object): GlobalField; - globalField(options: { api_version: string }): GlobalFields; - globalField(uidOrOptions?: string | { api_version: string }, option?: object): GlobalFields | GlobalField; + globalField(options: object): GlobalFields; + globalField(uidOrOptions?: string | object, option?: object): GlobalFields | GlobalField; +