Skip to content

Commit

Permalink
feat: ✨ adds params support in taxonomy export function
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeem-cs committed Feb 2, 2024
1 parent a5fa8dc commit 3e990e5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threshold: medium
fileignoreconfig:
- filename: package-lock.json
checksum: 2a2327aabd3f6eacf41a8e8bb3dd5afdab892683cfd15aac308f43c14108b824
checksum: 9d0340f9359927d477fe8ab4650642c068c592be63fb817651d866849e0dbbc2
version: ""
9 changes: 4 additions & 5 deletions lib/stack/taxonomy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ export function Taxonomy (http, data = {}) {
* .then((taxonomy) => console.log(taxonomy))
*
*/
this.export = async () => {
this.export = async (params = {}) => {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) }
headers: { ...cloneDeep(this.stackHeaders) },
params
}
const response = await http.get(`${this.urlPath}/export`, headers)
if (response.data) {
Expand All @@ -103,7 +104,6 @@ export function Taxonomy (http, data = {}) {
}
}


this.terms = (uid = '') => {
const data = { stackHeaders: this.stackHeaders }
data.taxonomy_uid = this.uid
Expand Down Expand Up @@ -183,7 +183,6 @@ export function Taxonomy (http, data = {}) {
throw error(err)
}
}

}
}
export function TaxonomyCollection (http, data) {
Expand All @@ -201,4 +200,4 @@ export function createFormData (data) {
formData.append('taxonomy', uploadStream)
return formData
}
}
}
52 changes: 26 additions & 26 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.15.1",
"version": "1.15.2",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down
4 changes: 2 additions & 2 deletions test/api/taxonomy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ describe('taxonomy api Test', () => {
makeTaxonomy()
.import(importTaxonomy)
.then((taxonomyResponse) => {
expect(taxonomyResponse.name).to.be.equal("name")
expect(taxonomyResponse.name).to.be.equal('name')
done()
})
.catch(done)
})

it('Export taxonomy', done => {
makeTaxonomy(taxonomyUID)
.export()
.export({})
.then((taxonomyResponse) => {
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID)
expect(taxonomyResponse.name).to.be.not.equal(null)
Expand Down
22 changes: 22 additions & 0 deletions test/typescript/taxonomy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,27 @@ export function testTaxonomy(stack: Stack) {
})
})
})
test('Import taxonomy', async () => {
const taxonomyData = {
"uid": "UID",
"name": "name",
"description": "test"
}
await stack.taxonomy()
.import(taxonomyData)
.then((taxonomyResponse) => {
expect(taxonomyResponse.name).to.be.equal('name')
})
.catch(() => {});
})
test('Export taxonomy', async () => {
await stack.taxonomy(taxonomyUID)
.export({ format: 'json'})
.then((taxonomyResponse) => {
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID)
expect(taxonomyResponse.name).to.be.not.equal(null)
})
.catch(() => {});
})
})
}
7 changes: 3 additions & 4 deletions types/stack/taxonomy/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { Term, Terms } from "../taxonomy/terms"
export interface Taxonomy extends SystemFields, SystemFunction<Taxonomy> {
terms(): Terms
terms(uid: string): Term
}

export interface Taxonomies extends Queryable<Taxonomy, {taxonomy: TaxonomyData}> {
export(params?: any): Promise<AnyProperty>
}

export interface Taxonomies extends Creatable<Taxonomy, {taxonomy: TaxonomyData}> {
export interface Taxonomies extends Creatable<Taxonomy, {taxonomy: TaxonomyData}>, Queryable<Taxonomy, {taxonomy: TaxonomyData}> {
import(data: TaxonomyData, params?: any): Promise<Taxonomy>
}

export interface TaxonomyData extends AnyProperty {
Expand Down

0 comments on commit 3e990e5

Please sign in to comment.