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