Skip to content

Commit 319a809

Browse files
test: ✅ added api test cases for terms implementation
1 parent 95204db commit 319a809

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

test/api/terms-test.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
var stack = {}
8+
9+
const taxonomy_uid = 'taxonomy_21'
10+
const term = {
11+
term: {
12+
uid: 'term_test',
13+
name: 'Term test'
14+
},
15+
parent_uid: null
16+
}
17+
18+
describe('Terms API Test', () => {
19+
beforeEach(() => {
20+
const user = jsonReader('loggedinuser.json')
21+
stack = jsonReader('stack.json')
22+
client = contentstackClient(user.authtoken)
23+
})
24+
25+
it('Create term', async () => {
26+
const response = await makeTerms().create([{ term }])
27+
console.log(response)
28+
expect(response.notice).to.be.equal('Term created successfully.')
29+
expect(response.uid).to.be.equal(term.term.uid)
30+
})
31+
32+
it('Query and get all terms', async () => {
33+
const response = await makeTerms().query().find()
34+
expect(response.items).to.be.an('array')
35+
expect(response.items[0].uid).not.to.be.equal(null)
36+
expect(response.items[0].name).not.to.be.equal(null)
37+
})
38+
39+
it('Fetch term from UID', async () => {
40+
const termsUid = 'fashion'
41+
const response = await makeTerms(termsUid).fetch()
42+
expect(response.uid).to.be.equal(termsUid)
43+
expect(response.name).not.to.be.equal(null)
44+
expect(response.created_by).not.to.be.equal(null)
45+
expect(response.updated_by).not.to.be.equal(null)
46+
})
47+
48+
it('Update term', async () => {
49+
const termsUid = 'fashion'
50+
const response = await makeTerms(termsUid).fetch()
51+
.then((term) => {
52+
term.name = 'fashion'
53+
return term.update()
54+
})
55+
expect(response.notice).to.be.equal('Term updated successfully.')
56+
expect(response.uid).to.be.equal(termsUid)
57+
expect(response.name).to.be.equal('fashion')
58+
expect(response.created_by).not.to.be.equal(null)
59+
expect(response.updated_by).not.to.be.equal(null)
60+
})
61+
62+
it('Delete term from UID', async () => {
63+
const termsUid = 'testing'
64+
const response = await makeTerms(termsUid).delete()
65+
expect(response.notice).to.be.equal('')
66+
})
67+
68+
it('Ancestors of the term given', async () => {
69+
const termsUid = 'term_3'
70+
const response = await makeTerms(termsUid).ancestors()
71+
expect(response.terms[0].uid).not.to.be.equal(null)
72+
expect(response.terms[0].name).not.to.be.equal(null)
73+
expect(response.terms[0].created_by).not.to.be.equal(null)
74+
expect(response.terms[0].updated_by).not.to.be.equal(null)
75+
})
76+
77+
it('Descendants of the term given', async () => {
78+
const termsUid = 'term_3'
79+
const response = await makeTerms(termsUid).descendants()
80+
expect(response.terms.uid).not.to.be.equal(null)
81+
expect(response.terms.name).not.to.be.equal(null)
82+
expect(response.terms.created_by).not.to.be.equal(null)
83+
expect(response.terms.updated_by).not.to.be.equal(null)
84+
})
85+
})
86+
87+
function makeTerms (uid = '') {
88+
return client.stack({ api_key: stack.api_key }).taxonomy(taxonomy_uid).terms(uid)
89+
}

test/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ require('./api/label-test')
2626
require('./api/contentType-delete-test')
2727
require('./api/delete-test')
2828
require('./api/taxonomy-test')
29+
require('./api/terms-test')

0 commit comments

Comments
 (0)