Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3c4ba30

Browse files
authoredDec 20, 2023
Merge pull request #102 from contentstack/test/cs-43154-sanity-test-taxonomy-terms
sanity test for taxonomy and terms
2 parents cfb7ea1 + 67f2a62 commit 3c4ba30

File tree

4 files changed

+263
-1
lines changed

4 files changed

+263
-1
lines changed
 

‎test/sanity-check/api/organization-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('Organization api test', () => {
4343
it('should fetch organization', done => {
4444
organization.fetch()
4545
.then((organizations) => {
46-
expect(organizations.name).to.be.equal('CLI Dev and Automation', 'Organization name dose not match')
46+
expect(organizations.name).to.be.equal('CLI Branches', 'Organization name dose not match')
4747
done()
4848
})
4949
.catch(done)
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { contentstackClient } from '../utility/ContentstackClient.js'
5+
6+
var client = {}
7+
var stack = {}
8+
9+
const taxonomy = {
10+
uid: 'taxonomy_testing',
11+
name: 'taxonomy testing',
12+
description: 'Description for Taxonomy testing'
13+
}
14+
15+
var taxonomyUID = ''
16+
17+
describe('taxonomy api Test', () => {
18+
setup(() => {
19+
const user = jsonReader('loggedinuser.json')
20+
stack = jsonReader('stack.json')
21+
client = contentstackClient(user.authtoken)
22+
})
23+
24+
it('should create taxonomy', done => {
25+
makeTaxonomy()
26+
.create({ taxonomy })
27+
.then((taxonomyResponse) => {
28+
taxonomyUID = taxonomyResponse.uid
29+
expect(taxonomyResponse.name).to.be.equal(taxonomy.name)
30+
done()
31+
})
32+
.catch(done)
33+
})
34+
35+
it('should fetch taxonomy of the uid passe', done => {
36+
makeTaxonomy(taxonomyUID)
37+
.fetch()
38+
.then((taxonomyResponse) => {
39+
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID)
40+
expect(taxonomyResponse.name).to.be.not.equal(null)
41+
done()
42+
})
43+
.catch(done)
44+
})
45+
46+
it('should update taxonomy of the uid passed', done => {
47+
makeTaxonomy(taxonomyUID)
48+
.fetch()
49+
.then((taxonomyResponse) => {
50+
taxonomyResponse.name = 'Updated Name'
51+
return taxonomyResponse.update()
52+
})
53+
.then((taxonomyResponse) => {
54+
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID)
55+
expect(taxonomyResponse.name).to.be.equal('Updated Name')
56+
done()
57+
})
58+
.catch(done)
59+
})
60+
61+
it('should get all taxonomies', async () => {
62+
makeTaxonomy()
63+
.query()
64+
.find()
65+
.then((response) => {
66+
response.items.forEach((taxonomyResponse) => {
67+
expect(taxonomyResponse.uid).to.be.not.equal(null)
68+
expect(taxonomyResponse.name).to.be.not.equal(null)
69+
})
70+
})
71+
})
72+
73+
it('should delete taxonomy from uid', done => {
74+
makeTaxonomy(taxonomyUID)
75+
.delete()
76+
.then((taxonomyResponse) => {
77+
expect(taxonomyResponse.status).to.be.equal(204)
78+
done()
79+
})
80+
.catch(done)
81+
})
82+
})
83+
84+
function makeTaxonomy (uid = null) {
85+
return client.stack({ api_key: stack.api_key }).taxonomy(uid)
86+
}

‎test/sanity-check/api/terms-test.js

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { describe, it, beforeEach } from 'mocha'
2+
import { expect } from 'chai'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { contentstackClient } from '../utility/ContentstackClient.js'
5+
6+
var client = {}
7+
8+
const taxonomy = {
9+
uid: 'taxonomy_testing',
10+
name: 'taxonomy testing',
11+
description: 'Description for Taxonomy testing'
12+
}
13+
const termString = 'term'
14+
const term = {
15+
term: {
16+
uid: 'term_test',
17+
name: 'Term test',
18+
parent_uid: null
19+
}
20+
}
21+
const childTerm1 = {
22+
term: {
23+
uid: 'term_test_child1',
24+
name: 'Term test1',
25+
parent_uid: 'term_test'
26+
}
27+
}
28+
const childTerm2 = {
29+
term: {
30+
uid: 'term_test_child2',
31+
name: 'Term test2',
32+
parent_uid: 'term_test_child1'
33+
}
34+
}
35+
var termUid = term.term.uid
36+
37+
describe('Terms API Test', () => {
38+
beforeEach(() => {
39+
const user = jsonReader('loggedinuser.json')
40+
client = contentstackClient(user.authtoken)
41+
})
42+
it('should create taxonomy', async () => {
43+
await client.stack({ api_key: process.env.API_KEY }).taxonomy().create({ taxonomy })
44+
})
45+
46+
it('should create term', done => {
47+
makeTerms(taxonomy.uid).create(term)
48+
.then((response) => {
49+
expect(response.uid).to.be.equal(term.term.uid)
50+
done()
51+
})
52+
.catch(done)
53+
})
54+
55+
it('should create child term 1', done => {
56+
makeTerms(taxonomy.uid).create(childTerm1)
57+
.then((response) => {
58+
expect(response.uid).to.be.equal(childTerm1.term.uid)
59+
done()
60+
})
61+
.catch(done)
62+
})
63+
64+
it('should create child term 2', done => {
65+
makeTerms(taxonomy.uid).create(childTerm2)
66+
.then((response) => {
67+
expect(response.uid).to.be.equal(childTerm2.term.uid)
68+
done()
69+
})
70+
.catch(done)
71+
})
72+
73+
it('should query and get all terms', done => {
74+
makeTerms(taxonomy.uid).query().find()
75+
.then((response) => {
76+
expect(response.items).to.be.an('array')
77+
expect(response.items[0].uid).not.to.be.equal(null)
78+
expect(response.items[0].name).not.to.be.equal(null)
79+
done()
80+
})
81+
.catch(done)
82+
})
83+
84+
it('should fetch term of the term uid passed', done => {
85+
makeTerms(taxonomy.uid, term.term.uid).fetch()
86+
.then((response) => {
87+
expect(response.uid).to.be.equal(termUid)
88+
expect(response.name).not.to.be.equal(null)
89+
expect(response.created_by).not.to.be.equal(null)
90+
expect(response.updated_by).not.to.be.equal(null)
91+
done()
92+
})
93+
.catch(done)
94+
})
95+
96+
it('should update term of the term uid passed', done => {
97+
makeTerms(taxonomy.uid, termUid).fetch()
98+
.then((term) => {
99+
term.name = 'update name'
100+
return term.update()
101+
})
102+
.then((response) => {
103+
expect(response.uid).to.be.equal(termUid)
104+
expect(response.name).to.be.equal('update name')
105+
expect(response.created_by).not.to.be.equal(null)
106+
expect(response.updated_by).not.to.be.equal(null)
107+
done()
108+
})
109+
.catch(done)
110+
})
111+
112+
it('should get the ancestors of the term uid passed', done => {
113+
makeTerms(taxonomy.uid, childTerm1.term.uid).ancestors()
114+
.then((response) => {
115+
expect(response.terms[0].uid).not.to.be.equal(null)
116+
expect(response.terms[0].name).not.to.be.equal(null)
117+
expect(response.terms[0].created_by).not.to.be.equal(null)
118+
expect(response.terms[0].updated_by).not.to.be.equal(null)
119+
done()
120+
})
121+
.catch(done)
122+
})
123+
124+
it('should get the descendants of the term uid passed', done => {
125+
makeTerms(taxonomy.uid, childTerm1.term.uid).descendants()
126+
.then((response) => {
127+
expect(response.terms.uid).not.to.be.equal(null)
128+
expect(response.terms.name).not.to.be.equal(null)
129+
expect(response.terms.created_by).not.to.be.equal(null)
130+
expect(response.terms.updated_by).not.to.be.equal(null)
131+
done()
132+
})
133+
.catch(done)
134+
})
135+
136+
it('should search the term with the string passed', done => {
137+
makeTerms(taxonomy.uid).search(termString)
138+
.then((response) => {
139+
expect(response.terms).to.be.an('array')
140+
done()
141+
})
142+
.catch(done)
143+
})
144+
145+
it('should move the term to parent uid passed', done => {
146+
makeTerms(taxonomy.uid, childTerm2.term.uid).move({ force: true })
147+
.then(async (term) => {
148+
term.parent_uid = null
149+
const moveTerm = await term.move({ force: true })
150+
expect(moveTerm.parent_uid).to.be.equal(null)
151+
done()
152+
return moveTerm
153+
})
154+
.catch(done)
155+
})
156+
157+
it('should delete of the term uid passed', done => {
158+
makeTerms(taxonomy.uid, term.term.uid).delete({ force: true })
159+
.then((response) => {
160+
expect(response.status).to.be.equal(204)
161+
done()
162+
})
163+
.catch(done)
164+
})
165+
166+
it('should delete taxonomy', async () => {
167+
const taxonomyResponse = await client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomy.uid).delete({ force: true })
168+
expect(taxonomyResponse.status).to.be.equal(204)
169+
})
170+
})
171+
172+
function makeTerms (taxonomyUid, termUid = null) {
173+
return client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomyUid).terms(termUid)
174+
}

‎test/sanity-check/sanity.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ require('./api/contentType-test')
55
require('./api/asset-test')
66
require('./api/entry-test')
77
require('./api/contentType-delete-test')
8+
require('./api/taxonomy-test')
9+
require('./api/terms-test')

0 commit comments

Comments
 (0)
Please sign in to comment.