@contentstack/datasync-mongodb-sdk 1.0.9-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/codeql-analysis.yml +68 -0
- package/.github/workflows/jira.yml +33 -0
- package/.github/workflows/release.yml +77 -0
- package/.github/workflows/sast-scan.yml +11 -0
- package/.github/workflows/sca-scan.yml +15 -0
- package/.talismanrc +4 -0
- package/CODEOWNERS +1 -0
- package/LICENCE +21 -0
- package/README.md +191 -0
- package/SECURITY.md +27 -0
- package/contentstack-datasync-mongodb-sdk-1.0.9-beta.1.tgz +0 -0
- package/dist/config.js +47 -0
- package/dist/index.js +42 -0
- package/dist/stack.js +2272 -0
- package/dist/util.js +86 -0
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/global.html +7520 -0
- package/docs/global.html#Stack +1070 -0
- package/docs/index.html +291 -0
- package/docs/index.js.html +92 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/stack.js.html +2244 -0
- package/docs/styles/jsdoc-default.css +358 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/example/index.js +56 -0
- package/package.json +59 -0
- package/test/comparison-operators.ts +257 -0
- package/test/conditional-operators.ts +106 -0
- package/test/config.ts +12 -0
- package/test/core.ts +333 -0
- package/test/count.ts +98 -0
- package/test/data/assets.ts +35 -0
- package/test/data/author.ts +168 -0
- package/test/data/blog.ts +138 -0
- package/test/data/category.ts +20 -0
- package/test/data/content_types.ts +164 -0
- package/test/data/products.ts +64 -0
- package/test/expressions.ts +108 -0
- package/test/include-exclude.ts +176 -0
- package/test/logical-operators.ts +140 -0
- package/test/projections.ts +109 -0
- package/test/queries.ts +143 -0
- package/test/references.ts +162 -0
- package/test/skip-limit.ts +150 -0
- package/test/sorting.ts +177 -0
- package/tslint.json +45 -0
- package/typings/config.d.ts +42 -0
- package/typings/index.d.ts +36 -0
- package/typings/stack.d.ts +1097 -0
- package/typings/util.d.ts +28 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Test contentstack-mongodb-sdk basic methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { cloneDeep } from 'lodash'
|
|
6
|
+
import { Contentstack } from '../src'
|
|
7
|
+
import { config } from './config'
|
|
8
|
+
import { assets } from './data/assets'
|
|
9
|
+
import { entries as authors } from './data/author'
|
|
10
|
+
import { entries as blogs } from './data/blog'
|
|
11
|
+
import { entries as categories } from './data/category'
|
|
12
|
+
import { content_types } from './data/content_types'
|
|
13
|
+
|
|
14
|
+
const scriptConfig = cloneDeep(config)
|
|
15
|
+
const collNameConfig: any = scriptConfig.contentStore.collection
|
|
16
|
+
collNameConfig.asset = 'contents.comparison_operators'
|
|
17
|
+
collNameConfig.entry = 'contents.comparison_operators'
|
|
18
|
+
collNameConfig.schema = 'content_types.comparison_operators'
|
|
19
|
+
|
|
20
|
+
const Stack = Contentstack.Stack(scriptConfig)
|
|
21
|
+
const collection = cloneDeep(collNameConfig)
|
|
22
|
+
|
|
23
|
+
collection.asset = `en-us.${collNameConfig.asset}`
|
|
24
|
+
collection.entry = `en-us.${collNameConfig.entry}`
|
|
25
|
+
collection.schema = `en-us.${collNameConfig.schema}`
|
|
26
|
+
|
|
27
|
+
let db
|
|
28
|
+
|
|
29
|
+
const checkEntries = (result: any) => {
|
|
30
|
+
expect(result).toHaveProperty('entries')
|
|
31
|
+
expect(result).toHaveProperty('locale')
|
|
32
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
33
|
+
expect(result.locale).toEqual('en-us')
|
|
34
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
35
|
+
result.entries.forEach((item) => {
|
|
36
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('# Comparison Operator Querying', () => {
|
|
41
|
+
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
return Stack.connect().then((dbInstance) => {
|
|
44
|
+
db = dbInstance
|
|
45
|
+
|
|
46
|
+
return
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
beforeAll(async () => {
|
|
51
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
52
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
53
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
54
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
55
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
56
|
+
|
|
57
|
+
return
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
afterAll(async () => {
|
|
61
|
+
await db.collection(collection.entry).drop()
|
|
62
|
+
// await db.collection(collection.asset).drop()
|
|
63
|
+
await db.collection(collection.schema).drop()
|
|
64
|
+
|
|
65
|
+
return Stack.close()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe('on: non pre-existing operator', () => {
|
|
69
|
+
test('.lessThan()', () => {
|
|
70
|
+
return Stack.contentType('blog')
|
|
71
|
+
.entries()
|
|
72
|
+
.lessThan('no', 1)
|
|
73
|
+
.find()
|
|
74
|
+
.then((result: any) => {
|
|
75
|
+
checkEntries(result)
|
|
76
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
77
|
+
expect(result.entries).toHaveLength(1)
|
|
78
|
+
result.entries.forEach((entry) => {
|
|
79
|
+
expect(entry).toHaveProperty('no')
|
|
80
|
+
expect(entry.no).toEqual(0)
|
|
81
|
+
})
|
|
82
|
+
}).catch((error) => {
|
|
83
|
+
expect(error).toBeNull()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('.lessThanOrEqualTo()', () => {
|
|
88
|
+
return Stack.contentType('blog')
|
|
89
|
+
.entries()
|
|
90
|
+
.lessThanOrEqualTo('no', 0)
|
|
91
|
+
.find()
|
|
92
|
+
.then((result: any) => {
|
|
93
|
+
checkEntries(result)
|
|
94
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
95
|
+
expect(result.entries).toHaveLength(1)
|
|
96
|
+
result.entries.forEach((entry) => {
|
|
97
|
+
expect(entry).toHaveProperty('no')
|
|
98
|
+
expect(entry.no).toEqual(0)
|
|
99
|
+
})
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
expect(error).toBeNull()
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('.notEqualTo()', () => {
|
|
106
|
+
return Stack.contentType('blog')
|
|
107
|
+
.entries()
|
|
108
|
+
.notEqualTo('no', 0)
|
|
109
|
+
.find()
|
|
110
|
+
.then((result: any) => {
|
|
111
|
+
checkEntries(result)
|
|
112
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
113
|
+
expect(result.entries).toHaveLength(4)
|
|
114
|
+
result.entries.forEach((entry) => {
|
|
115
|
+
expect(entry).toHaveProperty('no')
|
|
116
|
+
expect(entry.no).not.toEqual(0)
|
|
117
|
+
})
|
|
118
|
+
}).catch((error) => {
|
|
119
|
+
expect(error).toBeNull()
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('.greaterThan()', () => {
|
|
124
|
+
return Stack.contentType('blog')
|
|
125
|
+
.entries()
|
|
126
|
+
.greaterThan('no', 5)
|
|
127
|
+
.find()
|
|
128
|
+
.then((result: any) => {
|
|
129
|
+
checkEntries(result)
|
|
130
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
131
|
+
expect(result.entries).toHaveLength(1)
|
|
132
|
+
result.entries.forEach((entry) => {
|
|
133
|
+
expect(entry).toHaveProperty('no')
|
|
134
|
+
expect(entry.no).toBeGreaterThan(5)
|
|
135
|
+
})
|
|
136
|
+
}).catch((error) => {
|
|
137
|
+
expect(error).toBeNull()
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('.greaterThanOrEqualTo()', () => {
|
|
142
|
+
return Stack.contentType('blog')
|
|
143
|
+
.entries()
|
|
144
|
+
.greaterThanOrEqualTo('no', 6)
|
|
145
|
+
.find()
|
|
146
|
+
.then((result: any) => {
|
|
147
|
+
checkEntries(result)
|
|
148
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
149
|
+
expect(result.entries).toHaveLength(1)
|
|
150
|
+
result.entries.forEach((entry) => {
|
|
151
|
+
expect(entry).toHaveProperty('no')
|
|
152
|
+
expect(entry.no).toBeGreaterThanOrEqual(6)
|
|
153
|
+
})
|
|
154
|
+
}).catch((error) => {
|
|
155
|
+
expect(error).toBeNull()
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test('.containedIn()', () => {
|
|
160
|
+
return Stack.contentType('blog')
|
|
161
|
+
.entries()
|
|
162
|
+
.containedIn('tags', ['last'])
|
|
163
|
+
.find()
|
|
164
|
+
.then((result: any) => {
|
|
165
|
+
checkEntries(result)
|
|
166
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
167
|
+
expect(result.entries).toHaveLength(1)
|
|
168
|
+
result.entries.forEach((entry) => {
|
|
169
|
+
expect(entry).toHaveProperty('tags')
|
|
170
|
+
expect(entry.tags).toContain('last')
|
|
171
|
+
})
|
|
172
|
+
}).catch((error) => {
|
|
173
|
+
expect(error).toBeNull()
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('.notContainedIn()', () => {
|
|
178
|
+
return Stack.contentType('blog')
|
|
179
|
+
.entries()
|
|
180
|
+
.notContainedIn('tags', ['last'])
|
|
181
|
+
.find()
|
|
182
|
+
.then((result: any) => {
|
|
183
|
+
checkEntries(result)
|
|
184
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
185
|
+
expect(result.entries).toHaveLength(4)
|
|
186
|
+
result.entries.forEach((entry) => {
|
|
187
|
+
if (entry.tags) {
|
|
188
|
+
expect(entry.tags).not.toContain('last')
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
}).catch((error) => {
|
|
192
|
+
expect(error).toBeNull()
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
describe('on: pre-existing operator', () => {
|
|
198
|
+
test('.lessThan() + .lessThanOrEqualTo()', () => {
|
|
199
|
+
return Stack.contentType('blog')
|
|
200
|
+
.entries()
|
|
201
|
+
.lessThanOrEqualTo('no', 0)
|
|
202
|
+
.find()
|
|
203
|
+
.then((result: any) => {
|
|
204
|
+
checkEntries(result)
|
|
205
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
206
|
+
expect(result.entries).toHaveLength(1)
|
|
207
|
+
result.entries.forEach((entry) => {
|
|
208
|
+
expect(entry).toHaveProperty('no')
|
|
209
|
+
expect(entry.no).toEqual(0)
|
|
210
|
+
})
|
|
211
|
+
}).catch((error) => {
|
|
212
|
+
expect(error).toBeNull()
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
test('.notEqualTo() + .greaterThan() + .greaterThanOrEqualTo()', () => {
|
|
217
|
+
return Stack.contentType('blog')
|
|
218
|
+
.entries()
|
|
219
|
+
.notEqualTo('no', 0)
|
|
220
|
+
.greaterThan('no', 5)
|
|
221
|
+
.greaterThanOrEqualTo('no', 6)
|
|
222
|
+
.find()
|
|
223
|
+
.then((result: any) => {
|
|
224
|
+
checkEntries(result)
|
|
225
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
226
|
+
expect(result.entries).toHaveLength(1)
|
|
227
|
+
result.entries.forEach((entry) => {
|
|
228
|
+
expect(entry).toHaveProperty('no')
|
|
229
|
+
expect(entry.no).toBeGreaterThanOrEqual(6)
|
|
230
|
+
})
|
|
231
|
+
}).catch((error) => {
|
|
232
|
+
expect(error).toBeNull()
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('.containedIn() + .notContainedIn()', () => {
|
|
237
|
+
return Stack.contentType('blog')
|
|
238
|
+
.entries()
|
|
239
|
+
.containedIn('tags', ['last'])
|
|
240
|
+
.notContainedIn('tags', ['first'])
|
|
241
|
+
.find()
|
|
242
|
+
.then((result: any) => {
|
|
243
|
+
checkEntries(result)
|
|
244
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
245
|
+
expect(result.entries).toHaveLength(4)
|
|
246
|
+
result.entries.forEach((entry) => {
|
|
247
|
+
if (entry.tags) {
|
|
248
|
+
expect(entry.tags).not.toContain('first')
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
}).catch((error) => {
|
|
252
|
+
expect(error).toBeNull()
|
|
253
|
+
})
|
|
254
|
+
})
|
|
255
|
+
})
|
|
256
|
+
})
|
|
257
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Test contentstack-mongodb-sdk basic methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { cloneDeep } from 'lodash'
|
|
6
|
+
import { Contentstack } from '../src'
|
|
7
|
+
import { config } from './config'
|
|
8
|
+
import { assets } from './data/assets'
|
|
9
|
+
import { entries as authors } from './data/author'
|
|
10
|
+
import { entries as blogs } from './data/blog'
|
|
11
|
+
import { entries as categories } from './data/category'
|
|
12
|
+
import { content_types } from './data/content_types'
|
|
13
|
+
|
|
14
|
+
const scriptConfig = cloneDeep(config)
|
|
15
|
+
const collNameConfig: any = scriptConfig.contentStore.collection
|
|
16
|
+
collNameConfig.asset = 'contents.conditional_operators'
|
|
17
|
+
collNameConfig.entry = 'contents.conditional_operators'
|
|
18
|
+
collNameConfig.schema = 'content_types.conditional_operators'
|
|
19
|
+
|
|
20
|
+
const Stack = Contentstack.Stack(scriptConfig)
|
|
21
|
+
const collection = cloneDeep(collNameConfig)
|
|
22
|
+
|
|
23
|
+
collection.asset = `en-us.${collNameConfig.asset}`
|
|
24
|
+
collection.entry = `en-us.${collNameConfig.entry}`
|
|
25
|
+
collection.schema = `en-us.${collNameConfig.schema}`
|
|
26
|
+
|
|
27
|
+
let db
|
|
28
|
+
|
|
29
|
+
const checkEntries = (result: any) => {
|
|
30
|
+
expect(result).toHaveProperty('entries')
|
|
31
|
+
expect(result).toHaveProperty('locale')
|
|
32
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
33
|
+
expect(result.locale).toEqual('en-us')
|
|
34
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
35
|
+
result.entries.forEach((item) => {
|
|
36
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('# Conditional Operators', () => {
|
|
41
|
+
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
return Stack.connect().then((dbInstance) => {
|
|
44
|
+
db = dbInstance
|
|
45
|
+
|
|
46
|
+
return
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
beforeAll(async () => {
|
|
51
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
52
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
53
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
54
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
55
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
56
|
+
|
|
57
|
+
return
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
afterAll(async () => {
|
|
61
|
+
await db.collection(collection.entry).drop()
|
|
62
|
+
// await db.collection(collection.asset).drop()
|
|
63
|
+
await db.collection(collection.schema).drop()
|
|
64
|
+
|
|
65
|
+
return Stack.close()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe('check key existence', () => {
|
|
69
|
+
test('.exists()', () => {
|
|
70
|
+
return Stack.contentType('blog')
|
|
71
|
+
.entries()
|
|
72
|
+
.exists('tags')
|
|
73
|
+
.exists('single_file')
|
|
74
|
+
.find()
|
|
75
|
+
.then((result: any) => {
|
|
76
|
+
checkEntries(result)
|
|
77
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
78
|
+
result.entries.forEach((entry) => {
|
|
79
|
+
expect(entry).toHaveProperty('tags')
|
|
80
|
+
expect(entry).toHaveProperty('single_file')
|
|
81
|
+
})
|
|
82
|
+
}).catch((error) => {
|
|
83
|
+
expect(error).toBeNull()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('.notExists()', () => {
|
|
88
|
+
return Stack.contentType('blog')
|
|
89
|
+
.entries()
|
|
90
|
+
.notExists('tags')
|
|
91
|
+
.notExists('single_file')
|
|
92
|
+
.find()
|
|
93
|
+
.then((result: any) => {
|
|
94
|
+
checkEntries(result)
|
|
95
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
96
|
+
result.entries.forEach((entry) => {
|
|
97
|
+
expect(entry).not.toHaveProperty('tags')
|
|
98
|
+
expect(entry).not.toHaveProperty('single_file')
|
|
99
|
+
})
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
expect(error).toBeNull()
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
package/test/config.ts
ADDED
package/test/core.ts
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Test contentstack-mongodb-sdk basic methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { cloneDeep } from 'lodash'
|
|
6
|
+
import { Contentstack } from '../src'
|
|
7
|
+
import { config } from './config'
|
|
8
|
+
import { assets } from './data/assets'
|
|
9
|
+
import { entries as authors } from './data/author'
|
|
10
|
+
import { entries as blogs } from './data/blog'
|
|
11
|
+
import { entries as categories } from './data/category'
|
|
12
|
+
import { content_types } from './data/content_types'
|
|
13
|
+
import { entries as products } from './data/products'
|
|
14
|
+
|
|
15
|
+
const scriptConfig = cloneDeep(config)
|
|
16
|
+
const collNameConfig: any = scriptConfig.contentStore.collection
|
|
17
|
+
collNameConfig.asset = 'contents.core'
|
|
18
|
+
collNameConfig.entry = 'contents.core'
|
|
19
|
+
collNameConfig.schema = 'content_types.core'
|
|
20
|
+
|
|
21
|
+
const Stack = Contentstack.Stack(scriptConfig)
|
|
22
|
+
const collection = cloneDeep(collNameConfig)
|
|
23
|
+
const collection2 = cloneDeep(collNameConfig)
|
|
24
|
+
|
|
25
|
+
collection.asset = `en-us.${collNameConfig.asset}`
|
|
26
|
+
collection.entry = `en-us.${collNameConfig.entry}`
|
|
27
|
+
collection.schema = `en-us.${collNameConfig.schema}`
|
|
28
|
+
|
|
29
|
+
collection2.asset = `es-es.${collNameConfig.asset}`
|
|
30
|
+
collection2.entry = `es-es.${collNameConfig.entry}`
|
|
31
|
+
collection2.schema = `es-es.${collNameConfig.schema}`
|
|
32
|
+
|
|
33
|
+
let db
|
|
34
|
+
|
|
35
|
+
const checkEntries = (result: any) => {
|
|
36
|
+
expect(result).toHaveProperty('entries')
|
|
37
|
+
expect(result).toHaveProperty('locale')
|
|
38
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
39
|
+
expect(result.locale).toEqual('en-us')
|
|
40
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
41
|
+
result.entries.forEach((item) => {
|
|
42
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const checkAssets = (result: any) => {
|
|
47
|
+
expect(result).toHaveProperty('assets')
|
|
48
|
+
expect(result).toHaveProperty('locale')
|
|
49
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
50
|
+
expect(result.content_type_uid).toEqual('assets')
|
|
51
|
+
expect(result.locale).toEqual('en-us')
|
|
52
|
+
expect(result.assets instanceof Array).toBeTruthy()
|
|
53
|
+
result.assets.forEach((item) => {
|
|
54
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('# Core', () => {
|
|
59
|
+
|
|
60
|
+
beforeAll(() => {
|
|
61
|
+
return Stack.connect().then((dbInstance) => {
|
|
62
|
+
db = dbInstance
|
|
63
|
+
|
|
64
|
+
return
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
beforeAll(async () => {
|
|
69
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
70
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
71
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
72
|
+
await db.collection(collection.entry).insertMany(products)
|
|
73
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
74
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
75
|
+
|
|
76
|
+
await db.collection(collection2.entry).insertMany(authors)
|
|
77
|
+
await db.collection(collection2.entry).insertMany(blogs)
|
|
78
|
+
await db.collection(collection2.entry).insertMany(products)
|
|
79
|
+
await db.collection(collection2.asset).insertMany(assets)
|
|
80
|
+
await db.collection(collection2.schema).insertMany(content_types)
|
|
81
|
+
|
|
82
|
+
return
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
afterAll(async () => {
|
|
86
|
+
await db.collection(collection.entry).drop()
|
|
87
|
+
// await db.collection(collection.asset).drop()
|
|
88
|
+
await db.collection(collection.schema).drop()
|
|
89
|
+
|
|
90
|
+
await db.collection(collection2.entry).drop()
|
|
91
|
+
// await db.collection(collection.asset).drop()
|
|
92
|
+
await db.collection(collection2.schema).drop()
|
|
93
|
+
|
|
94
|
+
return Stack.close()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('initialize stack', () => {
|
|
98
|
+
expect(Contentstack.Stack())
|
|
99
|
+
.toHaveProperty('connect')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('entries', () => {
|
|
103
|
+
test('find', () => {
|
|
104
|
+
return Stack.contentType('blog')
|
|
105
|
+
.entries()
|
|
106
|
+
.find()
|
|
107
|
+
.then((result: any) => {
|
|
108
|
+
checkEntries(result)
|
|
109
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
110
|
+
expect(result.entries).toHaveLength(5)
|
|
111
|
+
}).catch((error) => {
|
|
112
|
+
expect(error).toBeNull()
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('find - language', () => {
|
|
117
|
+
return Stack.contentType('product')
|
|
118
|
+
.entries()
|
|
119
|
+
.language('es-es')
|
|
120
|
+
.find()
|
|
121
|
+
.then((result: any) => {
|
|
122
|
+
// checkEntries(result)
|
|
123
|
+
expect(result).toHaveProperty('entries')
|
|
124
|
+
expect(result).toHaveProperty('locale')
|
|
125
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
126
|
+
expect(result.locale).toEqual('es-es')
|
|
127
|
+
expect(result.content_type_uid).toEqual('product')
|
|
128
|
+
expect(result.entries).toHaveLength(1)
|
|
129
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
130
|
+
result.entries.forEach((item) => {
|
|
131
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
132
|
+
})
|
|
133
|
+
}).catch((error) => {
|
|
134
|
+
expect(error).toBeNull()
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('findOne', () => {
|
|
139
|
+
return Stack.contentType('blog')
|
|
140
|
+
.entries()
|
|
141
|
+
.findOne()
|
|
142
|
+
.then((result: any) => {
|
|
143
|
+
expect(result).toHaveProperty('entry')
|
|
144
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
145
|
+
expect(result).toHaveProperty('locale')
|
|
146
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
147
|
+
expect(result.locale).toEqual('en-us')
|
|
148
|
+
expect(result.entry).toHaveProperty('title')
|
|
149
|
+
expect(result.entry).not.toHaveProperty('content_type_uid')
|
|
150
|
+
}).catch((error) => {
|
|
151
|
+
expect(error).toBeNull()
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('count', () => {
|
|
156
|
+
return Stack.contentType('blog')
|
|
157
|
+
.entries()
|
|
158
|
+
.count()
|
|
159
|
+
.then((result: any) => {
|
|
160
|
+
expect(result).toHaveProperty('count')
|
|
161
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
162
|
+
expect(result).toHaveProperty('locale')
|
|
163
|
+
expect(result.locale).toEqual('en-us')
|
|
164
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
165
|
+
expect(Object.keys(result)).toHaveLength(3)
|
|
166
|
+
expect(result.count).toEqual(5)
|
|
167
|
+
}).catch((error) => {
|
|
168
|
+
expect(error).toBeNull()
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
describe('assets', () => {
|
|
174
|
+
test('find', () => {
|
|
175
|
+
return Stack.assets()
|
|
176
|
+
.find()
|
|
177
|
+
.then((result: any) => {
|
|
178
|
+
checkAssets(result)
|
|
179
|
+
expect(result.assets).toHaveLength(3)
|
|
180
|
+
}).catch((error) => {
|
|
181
|
+
expect(error).toBeNull()
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('findOne', () => {
|
|
186
|
+
return Stack.assets()
|
|
187
|
+
.findOne()
|
|
188
|
+
.then((result: any) => {
|
|
189
|
+
expect(result).toHaveProperty('asset')
|
|
190
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
191
|
+
expect(result).toHaveProperty('locale')
|
|
192
|
+
expect(result.content_type_uid).toEqual('assets')
|
|
193
|
+
expect(result.locale).toEqual('en-us')
|
|
194
|
+
expect(result.asset).toHaveProperty('title')
|
|
195
|
+
expect(result.asset).not.toHaveProperty('_content_type_uid')
|
|
196
|
+
}).catch((error) => {
|
|
197
|
+
expect(error).toBeNull()
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test('count', () => {
|
|
202
|
+
return Stack.assets()
|
|
203
|
+
.count()
|
|
204
|
+
.then((result: any) => {
|
|
205
|
+
expect(result).toHaveProperty('count')
|
|
206
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
207
|
+
expect(result).toHaveProperty('locale')
|
|
208
|
+
expect(result.locale).toEqual('en-us')
|
|
209
|
+
expect(result.content_type_uid).toEqual('assets')
|
|
210
|
+
expect(Object.keys(result)).toHaveLength(3)
|
|
211
|
+
expect(result.count).toEqual(3)
|
|
212
|
+
}).catch((error) => {
|
|
213
|
+
expect(error).toBeNull()
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
describe('schemas', () => {
|
|
219
|
+
test('find', () => {
|
|
220
|
+
return Stack.schemas()
|
|
221
|
+
.find()
|
|
222
|
+
.then((result: any) => {
|
|
223
|
+
expect(result).toHaveProperty('locale')
|
|
224
|
+
expect(result.locale).toEqual('en-us')
|
|
225
|
+
expect(result).toHaveProperty('content_types')
|
|
226
|
+
expect(result.content_type_uid).toEqual('content_types')
|
|
227
|
+
expect(result.content_types instanceof Array).toBeTruthy()
|
|
228
|
+
expect(result.content_types).toHaveLength(4)
|
|
229
|
+
}).catch((error) => {
|
|
230
|
+
expect(error).toBeNull()
|
|
231
|
+
})
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
test('findOne', () => {
|
|
235
|
+
return Stack.schemas()
|
|
236
|
+
.findOne()
|
|
237
|
+
.then((result: any) => {
|
|
238
|
+
expect(result).toHaveProperty('content_type')
|
|
239
|
+
expect(result.content_type_uid).toEqual('content_types')
|
|
240
|
+
expect(result.content_type).toHaveProperty('title')
|
|
241
|
+
}).catch((error) => {
|
|
242
|
+
expect(error).toBeNull()
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('count', () => {
|
|
247
|
+
return Stack.schemas()
|
|
248
|
+
.count()
|
|
249
|
+
.then((result: any) => {
|
|
250
|
+
expect(result).toHaveProperty('count')
|
|
251
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
252
|
+
expect(result).toHaveProperty('locale')
|
|
253
|
+
expect(result.locale).toEqual('en-us')
|
|
254
|
+
expect(result.content_type_uid).toEqual('content_types')
|
|
255
|
+
expect(Object.keys(result)).toHaveLength(3)
|
|
256
|
+
expect(result.count).toEqual(4)
|
|
257
|
+
}).catch((error) => {
|
|
258
|
+
expect(error).toBeNull()
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
describe('entry', () => {
|
|
264
|
+
test('find', () => {
|
|
265
|
+
return Stack.contentType('blog')
|
|
266
|
+
.entry()
|
|
267
|
+
.find()
|
|
268
|
+
.then((result: any) => {
|
|
269
|
+
expect(result).toHaveProperty('entry')
|
|
270
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
271
|
+
expect(result).toHaveProperty('locale')
|
|
272
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
273
|
+
expect(result.locale).toEqual('en-us')
|
|
274
|
+
expect(result.entry).toHaveProperty('title')
|
|
275
|
+
expect(result.entry).not.toHaveProperty('content_type_uid')
|
|
276
|
+
}).catch((error) => {
|
|
277
|
+
expect(error).toBeNull()
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
describe('asset', () => {
|
|
283
|
+
test('find', () => {
|
|
284
|
+
return Stack.asset()
|
|
285
|
+
.find()
|
|
286
|
+
.then((result: any) => {
|
|
287
|
+
expect(result).toHaveProperty('asset')
|
|
288
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
289
|
+
expect(result).toHaveProperty('locale')
|
|
290
|
+
expect(result.content_type_uid).toEqual('assets')
|
|
291
|
+
expect(result.locale).toEqual('en-us')
|
|
292
|
+
expect(result.asset).toHaveProperty('title')
|
|
293
|
+
expect(result.asset).not.toHaveProperty('_content_type_uid')
|
|
294
|
+
}).catch((error) => {
|
|
295
|
+
expect(error).toBeNull()
|
|
296
|
+
})
|
|
297
|
+
})
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
describe('schema', () => {
|
|
301
|
+
test('find', () => {
|
|
302
|
+
return Stack.schema()
|
|
303
|
+
.find()
|
|
304
|
+
.then((result: any) => {
|
|
305
|
+
expect(result).toHaveProperty('locale')
|
|
306
|
+
expect(result).toHaveProperty('content_type')
|
|
307
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
308
|
+
expect(result.locale).toEqual('en-us')
|
|
309
|
+
expect(result.content_type_uid).toEqual('content_types')
|
|
310
|
+
expect(result.content_type).toHaveProperty('title')
|
|
311
|
+
}).catch((error) => {
|
|
312
|
+
expect(error).toBeNull()
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
test('count', () => {
|
|
317
|
+
return Stack.schemas()
|
|
318
|
+
.count()
|
|
319
|
+
.then((result: any) => {
|
|
320
|
+
expect(result).toHaveProperty('count')
|
|
321
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
322
|
+
expect(result).toHaveProperty('locale')
|
|
323
|
+
expect(result.locale).toEqual('en-us')
|
|
324
|
+
expect(result.content_type_uid).toEqual('content_types')
|
|
325
|
+
expect(Object.keys(result)).toHaveLength(3)
|
|
326
|
+
expect(result.count).toEqual(4)
|
|
327
|
+
}).catch((error) => {
|
|
328
|
+
expect(error).toBeNull()
|
|
329
|
+
})
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
})
|
|
333
|
+
|