Skip to content

Commit 58d8d4d

Browse files
test: added taxonomy and terms tests in sanity folder
1 parent 4760c98 commit 58d8d4d

File tree

4 files changed

+264
-1
lines changed

4 files changed

+264
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
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)
Lines changed: 86 additions & 0 deletions
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+
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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+
stack = jsonReader('stack.json')
41+
client = contentstackClient(user.authtoken)
42+
})
43+
it('should create taxonomy', async () => {
44+
await client.stack({ api_key: process.env.API_KEY }).taxonomy().create({ taxonomy })
45+
})
46+
47+
it('should create term', done => {
48+
makeTerms(taxonomy.uid).create(term)
49+
.then((response) => {
50+
expect(response.uid).to.be.equal(term.term.uid)
51+
done()
52+
})
53+
.catch(done)
54+
})
55+
56+
it('should create child term 1', done => {
57+
makeTerms(taxonomy.uid).create(childTerm1)
58+
.then((response) => {
59+
expect(response.uid).to.be.equal(childTerm1.term.uid)
60+
done()
61+
})
62+
.catch(done)
63+
})
64+
65+
it('should create child term 2', done => {
66+
makeTerms(taxonomy.uid).create(childTerm2)
67+
.then((response) => {
68+
expect(response.uid).to.be.equal(childTerm2.term.uid)
69+
done()
70+
})
71+
.catch(done)
72+
})
73+
74+
it('should query and get all terms', done => {
75+
makeTerms(taxonomy.uid).query().find()
76+
.then((response) => {
77+
expect(response.items).to.be.an('array')
78+
expect(response.items[0].uid).not.to.be.equal(null)
79+
expect(response.items[0].name).not.to.be.equal(null)
80+
done()
81+
})
82+
.catch(done)
83+
})
84+
85+
it('should fetch term of the term uid passed', done => {
86+
makeTerms(taxonomy.uid, term.term.uid).fetch()
87+
.then((response) => {
88+
expect(response.uid).to.be.equal(termUid)
89+
expect(response.name).not.to.be.equal(null)
90+
expect(response.created_by).not.to.be.equal(null)
91+
expect(response.updated_by).not.to.be.equal(null)
92+
done()
93+
})
94+
.catch(done)
95+
})
96+
97+
it('should update term of the term uid passed', done => {
98+
makeTerms(taxonomy.uid, termUid).fetch()
99+
.then((term) => {
100+
term.name = 'update name'
101+
return term.update()
102+
})
103+
.then((response) => {
104+
expect(response.uid).to.be.equal(termUid)
105+
expect(response.name).to.be.equal('update name')
106+
expect(response.created_by).not.to.be.equal(null)
107+
expect(response.updated_by).not.to.be.equal(null)
108+
done()
109+
})
110+
.catch(done)
111+
})
112+
113+
it('should get the ancestors of the term uid passed', done => {
114+
makeTerms(taxonomy.uid, childTerm1.term.uid).ancestors()
115+
.then((response) => {
116+
expect(response.terms[0].uid).not.to.be.equal(null)
117+
expect(response.terms[0].name).not.to.be.equal(null)
118+
expect(response.terms[0].created_by).not.to.be.equal(null)
119+
expect(response.terms[0].updated_by).not.to.be.equal(null)
120+
done()
121+
})
122+
.catch(done)
123+
})
124+
125+
it('should get the descendants of the term uid passed', done => {
126+
makeTerms(taxonomy.uid, childTerm1.term.uid).descendants()
127+
.then((response) => {
128+
expect(response.terms.uid).not.to.be.equal(null)
129+
expect(response.terms.name).not.to.be.equal(null)
130+
expect(response.terms.created_by).not.to.be.equal(null)
131+
expect(response.terms.updated_by).not.to.be.equal(null)
132+
done()
133+
})
134+
.catch(done)
135+
})
136+
137+
it('should search the term with the string passed', done => {
138+
makeTerms(taxonomy.uid).search(termString)
139+
.then((response) => {
140+
expect(response.terms).to.be.an('array')
141+
done()
142+
})
143+
.catch(done)
144+
})
145+
146+
it('should move the term to parent uid passed', done => {
147+
makeTerms(taxonomy.uid, childTerm2.term.uid).move({ force: true })
148+
.then(async (term) => {
149+
term.parent_uid = null
150+
const moveTerm = await term.move({ force: true })
151+
expect(moveTerm.parent_uid).to.be.equal(null)
152+
done()
153+
return moveTerm
154+
})
155+
.catch(done)
156+
})
157+
158+
it('should delete of the term uid passed', done => {
159+
makeTerms(taxonomy.uid, term.term.uid).delete({ force: true })
160+
.then((response) => {
161+
expect(response.status).to.be.equal(204)
162+
done()
163+
})
164+
.catch(done)
165+
})
166+
167+
it('should delete taxonomy', async () => {
168+
const taxonomyResponse = await client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomy.uid).delete({ force: true })
169+
expect(taxonomyResponse.status).to.be.equal(204)
170+
})
171+
})
172+
173+
function makeTerms (taxonomyUid, termUid = null) {
174+
return client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomyUid).terms(termUid)
175+
}

test/sanity-check/sanity.js

Lines changed: 2 additions & 0 deletions
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)