-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathentry-test.js
More file actions
294 lines (272 loc) · 9.52 KB
/
entry-test.js
File metadata and controls
294 lines (272 loc) · 9.52 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import path from 'path'
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite'
import { multiPageCT, singlepageCT } from '../mock/content-type.js'
import { entryFirst, entrySecond, entryThird } from '../mock/entry.js'
import { contentstackClient } from '../utility/ContentstackClient.js'
var client = {}
var entryUTD = ''
describe('Entry api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should create Entry in Single ', done => {
var entry = {
title: 'Sample Entry',
url: 'sampleEntry'
}
makeEntry(singlepageCT.content_type.uid)
.create({ entry })
.then((entryResponse) => {
entryUTD = entryResponse.uid
expect(entryResponse.title).to.be.equal(entry.title)
expect(entryResponse.url).to.be.equal(entry.url)
expect(entryResponse.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should entry fetch with Content Type', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.fetch({ include_content_type: true })
.then((entryResponse) => {
expect(entryResponse.uid).to.be.not.equal(null)
expect(entryResponse.content_type).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should entry fetch with asset_fields parameter - single value', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.fetch({ asset_fields: ['user_defined_fields'] })
.then((entryResponse) => {
expect(entryResponse.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should entry fetch with asset_fields parameter - multiple values', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.fetch({ asset_fields: ['user_defined_fields', 'embedded', 'ai_suggested', 'visual_markups'] })
.then((entryResponse) => {
expect(entryResponse.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should localize entry with title update', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.fetch()
.then((entry) => {
entry.title = 'Sample Entry in en-at'
return entry.update({ locale: 'en-at' })
})
.then((entryResponse) => {
jsonWrite(entryResponse, 'publishEntry2.json')
entryUTD = entryResponse.uid
expect(entryResponse.title).to.be.equal('Sample Entry in en-at')
expect(entryResponse.uid).to.be.not.equal(null)
expect(entryResponse.locale).to.be.equal('en-at')
done()
})
.catch(done)
})
it('should create Entries for Multiple page', done => {
makeEntry(multiPageCT.content_type.uid)
.create({ entry: entryFirst })
.then((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.title).to.be.equal(entryFirst.title)
expect(entry.url).to.be.equal(`/${entryFirst.title.toLowerCase().replace(/ /g, '-')}`)
done()
})
.catch(done)
})
it('should create Entries 2 for Multiple page', done => {
makeEntry(multiPageCT.content_type.uid)
.create({ entry: entrySecond })
.then((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.title).to.be.equal(entrySecond.title)
expect(entry.url).to.be.equal(`/${entrySecond.title.toLowerCase().replace(/ /g, '-')}`)
expect(entry.tags[0]).to.be.equal(entrySecond.tags[0])
done()
})
.catch(done)
})
it('should create Entries 3 for Multiple page', done => {
makeEntry(multiPageCT.content_type.uid)
.create({ entry: entryThird })
.then((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.title).to.be.equal(entryThird.title)
expect(entry.url).to.be.equal(`/${entryThird.title.toLowerCase().replace(/ /g, '-')}`)
expect(entry.tags[0]).to.be.equal(entryThird.tags[0])
done()
})
.catch(done)
})
it('should get all Entry', done => {
makeEntry(multiPageCT.content_type.uid)
.query({ include_count: true, include_content_type: true }).find()
.then((collection) => {
jsonWrite(collection.items, 'entry.json')
expect(collection.count).to.be.equal(3)
collection.items.forEach((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.content_type_uid).to.be.equal(multiPageCT.content_type.uid)
})
done()
})
.catch(done)
})
it('should get all Entry from tag', done => {
makeEntry(multiPageCT.content_type.uid)
.query({ include_count: true, query: { tags: entrySecond.tags[0] } }).find()
.then((collection) => {
expect(collection.count).to.be.equal(1)
collection.items.forEach((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.tags).to.have.all.keys(0)
})
done()
})
.catch(done)
})
it('should get all Entry with asset_fields parameter - single value', done => {
makeEntry(multiPageCT.content_type.uid)
.query({ include_count: true, asset_fields: ['user_defined_fields'] }).find()
.then((collection) => {
expect(collection.count).to.be.equal(3)
collection.items.forEach((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.content_type_uid).to.be.equal(multiPageCT.content_type.uid)
})
done()
})
.catch(done)
})
it('should get all Entry with asset_fields parameter - multiple values', done => {
makeEntry(multiPageCT.content_type.uid)
.query({ include_count: true, asset_fields: ['user_defined_fields', 'embedded', 'ai_suggested', 'visual_markups'] }).find()
.then((collection) => {
expect(collection.count).to.be.equal(3)
collection.items.forEach((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.content_type_uid).to.be.equal(multiPageCT.content_type.uid)
})
done()
})
.catch(done)
})
it('should get all Entry with asset_fields parameter combined with other query params', done => {
makeEntry(multiPageCT.content_type.uid)
.query({
include_count: true,
include_content_type: true,
asset_fields: ['user_defined_fields', 'embedded']
}).find()
.then((collection) => {
expect(collection.count).to.be.equal(3)
collection.items.forEach((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.content_type_uid).to.be.equal(multiPageCT.content_type.uid)
})
done()
})
.catch(done)
})
it('should publish Entry', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.publish({
publishDetails: {
locales: ['en-us'],
environments: ['development']
}
})
.then((data) => {
expect(data.notice).to.be.equal('The requested action has been performed.')
done()
})
.catch(done)
})
it('should publish localized Entry to locales', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.publish({
publishDetails: {
locales: ['hi-in', 'en-at'],
environments: ['development']
},
locale: 'en-at'
})
.then((data) => {
expect(data.notice).to.be.equal('The requested action has been performed.')
done()
})
.catch(done)
})
it('should get languages of the given Entry uid', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD).locales()
.then((locale) => {
expect(locale.locales[0].code).to.be.equal('en-us')
locale.locales.forEach((locales) => {
expect(locales.code).to.be.not.equal(null)
})
done()
})
.catch(done)
})
it('should get references of the given Entry uid', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD).references()
.then((reference) => {
reference.references.forEach((references) => {
expect(references.entry_uid).to.be.not.equal(null)
expect(references.content_type_uid).to.be.not.equal(null)
expect(references.content_type_title).to.be.not.equal(null)
})
done()
})
.catch(done)
})
it('should unpublish localized entry', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.unpublish({
publishDetails: {
locales: ['hi-in', 'en-at'],
environments: ['development']
},
locale: 'en-at'
})
.then((data) => {
expect(data.notice).to.be.equal('The requested action has been performed.')
done()
})
.catch(done)
})
it('should import Entry', done => {
makeEntry(multiPageCT.content_type.uid)
.import({
entry: path.join(__dirname, '../mock/entry.json')
})
.then((response) => {
jsonWrite(response, 'publishEntry1.json')
expect(response.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should get entry variants of the given Entry uid', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD).includeVariants('true', 'variants_uid')
.then((response) => {
expect(response.uid).to.be.not.equal(null)
expect(response._variants).to.be.not.equal(null)
done()
})
.catch(done)
})
})
function makeEntry (contentType, uid = null) {
return client.stack({ api_key: process.env.API_KEY }).contentType(contentType).entry(uid)
}