Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #115

Merged
merged 5 commits into from
Jan 24, 2024
Merged

Next #115

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Changelog
## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13)
## [v1.15.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.0) (2024-01-23)
- Feature
- Taxonomy Import/Export feature added
## [v1.14.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.1) (2024-11-23)
- Fixes
- Fix for issue while updating entries with assets

- Fix for validating the data while updating entries with assets
## [v1.14.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.0) (2023-12-19)
- Feature
- Management token feature added
## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13)
- Fixes
- Fix for issue while updating entries with assets
## [v1.13.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.0) (2023-11-21)
- Feature
- Teams API support
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset })
- [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api)

### The MIT License (MIT)
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved
Copyright © 2012-2024 [Contentstack](https://www.contentstack.com/). All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function isAsset (data) {
}

export function cleanAssets (data) {
if (typeof data === "object" && Object.keys(data).length > 0) {
if (data && typeof data === "object" && Object.keys(data).length > 0) {
const keys = Object.keys(data);
for (const key of keys) {
if (typeof data[key] === "object" && Object.keys(data[key]).length > 0) {
Expand Down
82 changes: 81 additions & 1 deletion lib/stack/taxonomy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import {
fetch,
query,
update,
deleteEntity
deleteEntity,
upload,
parseData
} from '../../entity'
import { Terms, TermsCollection } from './terms'
import FormData from 'form-data'
import { createReadStream } from 'fs'
import error from '../../core/contentstackError'

export function Taxonomy (http, data = {}) {
this.stackHeaders = data.stackHeaders
Expand Down Expand Up @@ -69,6 +74,36 @@ export function Taxonomy (http, data = {}) {
*/
this.fetch = fetch(http, 'taxonomy')

/**
* @description The Export taxonomy call is used to export an existing taxonomy.
* @memberof Taxonomy
* @func export
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').export()
* .then((taxonomy) => console.log(taxonomy))
*
*/
this.export = async () => {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) }
}
const response = await http.get(`${this.urlPath}/export`, headers)
if (response.data) {
return response.data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}


this.terms = (uid = '') => {
const data = { stackHeaders: this.stackHeaders }
data.taxonomy_uid = this.uid
Expand Down Expand Up @@ -113,6 +148,42 @@ export function Taxonomy (http, data = {}) {
* .then((taxonomies) => console.log(taxonomies)
*/
this.query = query({ http: http, wrapperCollection: TaxonomyCollection })

/**
* @description The 'Import taxonomy' import a single entry by uploading JSON or CSV files.
* @memberof Taxonomy
* @func import
* @param {String} data.taxonomy path to file
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* const data = {
* taxonomy: 'path/to/file.json',
* }
* // Import a Taxonomy
* client.stack({ api_key: 'api_key'}).taxonomy().import(data)
* .then((taxonomy) => console.log(taxonomy))
*/
this.import = async function (data, params = {}) {
try {
const response = await upload({
http: http,
urlPath: `${this.urlPath}/import`,
stackHeaders: this.stackHeaders,
formData: createFormData(data),
params: params
})
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders))
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}

}
}
export function TaxonomyCollection (http, data) {
Expand All @@ -122,3 +193,12 @@ export function TaxonomyCollection (http, data) {
})
return taxonomyCollection
}

export function createFormData (data) {
return () => {
const formData = new FormData()
const uploadStream = createReadStream(data.taxonomy)
formData.append('taxonomy', uploadStream)
return formData
}
}
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.14.1",
"version": "1.15.0",
"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",
Expand Down Expand Up @@ -30,8 +30,8 @@
"buildnativescript": "webpack --config webpack/webpack.nativescript.js --mode production",
"buildweb": "webpack --config webpack/webpack.web.js --mode production",
"test": "npm run test:api && npm run test:unit",
"test:sanity": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill",
"test:sanity-report": "node sanity-report.mjs",
"test:sanity": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json && marge mochawesome-report/mochawesome.json -f sanity-report.html --inline",
"test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs",
"test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill",
"test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill",
"test:unit:report:json": "BABEL_ENV=test nyc --reporter=clover --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter json --reporter-options output=report.json --require babel-polyfill",
Expand Down Expand Up @@ -92,6 +92,7 @@
"jest": "^28.1.0",
"jsdoc": "^4.0.2",
"mocha": "^9.2.2",
"mocha-html-reporter": "^0.0.1",
"mochawesome": "^7.1.3",
"multiparty": "^4.2.3",
"nock": "^10.0.6",
Expand Down
31 changes: 21 additions & 10 deletions sanity-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,53 @@ dotenv.config()

const mochawesomeJsonOutput = fs.readFileSync('./mochawesome-report/mochawesome.json', 'utf-8')
const mochawesomeReport = JSON.parse(mochawesomeJsonOutput)
const report = `./mochawesome-report/sanity-report.html`

const totalSuites = mochawesomeReport.stats.suites
const totalTests = mochawesomeReport.stats.tests
const passedTests = mochawesomeReport.stats.passes
const failedTests = mochawesomeReport.stats.failures
const pendingTests = mochawesomeReport.stats.pending
const durationInSeconds = mochawesomeReport.stats.duration / 1000
let durationInSeconds = mochawesomeReport.stats.duration / 1000
const durationInMinutes = Math.floor(durationInSeconds / 60)
durationInSeconds %= 60

console.log(`Total Suites: ${totalSuites}`)
console.log(`Total Tests: ${totalTests}`)
console.log(`Passed Tests: ${passedTests}`)
console.log(`Failed Tests: ${failedTests}`)
console.log(`Pending Tests: ${pendingTests}`)
console.log(`Total Duration: ${durationInSeconds.toFixed(2)} seconds`)
console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`)

const slackMessage = `
*Test Summary*
Total Suites: ${totalSuites}
Total Tests: ${totalTests}
Passed Tests: ${passedTests}
Failed Tests: ${failedTests}
Pending Tests: ${pendingTests}
Total Duration: ${durationInSeconds.toFixed(2)} seconds
Total Suites: *${totalSuites}*
Total Tests: *${totalTests}*
Passed Tests: *${passedTests}*
Failed Tests: *${failedTests}*
Pending Tests: *${pendingTests}*
Total Duration: *${durationInMinutes}m ${durationInSeconds.toFixed(2)}s*
`

const app = new Slack.App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
})

async function publishMessage (text) {
async function publishMessage (text, report) {
await app.client.chat.postMessage({
token: process.env.SLACK_BOT_TOKEN,
channel: process.env.SLACK_CHANNEL,
text: text
})
await app.client.files.upload({
token: process.env.SLACK_BOT_TOKEN,
channels: process.env.SLACK_CHANNEL,
initial_comment: '*Here is the report generated*',
filetype: 'html',
filename: 'sanity-report.html',
file: fs.createReadStream(report)
})
}

publishMessage(slackMessage)
publishMessage(slackMessage, report)
Empty file.
68 changes: 68 additions & 0 deletions test/sanity-check/api/delete-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { environmentCreate, environmentProdCreate } from '../mock/environment.js'
import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}

describe('Delete Environment api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should delete an environment', done => {
makeEnvironment(environmentCreate.environment.name)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Environment deleted successfully.')
done()
})
.catch(done)
})

it('should delete the prod environment', done => {
makeEnvironment(environmentProdCreate.environment.name)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Environment deleted successfully.')
done()
})
.catch(done)
})
})

describe('Delete Locale api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})

it('should delete language: Hindi - India', done => {
makeLocale('hi-in')
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Language removed successfully.')
done()
})
.catch(done)
})

it('should delete language: English - Austria', done => {
makeLocale('en-at')
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Language removed successfully.')
done()
})
.catch(done)
})
})

function makeEnvironment (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
}

function makeLocale (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).locale(uid)
}
Loading
Loading