@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,108 @@
|
|
|
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.expressions'
|
|
17
|
+
collNameConfig.entry = 'contents.expressions'
|
|
18
|
+
collNameConfig.schema = 'content_types.expressions'
|
|
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
|
+
function fnWhere() {
|
|
30
|
+
return (this.no === 1)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const checkEntries = (result: any) => {
|
|
34
|
+
expect(result).toHaveProperty('entries')
|
|
35
|
+
expect(result).toHaveProperty('locale')
|
|
36
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
37
|
+
expect(result.locale).toEqual('en-us')
|
|
38
|
+
expect(result.entries instanceof Array).toBeTruthy()
|
|
39
|
+
result.entries.forEach((item) => {
|
|
40
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('# Expressional Operators', () => {
|
|
45
|
+
|
|
46
|
+
beforeAll(() => {
|
|
47
|
+
return Stack.connect().then((dbInstance) => {
|
|
48
|
+
db = dbInstance
|
|
49
|
+
|
|
50
|
+
return
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
beforeAll(async () => {
|
|
55
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
56
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
57
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
58
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
59
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
60
|
+
|
|
61
|
+
return
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
afterAll(async () => {
|
|
65
|
+
await db.collection(collection.entry).drop()
|
|
66
|
+
// await db.collection(collection.asset).drop()
|
|
67
|
+
await db.collection(collection.schema).drop()
|
|
68
|
+
|
|
69
|
+
return Stack.close()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('basic', () => {
|
|
73
|
+
test('.where()', () => {
|
|
74
|
+
return Stack.contentType('blog')
|
|
75
|
+
.entries()
|
|
76
|
+
.where(fnWhere)
|
|
77
|
+
.find()
|
|
78
|
+
.then((result: any) => {
|
|
79
|
+
checkEntries(result)
|
|
80
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
81
|
+
result.entries.forEach((entry) => {
|
|
82
|
+
expect(entry).toHaveProperty('no')
|
|
83
|
+
expect(entry.no).toEqual(1)
|
|
84
|
+
})
|
|
85
|
+
}).catch((error) => {
|
|
86
|
+
expect(error).toBeNull()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('.regex()', () => {
|
|
91
|
+
return Stack.contentType('blog')
|
|
92
|
+
.entries()
|
|
93
|
+
.regex('title', '/^Blog Two$/', 'i')
|
|
94
|
+
.find()
|
|
95
|
+
.then((result: any) => {
|
|
96
|
+
checkEntries(result)
|
|
97
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
98
|
+
result.entries.forEach((entry) => {
|
|
99
|
+
expect(entry).toHaveProperty('title')
|
|
100
|
+
expect(entry.title).toMatch(/^Blog Two$/)
|
|
101
|
+
})
|
|
102
|
+
}).catch((error) => {
|
|
103
|
+
expect(error).toBeNull()
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Test contentstack-mongodb-sdk basic methods
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import Debug from 'debug'
|
|
6
|
+
import { cloneDeep } from 'lodash'
|
|
7
|
+
import { Contentstack } from '../src'
|
|
8
|
+
import { config } from './config'
|
|
9
|
+
import { assets } from './data/assets'
|
|
10
|
+
import { entries as authors } from './data/author'
|
|
11
|
+
import { entries as blogs } from './data/blog'
|
|
12
|
+
import { entries as categories } from './data/category'
|
|
13
|
+
import { content_types } from './data/content_types'
|
|
14
|
+
|
|
15
|
+
const scriptConfig = cloneDeep(config)
|
|
16
|
+
const collNameConfig: any = scriptConfig.contentStore.collection
|
|
17
|
+
collNameConfig.asset = 'contents.include_exclude'
|
|
18
|
+
collNameConfig.entry = 'contents.include_exclude'
|
|
19
|
+
collNameConfig.schema = 'content_types.include_exclude'
|
|
20
|
+
|
|
21
|
+
const Stack = Contentstack.Stack(scriptConfig)
|
|
22
|
+
const collection = cloneDeep(collNameConfig)
|
|
23
|
+
const debug = new Debug('test:include-exclude')
|
|
24
|
+
collection.asset = `en-us.${collNameConfig.asset}`
|
|
25
|
+
collection.entry = `en-us.${collNameConfig.entry}`
|
|
26
|
+
collection.schema = `en-us.${collNameConfig.schema}`
|
|
27
|
+
|
|
28
|
+
let db
|
|
29
|
+
|
|
30
|
+
const itemPropertyChecks = (result) => {
|
|
31
|
+
expect(result).toHaveProperty('entries')
|
|
32
|
+
expect(result).toHaveProperty('locale')
|
|
33
|
+
expect(result).toHaveProperty('content_type_uid')
|
|
34
|
+
expect(result.locale).toEqual('en-us')
|
|
35
|
+
result.entries.forEach((item) => {
|
|
36
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('# Include Exclude', () => {
|
|
41
|
+
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
return Stack.connect().then((dbInstance) => {
|
|
44
|
+
db = dbInstance
|
|
45
|
+
debug('Stack connected successfully!')
|
|
46
|
+
|
|
47
|
+
return
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
beforeAll(async () => {
|
|
52
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
53
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
54
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
55
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
56
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
57
|
+
debug('Data populated..!')
|
|
58
|
+
|
|
59
|
+
return
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
afterAll(async () => {
|
|
63
|
+
await db.collection(collection.entry).drop()
|
|
64
|
+
// await db.collection(collection.asset).drop()
|
|
65
|
+
await db.collection(collection.schema).drop()
|
|
66
|
+
debug('Collections dropped..!')
|
|
67
|
+
|
|
68
|
+
return Stack.close()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('basic inclusion', () => {
|
|
72
|
+
test('1 .includeCount()', () => {
|
|
73
|
+
return Stack.contentType('blog')
|
|
74
|
+
.entries()
|
|
75
|
+
.includeCount()
|
|
76
|
+
.find()
|
|
77
|
+
.then((result: any) => {
|
|
78
|
+
debug(`# include-exclude: .includeCount() result\n${JSON.stringify(result)}`)
|
|
79
|
+
itemPropertyChecks(result)
|
|
80
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
81
|
+
expect(result.entries).toHaveLength(5)
|
|
82
|
+
expect(result).toHaveProperty('count')
|
|
83
|
+
expect(result.count).toEqual(5)
|
|
84
|
+
result.entries.forEach((entry) => {
|
|
85
|
+
expect(entry).toHaveProperty('no')
|
|
86
|
+
})
|
|
87
|
+
}).catch((error) => {
|
|
88
|
+
expect(error).toBeNull()
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('2 .includeSchema()', () => {
|
|
93
|
+
return Stack.contentType('blog')
|
|
94
|
+
.entries()
|
|
95
|
+
.includeSchema()
|
|
96
|
+
.find()
|
|
97
|
+
.then((result: any) => {
|
|
98
|
+
itemPropertyChecks(result)
|
|
99
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
100
|
+
expect(result.entries).toHaveLength(5)
|
|
101
|
+
expect(result).toHaveProperty('content_type')
|
|
102
|
+
expect(result.content_type).toHaveProperty('uid')
|
|
103
|
+
expect(result.content_type).toHaveProperty('title')
|
|
104
|
+
expect(result.content_type).toHaveProperty('schema')
|
|
105
|
+
}).catch((error) => {
|
|
106
|
+
expect(error).toBeNull()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('3 .excludeReferences()', () => {
|
|
111
|
+
return Stack.contentType('blog')
|
|
112
|
+
.entries()
|
|
113
|
+
.excludeReferences()
|
|
114
|
+
.find()
|
|
115
|
+
.then((result: any) => {
|
|
116
|
+
itemPropertyChecks(result)
|
|
117
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
118
|
+
expect(result.entries).toHaveLength(5)
|
|
119
|
+
result.entries.forEach((entry) => {
|
|
120
|
+
if (entry.hasOwnProperty('authors')) {
|
|
121
|
+
if (entry.authors instanceof Array) {
|
|
122
|
+
entry.authors.forEach((ref) => {
|
|
123
|
+
expect(ref).toHaveProperty('_content_type_uid')
|
|
124
|
+
expect(ref).toHaveProperty('uid')
|
|
125
|
+
})
|
|
126
|
+
} else {
|
|
127
|
+
expect(entry.authors).toHaveProperty('_content_type_uid')
|
|
128
|
+
expect(entry.authors).toHaveProperty('uid')
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}).catch((error) => {
|
|
133
|
+
expect(error).toBeNull()
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
describe('combination of include-exclude', () => {
|
|
139
|
+
test('1 .includeCount() + .includeSchema() + .excludeReferences()', () => {
|
|
140
|
+
return Stack.contentType('blog')
|
|
141
|
+
.entries()
|
|
142
|
+
.includeCount()
|
|
143
|
+
.includeSchema()
|
|
144
|
+
.excludeReferences()
|
|
145
|
+
.find()
|
|
146
|
+
.then((result: any) => {
|
|
147
|
+
itemPropertyChecks(result)
|
|
148
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
149
|
+
expect(result.entries).toHaveLength(5)
|
|
150
|
+
expect(result).toHaveProperty('count')
|
|
151
|
+
expect(result.count).toEqual(5)
|
|
152
|
+
expect(result).toHaveProperty('content_type')
|
|
153
|
+
expect(result.content_type).toHaveProperty('uid')
|
|
154
|
+
expect(result.content_type).toHaveProperty('title')
|
|
155
|
+
expect(result.content_type).toHaveProperty('schema')
|
|
156
|
+
result.entries.forEach((entry) => {
|
|
157
|
+
if (entry.authors && entry.authors instanceof Array) {
|
|
158
|
+
entry.authors.forEach((ref) => {
|
|
159
|
+
expect(ref).toHaveProperty('_content_type_uid')
|
|
160
|
+
expect(ref).toHaveProperty('uid')
|
|
161
|
+
expect(ref._content_type_uid).toEqual('author')
|
|
162
|
+
})
|
|
163
|
+
} else {
|
|
164
|
+
expect(entry.authors).toHaveProperty('_content_type_uid')
|
|
165
|
+
expect(entry.authors).toHaveProperty('uid')
|
|
166
|
+
expect(entry.authors._content_type_uid).toEqual('author')
|
|
167
|
+
}
|
|
168
|
+
expect(entry).toHaveProperty('no')
|
|
169
|
+
})
|
|
170
|
+
}).catch((error) => {
|
|
171
|
+
expect(error).toBeNull()
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
|
|
@@ -0,0 +1,140 @@
|
|
|
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.logical_operators'
|
|
17
|
+
collNameConfig.entry = 'contents.logical_operators'
|
|
18
|
+
collNameConfig.schema = 'content_types.logical_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 itemPropertyChecks = (result) => {
|
|
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
|
+
if (result.entries instanceof Array) {
|
|
35
|
+
result.entries.forEach((item) => {
|
|
36
|
+
expect(item).not.toHaveProperty('_content_type_uid')
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('# Logical Operator Querying', () => {
|
|
42
|
+
|
|
43
|
+
beforeAll(() => {
|
|
44
|
+
return Stack.connect().then((dbInstance) => {
|
|
45
|
+
db = dbInstance
|
|
46
|
+
|
|
47
|
+
return
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
beforeAll(async () => {
|
|
52
|
+
await db.collection(collection.entry).insertMany(authors)
|
|
53
|
+
await db.collection(collection.entry).insertMany(blogs)
|
|
54
|
+
await db.collection(collection.entry).insertMany(categories)
|
|
55
|
+
await db.collection(collection.asset).insertMany(assets)
|
|
56
|
+
await db.collection(collection.schema).insertMany(content_types)
|
|
57
|
+
|
|
58
|
+
return
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
afterAll(async () => {
|
|
62
|
+
await db.collection(collection.entry).drop()
|
|
63
|
+
// await db.collection(collection.asset).drop()
|
|
64
|
+
await db.collection(collection.schema).drop()
|
|
65
|
+
|
|
66
|
+
return Stack.close()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('on: non pre-existing operator', () => {
|
|
70
|
+
test('.and()', () => {
|
|
71
|
+
return Stack.contentType('blog')
|
|
72
|
+
.entries()
|
|
73
|
+
.and([{_content_type_uid: 'blog'}, {no: 1}])
|
|
74
|
+
.find()
|
|
75
|
+
.then((result: any) => {
|
|
76
|
+
itemPropertyChecks(result)
|
|
77
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
78
|
+
expect(result.entries).toHaveLength(1)
|
|
79
|
+
result.entries.forEach((entry) => {
|
|
80
|
+
expect(entry).toHaveProperty('no')
|
|
81
|
+
expect(entry.no).toEqual(1)
|
|
82
|
+
})
|
|
83
|
+
}).catch((error) => {
|
|
84
|
+
expect(error).toBeNull()
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('.or()', () => {
|
|
89
|
+
return Stack.contentType('blog')
|
|
90
|
+
.entries()
|
|
91
|
+
.or([{_content_type_uid: 'blogs'}, {no: 1}])
|
|
92
|
+
.find()
|
|
93
|
+
.then((result: any) => {
|
|
94
|
+
itemPropertyChecks(result)
|
|
95
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
96
|
+
expect(result.entries).toHaveLength(1)
|
|
97
|
+
result.entries.forEach((entry) => {
|
|
98
|
+
expect(entry).toHaveProperty('no')
|
|
99
|
+
expect(entry.no).toEqual(1)
|
|
100
|
+
})
|
|
101
|
+
}).catch((error) => {
|
|
102
|
+
expect(error).toBeNull()
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('on: pre-existing operator', () => {
|
|
109
|
+
test('.and()', () => {
|
|
110
|
+
return Stack.contentType('blog')
|
|
111
|
+
.entries()
|
|
112
|
+
.and([{no: 1}])
|
|
113
|
+
.and([{_content_type_uid: 'blogs'}])
|
|
114
|
+
.find()
|
|
115
|
+
.then((result: any) => {
|
|
116
|
+
itemPropertyChecks(result)
|
|
117
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
118
|
+
expect(result.entries).toHaveLength(0)
|
|
119
|
+
}).catch((error) => {
|
|
120
|
+
expect(error).toBeNull()
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('.or()', () => {
|
|
125
|
+
return Stack.contentType('blog')
|
|
126
|
+
.entries()
|
|
127
|
+
.or([{no: 1}])
|
|
128
|
+
.or([{_content_type_uid: 'blogs'}])
|
|
129
|
+
.find()
|
|
130
|
+
.then((result: any) => {
|
|
131
|
+
itemPropertyChecks(result)
|
|
132
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
133
|
+
expect(result.entries).toHaveLength(0)
|
|
134
|
+
}).catch((error) => {
|
|
135
|
+
expect(error).toBeNull()
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
@@ -0,0 +1,109 @@
|
|
|
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.projections'
|
|
17
|
+
collNameConfig.entry = 'contents.projections'
|
|
18
|
+
collNameConfig.schema = 'content_types.projections'
|
|
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('# Projections', () => {
|
|
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('basic', () => {
|
|
69
|
+
test('.only()', () => {
|
|
70
|
+
return Stack.contentType('blog')
|
|
71
|
+
.entries()
|
|
72
|
+
.only(['uid', 'title', '_id'])
|
|
73
|
+
.find()
|
|
74
|
+
.then((result: any) => {
|
|
75
|
+
checkEntries(result)
|
|
76
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
77
|
+
expect(result.entries).toHaveLength(5)
|
|
78
|
+
result.entries.forEach((entry) => {
|
|
79
|
+
expect(entry).toHaveProperty('uid')
|
|
80
|
+
expect(entry).toHaveProperty('title')
|
|
81
|
+
expect(entry).toHaveProperty('_id')
|
|
82
|
+
expect(Object.keys(entry)).toHaveLength(3)
|
|
83
|
+
})
|
|
84
|
+
}).catch((error) => {
|
|
85
|
+
expect(error).toBeNull()
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('.except()', () => {
|
|
90
|
+
return Stack.contentType('blog')
|
|
91
|
+
.entries()
|
|
92
|
+
.except(['uid', 'title'])
|
|
93
|
+
.find()
|
|
94
|
+
.then((result: any) => {
|
|
95
|
+
checkEntries(result)
|
|
96
|
+
expect(result).toHaveProperty('entries')
|
|
97
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
98
|
+
expect(result.entries).toHaveLength(5)
|
|
99
|
+
result.entries.forEach((entry) => {
|
|
100
|
+
expect(entry).not.toHaveProperty('uid')
|
|
101
|
+
expect(entry).not.toHaveProperty('title')
|
|
102
|
+
expect(entry).not.toHaveProperty('_id')
|
|
103
|
+
})
|
|
104
|
+
}).catch((error) => {
|
|
105
|
+
expect(error).toBeNull()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
})
|
package/test/queries.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
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.query_filters'
|
|
17
|
+
collNameConfig.entry = 'contents.query_filters'
|
|
18
|
+
collNameConfig.schema = 'content_types.query_filters'
|
|
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('# 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('basic querying', () => {
|
|
69
|
+
test('.query $and', () => {
|
|
70
|
+
return Stack.contentType('blog')
|
|
71
|
+
.entries()
|
|
72
|
+
.query({$and: [{_content_type_uid: 'blog'}, {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(1)
|
|
81
|
+
})
|
|
82
|
+
}).catch((error) => {
|
|
83
|
+
expect(error).toBeNull()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('.query $or', () => {
|
|
88
|
+
return Stack.contentType('blog')
|
|
89
|
+
.entries()
|
|
90
|
+
.query({$or: [{content_type_uid: 'blogs'}, {no: 1}]})
|
|
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(1)
|
|
99
|
+
})
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
expect(error).toBeNull()
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('.tags()', () => {
|
|
106
|
+
return Stack.contentType('blog')
|
|
107
|
+
.entries()
|
|
108
|
+
.tags(['last'])
|
|
109
|
+
.find()
|
|
110
|
+
.then((result: any) => {
|
|
111
|
+
checkEntries(result)
|
|
112
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
113
|
+
expect(result.entries).toHaveLength(1)
|
|
114
|
+
result.entries.forEach((entry) => {
|
|
115
|
+
expect(entry).toHaveProperty('tags')
|
|
116
|
+
expect(entry.tags).toContain('last')
|
|
117
|
+
})
|
|
118
|
+
}).catch((error) => {
|
|
119
|
+
expect(error).toBeNull()
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('.query + .tags()', () => {
|
|
124
|
+
return Stack.contentType('blog')
|
|
125
|
+
.entries()
|
|
126
|
+
.query({$or: [{content_type_uid: 'blogs'}, {tags: {$exists: true}}]})
|
|
127
|
+
.tags(['last'])
|
|
128
|
+
.find()
|
|
129
|
+
.then((result: any) => {
|
|
130
|
+
checkEntries(result)
|
|
131
|
+
expect(result.content_type_uid).toEqual('blog')
|
|
132
|
+
expect(result.entries).toHaveLength(1)
|
|
133
|
+
result.entries.forEach((entry) => {
|
|
134
|
+
expect(entry).toHaveProperty('tags')
|
|
135
|
+
expect(entry.tags).toContain('last')
|
|
136
|
+
})
|
|
137
|
+
}).catch((error) => {
|
|
138
|
+
expect(error).toBeNull()
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
|