Skip to content

Commit ff8dd65

Browse files
Merge branch 'next' into test/cs-43493-sanity-test-global-fields
2 parents 3489d88 + 4d20885 commit ff8dd65

File tree

7 files changed

+96
-3
lines changed

7 files changed

+96
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
3+
## [v1.15.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.1) (2024-01-29)
4+
- Feature
5+
- Taxonomy Import/Export test cases are added
26
## [v1.15.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.0) (2024-01-23)
37
- Feature
48
- Taxonomy Import/Export feature added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.15.0",
3+
"version": "1.15.1",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",

test/api/mock/taxonomy.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"taxonomy": {
3+
"uid": "UID",
4+
"name": "name",
5+
"description": "test"
6+
},
7+
"terms": []
8+
}

test/api/taxonomy-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai'
2+
import path from 'path'
23
import { describe, it, setup } from 'mocha'
34
import { jsonReader } from '../utility/fileOperations/readwrite'
45
import { contentstackClient } from '../utility/ContentstackClient.js'
@@ -12,6 +13,8 @@ const taxonomy = {
1213
description: 'Description for Taxonomy testing'
1314
}
1415

16+
const importTaxonomy = { taxonomy: path.join(__dirname, './mock/taxonomy.json') }
17+
1518
var taxonomyUID = ''
1619
var taxonomyDelUID = 'taxonomy_testing'
1720

@@ -32,6 +35,28 @@ describe('taxonomy api Test', () => {
3235
.catch(done)
3336
})
3437

38+
it('Import taxonomy', done => {
39+
makeTaxonomy()
40+
.import(importTaxonomy)
41+
.then((taxonomyResponse) => {
42+
expect(taxonomyResponse.name).to.be.equal("name")
43+
done()
44+
})
45+
.catch(done)
46+
})
47+
48+
it('Export taxonomy', done => {
49+
makeTaxonomy(taxonomyUID)
50+
.export()
51+
.then((taxonomyResponse) => {
52+
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID)
53+
expect(taxonomyResponse.name).to.be.not.equal(null)
54+
done()
55+
})
56+
.catch(done)
57+
})
58+
59+
3560
it('Fetch taxonomy from uid', done => {
3661
makeTaxonomy(taxonomyUID)
3762
.fetch()

test/sanity-check/api/delete-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createDeliveryToken } from '../mock/deliveryToken.js'
88
import dotenv from 'dotenv'
99

1010
dotenv.config()
11+
1112
let client = {}
1213

1314
describe('Delete Environment api Test', () => {
@@ -121,6 +122,7 @@ describe('Branch Alias delete api Test', () => {
121122
.catch(done)
122123
})
123124
})
125+
124126
function makeEnvironment (uid = null) {
125127
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
126128
}
@@ -136,3 +138,4 @@ function makeDeliveryToken (uid = null) {
136138
function makeBranchAlias (uid = null) {
137139
return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid)
138140
}
141+

test/unit/mock/objects.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,12 @@ const auditLogsMock = {
741741
]
742742
}
743743

744+
const taxonomyImportMock = {
745+
"uid": "UID",
746+
"name": "name",
747+
"description": "test"
748+
}
749+
744750
const taxonomyMock = {
745751
uid: 'UID',
746752
name: 'name',
@@ -883,6 +889,7 @@ export {
883889
auditLogsMock,
884890
auditLogItemMock,
885891
taxonomyMock,
892+
taxonomyImportMock,
886893
termsMock,
887894
teamsMock,
888895
teamUsersMock,

test/unit/taxonomy-test.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import Axios from 'axios'
2+
import path from 'path'
23
import { expect } from 'chai'
34
import { describe, it } from 'mocha'
45
import MockAdapter from 'axios-mock-adapter'
5-
import { Taxonomy } from '../../lib/stack/taxonomy'
6-
import { systemUidMock, stackHeadersMock, taxonomyMock, noticeMock, termsMock } from './mock/objects'
6+
import { Taxonomy, createFormData, TaxonomyCollection } from '../../lib/stack/taxonomy'
7+
import { systemUidMock, stackHeadersMock, taxonomyMock, noticeMock, termsMock, taxonomyImportMock } from './mock/objects'
78

89
describe('Contentstack Taxonomy test', () => {
910
it('taxonomy create test', done => {
@@ -122,6 +123,51 @@ describe('Contentstack Taxonomy test', () => {
122123
done()
123124
})
124125

126+
it('Taxonomy export test', done => {
127+
var mock = new MockAdapter(Axios)
128+
mock.onGet('/taxonomies/UID/export').reply(200, {
129+
taxonomy: {
130+
...taxonomyImportMock
131+
}
132+
})
133+
makeTaxonomy({
134+
taxonomy: {
135+
...systemUidMock
136+
},
137+
stackHeaders: stackHeadersMock
138+
})
139+
.export()
140+
.then((taxonomy) => {
141+
expect(taxonomy['taxonomy']['uid']).to.be.equal('UID')
142+
expect(taxonomy['taxonomy']['name']).to.be.equal('name')
143+
done()
144+
})
145+
.catch(done)
146+
})
147+
148+
it('Taxonomy import test', done => {
149+
var mock = new MockAdapter(Axios)
150+
mock.onPost('/taxonomies/import').reply(200, {
151+
taxonomy: {
152+
...taxonomyMock
153+
}
154+
})
155+
const taxonomyUpload = { taxonomy: path.join(__dirname, '../api/mock/taxonomy.json') }
156+
const form = createFormData(taxonomyUpload)()
157+
var boundary = form.getBoundary()
158+
159+
expect(boundary).to.be.equal(form.getBoundary())
160+
expect(boundary.length).to.be.equal(50)
161+
makeTaxonomy()
162+
.import(taxonomyUpload)
163+
.then((taxonomy) => {
164+
checkTaxonomy(taxonomy)
165+
done()
166+
})
167+
.catch(done)
168+
})
169+
170+
125171
it('term create test', done => {
126172
var mock = new MockAdapter(Axios)
127173
mock.onPost(`/taxonomies/taxonomy_uid/terms`).reply(200, {

0 commit comments

Comments
 (0)