@jsreport/jsreport-core 3.0.1 → 3.1.2-test.2
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/LICENSE +166 -166
- package/README.md +298 -284
- package/index.js +29 -27
- package/lib/main/blobStorage/blobStorage.js +52 -47
- package/lib/main/blobStorage/inMemoryProvider.js +27 -27
- package/lib/main/blobStorage/mainActions.js +24 -24
- package/lib/main/createDefaultLoggerFormat.js +17 -17
- package/lib/main/defaults.js +14 -14
- package/lib/main/extensions/discover.js +20 -20
- package/lib/main/extensions/extensionsManager.js +264 -265
- package/lib/main/extensions/fileUtils.js +56 -55
- package/lib/main/extensions/findVersion.js +49 -53
- package/lib/main/extensions/locationCache.js +103 -97
- package/lib/main/extensions/sorter.js +10 -10
- package/lib/main/extensions/validateMinimalVersion.js +50 -50
- package/lib/main/folders/cascadeFolderRemove.js +25 -25
- package/lib/main/folders/getEntitiesInFolder.js +53 -53
- package/lib/main/folders/index.js +42 -42
- package/lib/main/folders/moveBetweenFolders.js +354 -354
- package/lib/main/folders/validateDuplicatedName.js +107 -107
- package/lib/main/folders/validateReservedName.js +53 -53
- package/lib/main/logger.js +244 -244
- package/lib/main/migration/resourcesToAssets.js +230 -210
- package/lib/main/migration/xlsxTemplatesToAssets.js +128 -118
- package/lib/main/monitoring.js +91 -91
- package/lib/main/optionsLoad.js +237 -237
- package/lib/main/optionsSchema.js +237 -237
- package/lib/main/reporter.js +579 -578
- package/lib/main/schemaValidator.js +252 -252
- package/lib/main/settings.js +154 -154
- package/lib/main/store/checkDuplicatedId.js +27 -27
- package/lib/main/store/collection.js +329 -329
- package/lib/main/store/documentStore.js +469 -469
- package/lib/main/store/mainActions.js +28 -28
- package/lib/main/store/memoryStoreProvider.js +99 -99
- package/lib/main/store/queue.js +48 -48
- package/lib/main/store/referenceUtils.js +251 -251
- package/lib/main/store/setupValidateId.js +43 -43
- package/lib/main/store/setupValidateShortid.js +71 -71
- package/lib/main/store/transaction.js +69 -69
- package/lib/main/store/typeUtils.js +180 -180
- package/lib/main/templates.js +34 -34
- package/lib/main/validateEntityName.js +62 -62
- package/lib/shared/createError.js +36 -36
- package/lib/shared/encryption.js +114 -114
- package/lib/shared/folders/index.js +11 -11
- package/lib/shared/folders/normalizeEntityPath.js +15 -15
- package/lib/shared/folders/resolveEntityFromPath.js +88 -88
- package/lib/shared/folders/resolveEntityPath.js +46 -46
- package/lib/shared/folders/resolveFolderFromPath.js +38 -38
- package/lib/shared/generateRequestId.js +4 -4
- package/lib/shared/listenerCollection.js +169 -0
- package/lib/shared/normalizeMetaFromLogs.js +30 -30
- package/lib/shared/reporter.js +123 -123
- package/lib/shared/request.js +64 -64
- package/lib/shared/tempFilesHandler.js +81 -81
- package/lib/shared/templates.js +82 -82
- package/lib/static/helpers.js +33 -33
- package/lib/worker/blobStorage.js +34 -34
- package/lib/worker/defaultProxyExtend.js +46 -46
- package/lib/worker/documentStore.js +49 -49
- package/lib/worker/extensionsManager.js +17 -17
- package/lib/worker/logger.js +48 -48
- package/lib/worker/render/diff.js +138 -138
- package/lib/worker/render/executeEngine.js +207 -200
- package/lib/worker/render/htmlRecipe.js +10 -10
- package/lib/worker/render/moduleHelper.js +43 -43
- package/lib/worker/render/noneEngine.js +12 -12
- package/lib/worker/render/profiler.js +158 -158
- package/lib/worker/render/render.js +205 -209
- package/lib/worker/render/resolveReferences.js +60 -60
- package/lib/worker/reporter.js +191 -187
- package/lib/worker/sandbox/runInSandbox.js +13 -4
- package/lib/worker/sandbox/safeSandbox.js +828 -822
- package/lib/worker/templates.js +78 -78
- package/lib/worker/workerHandler.js +54 -54
- package/package.json +92 -92
- package/test/blobStorage/common.js +21 -21
- package/test/store/common.js +1449 -1449
package/test/store/common.js
CHANGED
|
@@ -1,1449 +1,1449 @@
|
|
|
1
|
-
const should = require('should')
|
|
2
|
-
const Request = require('../../lib/shared/request')
|
|
3
|
-
|
|
4
|
-
module.exports = (store, runTransactions = true) => {
|
|
5
|
-
describe('public collection', () => {
|
|
6
|
-
collectionTests(store, undefined, runTransactions)
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
describe('internal collection', () => {
|
|
10
|
-
collectionTests(store, true, runTransactions)
|
|
11
|
-
})
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function collectionTests (store, isInternal, runTransactions) {
|
|
15
|
-
function getCollection (name) {
|
|
16
|
-
if (!isInternal) {
|
|
17
|
-
return store().collection(name)
|
|
18
|
-
} else {
|
|
19
|
-
return store().internalCollection(name)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
it('insert and query', async () => {
|
|
24
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
25
|
-
|
|
26
|
-
await getCollection(colName).insert({
|
|
27
|
-
name: 'test',
|
|
28
|
-
engine: 'none',
|
|
29
|
-
recipe: 'html'
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const res = await getCollection(colName).find({ name: 'test' })
|
|
33
|
-
res.length.should.be.eql(1)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('insert and query with condition', async () => {
|
|
37
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
38
|
-
|
|
39
|
-
await getCollection(colName).insert({
|
|
40
|
-
name: 'test',
|
|
41
|
-
engine: 'none',
|
|
42
|
-
recipe: 'html'
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const res = await getCollection(colName).find({ name: 'diferent' })
|
|
46
|
-
res.length.should.be.eql(0)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('insert, update, query', async () => {
|
|
50
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
51
|
-
|
|
52
|
-
await getCollection(colName).insert({
|
|
53
|
-
name: 'test',
|
|
54
|
-
engine: 'none',
|
|
55
|
-
recipe: 'html'
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
await getCollection(colName).update({ name: 'test' }, { $set: { recipe: 'foo' } })
|
|
59
|
-
const res = await getCollection(colName).find({ name: 'test' })
|
|
60
|
-
res.length.should.be.eql(1)
|
|
61
|
-
res[0].recipe.should.be.eql('foo')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('insert remove query', async () => {
|
|
65
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
66
|
-
|
|
67
|
-
await getCollection(colName).insert({
|
|
68
|
-
name: 'test',
|
|
69
|
-
engine: 'none',
|
|
70
|
-
recipe: 'html'
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
await getCollection(colName).remove({ name: 'test' })
|
|
74
|
-
const res = await getCollection(colName).find({ name: 'test' })
|
|
75
|
-
res.length.should.be.eql(0)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('insert should return an object with _id set', async () => {
|
|
79
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
80
|
-
|
|
81
|
-
const doc = await getCollection(colName).insert({
|
|
82
|
-
name: 'test',
|
|
83
|
-
engine: 'none',
|
|
84
|
-
recipe: 'html'
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
doc.should.have.property('_id')
|
|
88
|
-
doc._id.should.be.ok()
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('update with upsert', async () => {
|
|
92
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
93
|
-
|
|
94
|
-
await getCollection(colName).update({ name: 'test' }, {
|
|
95
|
-
$set: {
|
|
96
|
-
name: 'test2',
|
|
97
|
-
engine: 'none',
|
|
98
|
-
recipe: 'html'
|
|
99
|
-
}
|
|
100
|
-
}, { upsert: true })
|
|
101
|
-
const res = await getCollection(colName).find({ name: 'test2' })
|
|
102
|
-
res.length.should.be.eql(1)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('find should return clones', async () => {
|
|
106
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
107
|
-
|
|
108
|
-
await getCollection(colName).insert({
|
|
109
|
-
name: 'test',
|
|
110
|
-
engine: 'none',
|
|
111
|
-
recipe: 'html',
|
|
112
|
-
content: 'original',
|
|
113
|
-
phantom: { header: 'original' }
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
const res = await getCollection(colName).find({})
|
|
117
|
-
res[0].content = 'modified'
|
|
118
|
-
res[0].phantom.header = 'modified'
|
|
119
|
-
const res2 = await getCollection(colName).find({})
|
|
120
|
-
res2[0].content.should.be.eql('original')
|
|
121
|
-
res2[0].phantom.header.should.be.eql('original')
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('insert should use clones', async () => {
|
|
125
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
126
|
-
|
|
127
|
-
const doc = {
|
|
128
|
-
name: 'test',
|
|
129
|
-
engine: 'none',
|
|
130
|
-
recipe: 'html',
|
|
131
|
-
content: 'original',
|
|
132
|
-
phantom: { header: 'original' }
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
await getCollection(colName).insert(doc)
|
|
136
|
-
|
|
137
|
-
doc.content = 'modified'
|
|
138
|
-
doc.phantom.header = 'modified'
|
|
139
|
-
const res = await getCollection(colName).find({})
|
|
140
|
-
res[0].content.should.be.eql('original')
|
|
141
|
-
res[0].phantom.header.should.be.eql('original')
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('skip and limit', async () => {
|
|
145
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
146
|
-
|
|
147
|
-
await getCollection(colName).insert({
|
|
148
|
-
name: '1',
|
|
149
|
-
engine: 'none',
|
|
150
|
-
recipe: 'html'
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
await getCollection(colName).insert({
|
|
154
|
-
name: '3',
|
|
155
|
-
engine: 'none',
|
|
156
|
-
recipe: 'html'
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
await getCollection(colName).insert({
|
|
160
|
-
name: '2',
|
|
161
|
-
engine: 'none',
|
|
162
|
-
recipe: 'html'
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
const res = await getCollection(colName).find({}).sort({ name: 1 }).skip(1).limit(1).toArray()
|
|
166
|
-
res.length.should.be.eql(1)
|
|
167
|
-
res[0].name.should.be.eql('2')
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('$and', async () => {
|
|
171
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
172
|
-
|
|
173
|
-
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
174
|
-
await getCollection(colName).insert({ name: '2', engine: 'none', recipe: 'b' })
|
|
175
|
-
await getCollection(colName).insert({ name: '3', engine: 'none', recipe: 'b' })
|
|
176
|
-
|
|
177
|
-
const res = await getCollection(colName).find({ $and: [{ name: '2' }, { recipe: 'b' }] }).toArray()
|
|
178
|
-
res.length.should.be.eql(1)
|
|
179
|
-
res[0].name.should.be.eql('2')
|
|
180
|
-
res[0].recipe.should.be.eql('b')
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
it('projection', async () => {
|
|
184
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
185
|
-
|
|
186
|
-
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
187
|
-
|
|
188
|
-
const res = await getCollection(colName).find({}, { recipe: 1 })
|
|
189
|
-
res.length.should.be.eql(1)
|
|
190
|
-
res[0].should.not.have.property('name')
|
|
191
|
-
res[0].recipe.should.be.eql('a')
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('count', async () => {
|
|
195
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
196
|
-
|
|
197
|
-
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
198
|
-
|
|
199
|
-
const res = await getCollection(colName).find({}).count()
|
|
200
|
-
res.should.be.eql(1)
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
it('count without cursor', async () => {
|
|
204
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
205
|
-
|
|
206
|
-
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
207
|
-
|
|
208
|
-
const res = await getCollection(colName).count({})
|
|
209
|
-
res.should.be.eql(1)
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
it('projection should not be applied when second param is request', async () => {
|
|
213
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
214
|
-
|
|
215
|
-
await getCollection(colName).insert({ name: 'test', engine: 'none', recipe: 'html' })
|
|
216
|
-
const res = await getCollection(colName).find({ name: 'test' }, Request({ template: {} }))
|
|
217
|
-
res[0].name.should.be.eql('test')
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
it('update should return 1 if upsert', async () => {
|
|
221
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
222
|
-
|
|
223
|
-
const res = await getCollection(colName).update({ name: 'test' }, { $set: { name: 'test2', engine: 'none', recipe: 'html' } }, { upsert: true })
|
|
224
|
-
res.should.be.eql(1)
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
it('update should return number of updated items', async () => {
|
|
228
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
229
|
-
|
|
230
|
-
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
231
|
-
await getCollection(colName).insert({ name: '2', engine: 'none', recipe: 'a' })
|
|
232
|
-
const res = await getCollection(colName).update({ recipe: 'a' }, { $set: { engine: 'test2' } })
|
|
233
|
-
res.should.be.eql(2)
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
it('should validate duplicated _id on insert', async () => {
|
|
237
|
-
const newEntity = await store().collection('templates').insert({
|
|
238
|
-
name: 'a',
|
|
239
|
-
content: 'x',
|
|
240
|
-
engine: 'none',
|
|
241
|
-
recipe: 'html'
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
return should(store().collection('templates').insert({
|
|
245
|
-
_id: newEntity._id,
|
|
246
|
-
name: 'b',
|
|
247
|
-
content: 'x',
|
|
248
|
-
engine: 'none',
|
|
249
|
-
recipe: 'html'
|
|
250
|
-
})).be.rejected()
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
it('should validate duplicated _id on update', async () => {
|
|
254
|
-
const a = await store().collection('templates').insert({
|
|
255
|
-
name: 'a',
|
|
256
|
-
engine: 'none',
|
|
257
|
-
recipe: 'html'
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
const b = await store().collection('templates').insert({
|
|
261
|
-
name: 'b',
|
|
262
|
-
engine: 'none',
|
|
263
|
-
recipe: 'html'
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
return should(store().collection('templates').update({
|
|
267
|
-
_id: a._id
|
|
268
|
-
}, {
|
|
269
|
-
$set: {
|
|
270
|
-
_id: b._id
|
|
271
|
-
}
|
|
272
|
-
})).be.rejected()
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
it('should validate duplicated shortid on upsert', async () => {
|
|
276
|
-
const a = await store().collection('templates').insert({
|
|
277
|
-
name: 'a',
|
|
278
|
-
engine: 'none',
|
|
279
|
-
recipe: 'html'
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
return should(store().collection('templates').update({
|
|
283
|
-
name: 'b'
|
|
284
|
-
}, {
|
|
285
|
-
$set: {
|
|
286
|
-
_id: a._id,
|
|
287
|
-
name: 'b'
|
|
288
|
-
}
|
|
289
|
-
}, { upsert: true })).be.rejected()
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
it('should validate duplicated shortid on insert', async () => {
|
|
293
|
-
await store().collection('templates').insert({
|
|
294
|
-
name: 'a',
|
|
295
|
-
shortid: 'a',
|
|
296
|
-
engine: 'none',
|
|
297
|
-
recipe: 'html'
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
return should(store().collection('templates').insert({
|
|
301
|
-
name: 'b',
|
|
302
|
-
shortid: 'a',
|
|
303
|
-
engine: 'none',
|
|
304
|
-
recipe: 'html'
|
|
305
|
-
})).be.rejected()
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
it('should validate duplicated shortid on update', async () => {
|
|
309
|
-
const a = await store().collection('templates').insert({
|
|
310
|
-
name: 'a',
|
|
311
|
-
shortid: 'a',
|
|
312
|
-
engine: 'none',
|
|
313
|
-
recipe: 'html'
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
await store().collection('templates').insert({
|
|
317
|
-
name: 'b',
|
|
318
|
-
shortid: 'b',
|
|
319
|
-
engine: 'none',
|
|
320
|
-
recipe: 'html'
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
return should(store().collection('templates').update({
|
|
324
|
-
_id: a._id
|
|
325
|
-
}, {
|
|
326
|
-
$set: {
|
|
327
|
-
shortid: 'b'
|
|
328
|
-
}
|
|
329
|
-
})).be.rejected()
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
it('should validate duplicated shortid on upsert', async () => {
|
|
333
|
-
await store().collection('templates').insert({
|
|
334
|
-
name: 'a',
|
|
335
|
-
shortid: 'a',
|
|
336
|
-
engine: 'none',
|
|
337
|
-
recipe: 'html'
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
return should(store().collection('templates').update({
|
|
341
|
-
name: 'b'
|
|
342
|
-
}, {
|
|
343
|
-
$set: {
|
|
344
|
-
name: 'b',
|
|
345
|
-
shortid: 'a'
|
|
346
|
-
}
|
|
347
|
-
}, { upsert: true })).be.rejected()
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
if (runTransactions) {
|
|
351
|
-
describe('transactions', () => {
|
|
352
|
-
it('should be able to start', async () => {
|
|
353
|
-
const req = Request({})
|
|
354
|
-
await store().beginTransaction(req)
|
|
355
|
-
req.context.storeTransaction.should.be.not.empty()
|
|
356
|
-
await store().commitTransaction(req)
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
it('should fail when trying to start more than once', async () => {
|
|
360
|
-
const req = Request({})
|
|
361
|
-
|
|
362
|
-
await store().beginTransaction(req)
|
|
363
|
-
|
|
364
|
-
try {
|
|
365
|
-
await store().beginTransaction(req)
|
|
366
|
-
throw new Error('it should have failed calling beginTransaction twice')
|
|
367
|
-
} catch (e) {
|
|
368
|
-
e.message.should.containEql('active transaction already exists')
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
await store().commitTransaction(req)
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
it('should fail when commit without start', async () => {
|
|
375
|
-
const req = Request({})
|
|
376
|
-
return should(store().commitTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
377
|
-
})
|
|
378
|
-
|
|
379
|
-
it('should fail when rollback without start', async () => {
|
|
380
|
-
const req = Request({})
|
|
381
|
-
return should(store().rollbackTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
382
|
-
})
|
|
383
|
-
|
|
384
|
-
it('should fail when commit more than once', async () => {
|
|
385
|
-
const req = Request({})
|
|
386
|
-
|
|
387
|
-
await store().beginTransaction(req)
|
|
388
|
-
await store().commitTransaction(req)
|
|
389
|
-
|
|
390
|
-
return should(store().commitTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
it('should fail when rollback more than once', async () => {
|
|
394
|
-
const req = Request({})
|
|
395
|
-
|
|
396
|
-
await store().beginTransaction(req)
|
|
397
|
-
await store().rollbackTransaction(req)
|
|
398
|
-
|
|
399
|
-
return should(store().rollbackTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
400
|
-
})
|
|
401
|
-
|
|
402
|
-
it('should fail when rollback after commit', async () => {
|
|
403
|
-
const req = Request({})
|
|
404
|
-
|
|
405
|
-
await store().beginTransaction(req)
|
|
406
|
-
await store().commitTransaction(req)
|
|
407
|
-
|
|
408
|
-
return should(store().rollbackTransaction(req)).rejectedWith(/without an active transaction/)
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
it('should fail when commit after rollback', async () => {
|
|
412
|
-
const req = Request({})
|
|
413
|
-
|
|
414
|
-
await store().beginTransaction(req)
|
|
415
|
-
await store().rollbackTransaction(req)
|
|
416
|
-
|
|
417
|
-
return should(store().commitTransaction(req)).rejectedWith(/without an active transaction/)
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
it('should be able to commit (insert)', async () => {
|
|
421
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
422
|
-
const req = Request({})
|
|
423
|
-
|
|
424
|
-
await store().beginTransaction(req)
|
|
425
|
-
|
|
426
|
-
try {
|
|
427
|
-
const t1 = {
|
|
428
|
-
name: 't1',
|
|
429
|
-
engine: 'none',
|
|
430
|
-
recipe: 'html'
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
await getCollection(colName).insert(t1, req)
|
|
434
|
-
|
|
435
|
-
await store().commitTransaction(req)
|
|
436
|
-
} catch (e) {
|
|
437
|
-
await store().rollbackTransaction(req)
|
|
438
|
-
throw e
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
442
|
-
|
|
443
|
-
should(found != null).be.True()
|
|
444
|
-
})
|
|
445
|
-
|
|
446
|
-
it('should be able to rollback (insert)', async () => {
|
|
447
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
448
|
-
const req = Request({})
|
|
449
|
-
await store().beginTransaction(req)
|
|
450
|
-
|
|
451
|
-
const t1 = {
|
|
452
|
-
name: 't1',
|
|
453
|
-
engine: 'none',
|
|
454
|
-
recipe: 'html'
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
await getCollection(colName).insert(t1, req)
|
|
458
|
-
|
|
459
|
-
await store().rollbackTransaction(req)
|
|
460
|
-
|
|
461
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
462
|
-
|
|
463
|
-
should(found == null).be.True()
|
|
464
|
-
})
|
|
465
|
-
|
|
466
|
-
it('should be able to commit (update)', async () => {
|
|
467
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
468
|
-
const req = Request({})
|
|
469
|
-
|
|
470
|
-
const t1 = {
|
|
471
|
-
name: 't1',
|
|
472
|
-
content: 't1',
|
|
473
|
-
engine: 'none',
|
|
474
|
-
recipe: 'html'
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
await getCollection(colName).insert(t1)
|
|
478
|
-
|
|
479
|
-
await store().beginTransaction(req)
|
|
480
|
-
|
|
481
|
-
try {
|
|
482
|
-
await getCollection(colName).update({
|
|
483
|
-
name: 't1'
|
|
484
|
-
}, {
|
|
485
|
-
$set: {
|
|
486
|
-
content: 't1-new',
|
|
487
|
-
engine: 'handlebars'
|
|
488
|
-
}
|
|
489
|
-
}, req)
|
|
490
|
-
|
|
491
|
-
await store().commitTransaction(req)
|
|
492
|
-
} catch (e) {
|
|
493
|
-
await store().rollbackTransaction(req)
|
|
494
|
-
throw e
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
498
|
-
|
|
499
|
-
should(found.engine).be.eql('handlebars')
|
|
500
|
-
should(found.content).be.eql('t1-new')
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
it('should be able to rollback (update)', async () => {
|
|
504
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
505
|
-
const req = Request({})
|
|
506
|
-
|
|
507
|
-
const t1 = {
|
|
508
|
-
name: 't1',
|
|
509
|
-
engine: 'none',
|
|
510
|
-
recipe: 'html'
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
await getCollection(colName).insert(t1)
|
|
514
|
-
|
|
515
|
-
await store().beginTransaction(req)
|
|
516
|
-
|
|
517
|
-
await getCollection(colName).update({
|
|
518
|
-
name: 't1'
|
|
519
|
-
}, {
|
|
520
|
-
$set: {
|
|
521
|
-
engine: 'handlebars'
|
|
522
|
-
}
|
|
523
|
-
}, req)
|
|
524
|
-
|
|
525
|
-
await store().rollbackTransaction(req)
|
|
526
|
-
|
|
527
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
528
|
-
|
|
529
|
-
should(found.engine).be.eql('none')
|
|
530
|
-
})
|
|
531
|
-
|
|
532
|
-
it('should be able to commit (upsert)', async () => {
|
|
533
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
534
|
-
const req = Request({})
|
|
535
|
-
|
|
536
|
-
const t1 = {
|
|
537
|
-
name: 't1',
|
|
538
|
-
engine: 'none',
|
|
539
|
-
recipe: 'html'
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
await store().beginTransaction(req)
|
|
543
|
-
|
|
544
|
-
try {
|
|
545
|
-
await getCollection(colName).insert(t1, req)
|
|
546
|
-
|
|
547
|
-
await getCollection(colName).update({
|
|
548
|
-
name: 't1'
|
|
549
|
-
}, {
|
|
550
|
-
$set: {
|
|
551
|
-
engine: 'handlebars'
|
|
552
|
-
}
|
|
553
|
-
}, req)
|
|
554
|
-
|
|
555
|
-
await store().commitTransaction(req)
|
|
556
|
-
} catch (e) {
|
|
557
|
-
await store().rollbackTransaction(req)
|
|
558
|
-
throw e
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
562
|
-
|
|
563
|
-
should(found != null).be.True()
|
|
564
|
-
})
|
|
565
|
-
|
|
566
|
-
it('should be able to rollback (upsert)', async () => {
|
|
567
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
568
|
-
const req = Request({})
|
|
569
|
-
|
|
570
|
-
const t1 = {
|
|
571
|
-
name: 't1',
|
|
572
|
-
engine: 'none',
|
|
573
|
-
recipe: 'html'
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
await store().beginTransaction(req)
|
|
577
|
-
|
|
578
|
-
await getCollection(colName).insert(t1, req)
|
|
579
|
-
|
|
580
|
-
await getCollection(colName).update({
|
|
581
|
-
name: 't1'
|
|
582
|
-
}, {
|
|
583
|
-
$set: {
|
|
584
|
-
engine: 'handlebars'
|
|
585
|
-
}
|
|
586
|
-
}, req)
|
|
587
|
-
|
|
588
|
-
await store().rollbackTransaction(req)
|
|
589
|
-
|
|
590
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
591
|
-
|
|
592
|
-
should(found == null).be.True()
|
|
593
|
-
})
|
|
594
|
-
|
|
595
|
-
it('should be able to commit (remove)', async () => {
|
|
596
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
597
|
-
const req = Request({})
|
|
598
|
-
|
|
599
|
-
const t1 = {
|
|
600
|
-
name: 't1',
|
|
601
|
-
engine: 'none',
|
|
602
|
-
recipe: 'html'
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
await getCollection(colName).insert(t1)
|
|
606
|
-
|
|
607
|
-
await store().beginTransaction(req)
|
|
608
|
-
|
|
609
|
-
try {
|
|
610
|
-
await getCollection(colName).remove({
|
|
611
|
-
name: 't1'
|
|
612
|
-
}, req)
|
|
613
|
-
|
|
614
|
-
await store().commitTransaction(req)
|
|
615
|
-
} catch (e) {
|
|
616
|
-
await store().rollbackTransaction(req)
|
|
617
|
-
throw e
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
621
|
-
|
|
622
|
-
should(found == null).be.True()
|
|
623
|
-
})
|
|
624
|
-
|
|
625
|
-
it('should be able to rollback (remove)', async () => {
|
|
626
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
627
|
-
const req = Request({})
|
|
628
|
-
|
|
629
|
-
const t1 = {
|
|
630
|
-
name: 't1',
|
|
631
|
-
engine: 'none',
|
|
632
|
-
recipe: 'html'
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
await getCollection(colName).insert(t1)
|
|
636
|
-
|
|
637
|
-
await store().beginTransaction(req)
|
|
638
|
-
|
|
639
|
-
await getCollection(colName).remove({
|
|
640
|
-
name: 't1'
|
|
641
|
-
}, req)
|
|
642
|
-
|
|
643
|
-
await store().rollbackTransaction(req)
|
|
644
|
-
|
|
645
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
646
|
-
|
|
647
|
-
should(found != null).be.True()
|
|
648
|
-
})
|
|
649
|
-
|
|
650
|
-
it('should be able to commit across collections', async () => {
|
|
651
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
652
|
-
const colName2 = !isInternal ? 'templates2' : 'internalTemplates2'
|
|
653
|
-
|
|
654
|
-
const req = Request({})
|
|
655
|
-
await store().beginTransaction(req)
|
|
656
|
-
|
|
657
|
-
try {
|
|
658
|
-
const t1 = {
|
|
659
|
-
name: 't1',
|
|
660
|
-
engine: 'none',
|
|
661
|
-
recipe: 'html'
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
const t2 = {
|
|
665
|
-
name: 't2',
|
|
666
|
-
engine: 'none',
|
|
667
|
-
recipe: 'html'
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
await getCollection(colName).insert(t1, req)
|
|
671
|
-
await getCollection(colName2).insert(t2, req)
|
|
672
|
-
|
|
673
|
-
await store().commitTransaction(req)
|
|
674
|
-
} catch (e) {
|
|
675
|
-
await store().rollbackTransaction(req)
|
|
676
|
-
throw e
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
680
|
-
const found2 = await getCollection(colName2).findOne({ name: 't2' })
|
|
681
|
-
|
|
682
|
-
should(found != null).be.True()
|
|
683
|
-
should(found2 != null).be.True()
|
|
684
|
-
})
|
|
685
|
-
|
|
686
|
-
it('should be able to rollback across collections', async () => {
|
|
687
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
688
|
-
const colName2 = !isInternal ? 'templates2' : 'internalTemplates2'
|
|
689
|
-
const req = Request({})
|
|
690
|
-
await store().beginTransaction(req)
|
|
691
|
-
|
|
692
|
-
const t1 = {
|
|
693
|
-
name: 't1',
|
|
694
|
-
engine: 'none',
|
|
695
|
-
recipe: 'html'
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
const t2 = {
|
|
699
|
-
name: 't2',
|
|
700
|
-
engine: 'none',
|
|
701
|
-
recipe: 'html'
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
await getCollection(colName).insert(t1, req)
|
|
705
|
-
await getCollection(colName).insert(t2, req)
|
|
706
|
-
|
|
707
|
-
await store().rollbackTransaction(req)
|
|
708
|
-
|
|
709
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
710
|
-
const found2 = await getCollection(colName2).findOne({ name: 't1' })
|
|
711
|
-
|
|
712
|
-
should(found == null).be.True()
|
|
713
|
-
should(found2 == null).be.True()
|
|
714
|
-
})
|
|
715
|
-
|
|
716
|
-
it('should be able to see entity created inside transaction', async () => {
|
|
717
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
718
|
-
const req = Request({})
|
|
719
|
-
await store().beginTransaction(req)
|
|
720
|
-
|
|
721
|
-
try {
|
|
722
|
-
const t1 = {
|
|
723
|
-
name: 't1',
|
|
724
|
-
engine: 'none',
|
|
725
|
-
recipe: 'html'
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
await getCollection(colName).insert(t1, req)
|
|
729
|
-
|
|
730
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
731
|
-
|
|
732
|
-
should(found != null).be.True()
|
|
733
|
-
|
|
734
|
-
await store().commitTransaction(req)
|
|
735
|
-
} catch (e) {
|
|
736
|
-
await store().rollbackTransaction(req)
|
|
737
|
-
throw e
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
741
|
-
|
|
742
|
-
should(found != null).be.True()
|
|
743
|
-
})
|
|
744
|
-
|
|
745
|
-
it('should be able to see entity updated inside transaction', async () => {
|
|
746
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
747
|
-
const req = Request({})
|
|
748
|
-
|
|
749
|
-
const t1 = {
|
|
750
|
-
name: 't1',
|
|
751
|
-
engine: 'none',
|
|
752
|
-
recipe: 'html'
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
await getCollection(colName).insert(t1)
|
|
756
|
-
|
|
757
|
-
await store().beginTransaction(req)
|
|
758
|
-
|
|
759
|
-
try {
|
|
760
|
-
await getCollection(colName).update({
|
|
761
|
-
name: 't1'
|
|
762
|
-
}, {
|
|
763
|
-
$set: {
|
|
764
|
-
engine: 'handlebars'
|
|
765
|
-
}
|
|
766
|
-
}, req)
|
|
767
|
-
|
|
768
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
769
|
-
|
|
770
|
-
should(found != null).be.True()
|
|
771
|
-
|
|
772
|
-
await store().commitTransaction(req)
|
|
773
|
-
} catch (e) {
|
|
774
|
-
await store().rollbackTransaction(req)
|
|
775
|
-
throw e
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
779
|
-
|
|
780
|
-
should(found != null).be.True()
|
|
781
|
-
})
|
|
782
|
-
|
|
783
|
-
it('should be able to see entity updated properties inside transaction', async () => {
|
|
784
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
785
|
-
const req = Request({})
|
|
786
|
-
|
|
787
|
-
const t1 = {
|
|
788
|
-
name: 't1',
|
|
789
|
-
engine: 'none',
|
|
790
|
-
recipe: 'html'
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
await getCollection(colName).insert(t1)
|
|
794
|
-
|
|
795
|
-
await store().beginTransaction(req)
|
|
796
|
-
|
|
797
|
-
try {
|
|
798
|
-
await getCollection(colName).update({
|
|
799
|
-
name: 't1'
|
|
800
|
-
}, {
|
|
801
|
-
$set: {
|
|
802
|
-
engine: 'handlebars'
|
|
803
|
-
}
|
|
804
|
-
}, req)
|
|
805
|
-
|
|
806
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
807
|
-
|
|
808
|
-
should(found.engine).be.eql('handlebars')
|
|
809
|
-
|
|
810
|
-
await store().commitTransaction(req)
|
|
811
|
-
} catch (e) {
|
|
812
|
-
await store().rollbackTransaction(req)
|
|
813
|
-
throw e
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
817
|
-
|
|
818
|
-
should(found.engine).be.eql('handlebars')
|
|
819
|
-
})
|
|
820
|
-
|
|
821
|
-
it('should be able to see entity upsert inside transaction', async () => {
|
|
822
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
823
|
-
const req = Request({})
|
|
824
|
-
|
|
825
|
-
const t1 = {
|
|
826
|
-
name: 't1',
|
|
827
|
-
engine: 'none',
|
|
828
|
-
recipe: 'html'
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
await store().beginTransaction(req)
|
|
832
|
-
|
|
833
|
-
try {
|
|
834
|
-
await getCollection(colName).insert(t1, req)
|
|
835
|
-
|
|
836
|
-
await getCollection(colName).update({
|
|
837
|
-
name: 't1'
|
|
838
|
-
}, {
|
|
839
|
-
$set: {
|
|
840
|
-
engine: 'handlebars'
|
|
841
|
-
}
|
|
842
|
-
}, req)
|
|
843
|
-
|
|
844
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
845
|
-
|
|
846
|
-
should(found != null).be.True()
|
|
847
|
-
|
|
848
|
-
await store().commitTransaction(req)
|
|
849
|
-
} catch (e) {
|
|
850
|
-
await store().rollbackTransaction(req)
|
|
851
|
-
throw e
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
855
|
-
|
|
856
|
-
should(found != null).be.True()
|
|
857
|
-
})
|
|
858
|
-
|
|
859
|
-
it('should not be able to see entity removed inside transaction', async () => {
|
|
860
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
861
|
-
const req = Request({})
|
|
862
|
-
|
|
863
|
-
const t1 = {
|
|
864
|
-
name: 't1',
|
|
865
|
-
engine: 'none',
|
|
866
|
-
recipe: 'html'
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
await getCollection(colName).insert(t1)
|
|
870
|
-
|
|
871
|
-
await store().beginTransaction(req)
|
|
872
|
-
|
|
873
|
-
try {
|
|
874
|
-
await getCollection(colName).remove({
|
|
875
|
-
name: 't1'
|
|
876
|
-
}, req)
|
|
877
|
-
|
|
878
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
879
|
-
|
|
880
|
-
should(found == null).be.True()
|
|
881
|
-
|
|
882
|
-
await store().commitTransaction(req)
|
|
883
|
-
} catch (e) {
|
|
884
|
-
await store().rollbackTransaction(req)
|
|
885
|
-
throw e
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
889
|
-
|
|
890
|
-
should(found == null).be.True()
|
|
891
|
-
})
|
|
892
|
-
|
|
893
|
-
it('should not be able to see entity created in transaction from outside', async () => {
|
|
894
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
895
|
-
const req = Request({})
|
|
896
|
-
await store().beginTransaction(req)
|
|
897
|
-
|
|
898
|
-
try {
|
|
899
|
-
const t1 = {
|
|
900
|
-
name: 't1',
|
|
901
|
-
engine: 'none',
|
|
902
|
-
recipe: 'html'
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
await getCollection(colName).insert(t1, req)
|
|
906
|
-
|
|
907
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
908
|
-
|
|
909
|
-
should(found == null).be.True()
|
|
910
|
-
|
|
911
|
-
await store().commitTransaction(req)
|
|
912
|
-
} catch (e) {
|
|
913
|
-
await store().rollbackTransaction(req)
|
|
914
|
-
throw e
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
918
|
-
|
|
919
|
-
should(found != null).be.True()
|
|
920
|
-
})
|
|
921
|
-
|
|
922
|
-
it('should be able to see entity updated in transaction from outside', async () => {
|
|
923
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
924
|
-
const req = Request({})
|
|
925
|
-
|
|
926
|
-
const t1 = {
|
|
927
|
-
name: 't1',
|
|
928
|
-
engine: 'none',
|
|
929
|
-
recipe: 'html'
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
await getCollection(colName).insert(t1)
|
|
933
|
-
|
|
934
|
-
await store().beginTransaction(req)
|
|
935
|
-
|
|
936
|
-
try {
|
|
937
|
-
await getCollection(colName).update({
|
|
938
|
-
name: 't1'
|
|
939
|
-
}, {
|
|
940
|
-
$set: {
|
|
941
|
-
engine: 'handlebars'
|
|
942
|
-
}
|
|
943
|
-
}, req)
|
|
944
|
-
|
|
945
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
946
|
-
|
|
947
|
-
should(found != null).be.True()
|
|
948
|
-
|
|
949
|
-
await store().commitTransaction(req)
|
|
950
|
-
} catch (e) {
|
|
951
|
-
await store().rollbackTransaction(req)
|
|
952
|
-
throw e
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
956
|
-
|
|
957
|
-
should(found != null).be.True()
|
|
958
|
-
})
|
|
959
|
-
|
|
960
|
-
it('should not be able to see entity updated properties from outside', async () => {
|
|
961
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
962
|
-
const req = Request({})
|
|
963
|
-
|
|
964
|
-
const t1 = {
|
|
965
|
-
name: 't1',
|
|
966
|
-
engine: 'none',
|
|
967
|
-
recipe: 'html'
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
await getCollection(colName).insert(t1)
|
|
971
|
-
|
|
972
|
-
await store().beginTransaction(req)
|
|
973
|
-
|
|
974
|
-
try {
|
|
975
|
-
await getCollection(colName).update({
|
|
976
|
-
name: 't1'
|
|
977
|
-
}, {
|
|
978
|
-
$set: {
|
|
979
|
-
engine: 'handlebars'
|
|
980
|
-
}
|
|
981
|
-
}, req)
|
|
982
|
-
|
|
983
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
984
|
-
|
|
985
|
-
should(found.engine).be.eql('none')
|
|
986
|
-
|
|
987
|
-
await store().commitTransaction(req)
|
|
988
|
-
} catch (e) {
|
|
989
|
-
await store().rollbackTransaction(req)
|
|
990
|
-
throw e
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
994
|
-
|
|
995
|
-
should(found.engine).be.eql('handlebars')
|
|
996
|
-
})
|
|
997
|
-
|
|
998
|
-
it('should not be able to see entity upsert in transaction from outside', async () => {
|
|
999
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1000
|
-
const req = Request({})
|
|
1001
|
-
|
|
1002
|
-
const t1 = {
|
|
1003
|
-
name: 't1',
|
|
1004
|
-
engine: 'none',
|
|
1005
|
-
recipe: 'html'
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
await store().beginTransaction(req)
|
|
1009
|
-
|
|
1010
|
-
try {
|
|
1011
|
-
await getCollection(colName).insert(t1, req)
|
|
1012
|
-
|
|
1013
|
-
await getCollection(colName).update({
|
|
1014
|
-
name: 't1'
|
|
1015
|
-
}, {
|
|
1016
|
-
$set: {
|
|
1017
|
-
engine: 'handlebars'
|
|
1018
|
-
}
|
|
1019
|
-
}, req)
|
|
1020
|
-
|
|
1021
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1022
|
-
|
|
1023
|
-
should(found == null).be.True()
|
|
1024
|
-
|
|
1025
|
-
await store().commitTransaction(req)
|
|
1026
|
-
} catch (e) {
|
|
1027
|
-
await store().rollbackTransaction(req)
|
|
1028
|
-
throw e
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1032
|
-
|
|
1033
|
-
should(found != null).be.True()
|
|
1034
|
-
})
|
|
1035
|
-
|
|
1036
|
-
it('should be able to see entity removed in transaction from outside', async () => {
|
|
1037
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1038
|
-
const req = Request({})
|
|
1039
|
-
|
|
1040
|
-
const t1 = {
|
|
1041
|
-
name: 't1',
|
|
1042
|
-
engine: 'none',
|
|
1043
|
-
recipe: 'html'
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
await getCollection(colName).insert(t1)
|
|
1047
|
-
|
|
1048
|
-
await store().beginTransaction(req)
|
|
1049
|
-
|
|
1050
|
-
try {
|
|
1051
|
-
await getCollection(colName).remove({
|
|
1052
|
-
name: 't1'
|
|
1053
|
-
}, req)
|
|
1054
|
-
|
|
1055
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1056
|
-
|
|
1057
|
-
should(found != null).be.True()
|
|
1058
|
-
|
|
1059
|
-
await store().commitTransaction(req)
|
|
1060
|
-
} catch (e) {
|
|
1061
|
-
await store().rollbackTransaction(req)
|
|
1062
|
-
throw e
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1066
|
-
|
|
1067
|
-
should(found == null).be.True()
|
|
1068
|
-
})
|
|
1069
|
-
|
|
1070
|
-
it('should not be able to see entity created in transaction from another transaction', async () => {
|
|
1071
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1072
|
-
const req = Request({})
|
|
1073
|
-
const req2 = Request({})
|
|
1074
|
-
|
|
1075
|
-
await store().beginTransaction(req)
|
|
1076
|
-
await store().beginTransaction(req2)
|
|
1077
|
-
|
|
1078
|
-
try {
|
|
1079
|
-
const t1 = {
|
|
1080
|
-
name: 't1',
|
|
1081
|
-
engine: 'none',
|
|
1082
|
-
recipe: 'html'
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
await getCollection(colName).insert(t1, req)
|
|
1086
|
-
|
|
1087
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1088
|
-
|
|
1089
|
-
should(found == null).be.True()
|
|
1090
|
-
|
|
1091
|
-
await store().commitTransaction(req)
|
|
1092
|
-
await store().commitTransaction(req2)
|
|
1093
|
-
} catch (e) {
|
|
1094
|
-
await store().rollbackTransaction(req)
|
|
1095
|
-
await store().rollbackTransaction(req2)
|
|
1096
|
-
throw e
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1100
|
-
|
|
1101
|
-
should(found != null).be.True()
|
|
1102
|
-
})
|
|
1103
|
-
|
|
1104
|
-
it('should be able to see entity updated in transaction from another transaction', async () => {
|
|
1105
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1106
|
-
const req = Request({})
|
|
1107
|
-
const req2 = Request({})
|
|
1108
|
-
|
|
1109
|
-
const t1 = {
|
|
1110
|
-
name: 't1',
|
|
1111
|
-
engine: 'none',
|
|
1112
|
-
recipe: 'html'
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
await getCollection(colName).insert(t1)
|
|
1116
|
-
|
|
1117
|
-
await store().beginTransaction(req)
|
|
1118
|
-
await store().beginTransaction(req2)
|
|
1119
|
-
|
|
1120
|
-
try {
|
|
1121
|
-
await getCollection(colName).update({
|
|
1122
|
-
name: 't1'
|
|
1123
|
-
}, {
|
|
1124
|
-
$set: {
|
|
1125
|
-
engine: 'handlebars'
|
|
1126
|
-
}
|
|
1127
|
-
}, req)
|
|
1128
|
-
|
|
1129
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1130
|
-
|
|
1131
|
-
should(found != null).be.True()
|
|
1132
|
-
|
|
1133
|
-
await store().commitTransaction(req)
|
|
1134
|
-
await store().commitTransaction(req2)
|
|
1135
|
-
} catch (e) {
|
|
1136
|
-
await store().rollbackTransaction(req)
|
|
1137
|
-
await store().rollbackTransaction(req2)
|
|
1138
|
-
throw e
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1142
|
-
|
|
1143
|
-
should(found != null).be.True()
|
|
1144
|
-
})
|
|
1145
|
-
|
|
1146
|
-
it('should not be able to see entity updated properties from another transaction', async () => {
|
|
1147
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1148
|
-
const req = Request({})
|
|
1149
|
-
const req2 = Request({})
|
|
1150
|
-
|
|
1151
|
-
const t1 = {
|
|
1152
|
-
name: 't1',
|
|
1153
|
-
engine: 'none',
|
|
1154
|
-
recipe: 'html'
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
await getCollection(colName).insert(t1)
|
|
1158
|
-
|
|
1159
|
-
await store().beginTransaction(req)
|
|
1160
|
-
await store().beginTransaction(req2)
|
|
1161
|
-
|
|
1162
|
-
try {
|
|
1163
|
-
await getCollection(colName).update({
|
|
1164
|
-
name: 't1'
|
|
1165
|
-
}, {
|
|
1166
|
-
$set: {
|
|
1167
|
-
engine: 'handlebars'
|
|
1168
|
-
}
|
|
1169
|
-
}, req)
|
|
1170
|
-
|
|
1171
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1172
|
-
|
|
1173
|
-
should(found.engine).be.eql('none')
|
|
1174
|
-
|
|
1175
|
-
await store().commitTransaction(req)
|
|
1176
|
-
await store().commitTransaction(req2)
|
|
1177
|
-
} catch (e) {
|
|
1178
|
-
await store().rollbackTransaction(req)
|
|
1179
|
-
await store().rollbackTransaction(req2)
|
|
1180
|
-
throw e
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1184
|
-
|
|
1185
|
-
should(found.engine).be.eql('handlebars')
|
|
1186
|
-
})
|
|
1187
|
-
|
|
1188
|
-
it('should not be able to see entity upsert in transaction from another transaction', async () => {
|
|
1189
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1190
|
-
const req = Request({})
|
|
1191
|
-
const req2 = Request({})
|
|
1192
|
-
|
|
1193
|
-
const t1 = {
|
|
1194
|
-
name: 't1',
|
|
1195
|
-
engine: 'none',
|
|
1196
|
-
recipe: 'html'
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
await store().beginTransaction(req)
|
|
1200
|
-
await store().beginTransaction(req2)
|
|
1201
|
-
|
|
1202
|
-
try {
|
|
1203
|
-
await getCollection(colName).insert(t1, req)
|
|
1204
|
-
|
|
1205
|
-
await getCollection(colName).update({
|
|
1206
|
-
name: 't1'
|
|
1207
|
-
}, {
|
|
1208
|
-
$set: {
|
|
1209
|
-
engine: 'handlebars'
|
|
1210
|
-
}
|
|
1211
|
-
}, req)
|
|
1212
|
-
|
|
1213
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1214
|
-
|
|
1215
|
-
should(found == null).be.True()
|
|
1216
|
-
|
|
1217
|
-
await store().commitTransaction(req)
|
|
1218
|
-
await store().commitTransaction(req2)
|
|
1219
|
-
} catch (e) {
|
|
1220
|
-
await store().rollbackTransaction(req)
|
|
1221
|
-
await store().rollbackTransaction(req2)
|
|
1222
|
-
throw e
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1226
|
-
|
|
1227
|
-
should(found != null).be.True()
|
|
1228
|
-
})
|
|
1229
|
-
|
|
1230
|
-
it('should be able to see entity removed in transaction from another transaction', async () => {
|
|
1231
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1232
|
-
const req = Request({})
|
|
1233
|
-
const req2 = Request({})
|
|
1234
|
-
|
|
1235
|
-
const t1 = {
|
|
1236
|
-
name: 't1',
|
|
1237
|
-
engine: 'none',
|
|
1238
|
-
recipe: 'html'
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
await getCollection(colName).insert(t1)
|
|
1242
|
-
|
|
1243
|
-
await store().beginTransaction(req)
|
|
1244
|
-
await store().beginTransaction(req2)
|
|
1245
|
-
|
|
1246
|
-
try {
|
|
1247
|
-
await getCollection(colName).remove({
|
|
1248
|
-
name: 't1'
|
|
1249
|
-
}, req)
|
|
1250
|
-
|
|
1251
|
-
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1252
|
-
|
|
1253
|
-
should(found != null).be.True()
|
|
1254
|
-
|
|
1255
|
-
await store().commitTransaction(req)
|
|
1256
|
-
await store().commitTransaction(req2)
|
|
1257
|
-
} catch (e) {
|
|
1258
|
-
await store().rollbackTransaction(req)
|
|
1259
|
-
await store().rollbackTransaction(req2)
|
|
1260
|
-
throw e
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1264
|
-
|
|
1265
|
-
should(found == null).be.True()
|
|
1266
|
-
})
|
|
1267
|
-
|
|
1268
|
-
it('should not be able to commit changes of transaction from another transaction (insert)', async () => {
|
|
1269
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1270
|
-
const req = Request({})
|
|
1271
|
-
const req2 = Request({})
|
|
1272
|
-
|
|
1273
|
-
const t1 = {
|
|
1274
|
-
name: 't1',
|
|
1275
|
-
engine: 'none',
|
|
1276
|
-
recipe: 'html'
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
await store().beginTransaction(req)
|
|
1280
|
-
await store().beginTransaction(req2)
|
|
1281
|
-
|
|
1282
|
-
try {
|
|
1283
|
-
await getCollection(colName).insert(t1, req)
|
|
1284
|
-
|
|
1285
|
-
await store().commitTransaction(req2)
|
|
1286
|
-
|
|
1287
|
-
let found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1288
|
-
|
|
1289
|
-
should(found == null).be.True()
|
|
1290
|
-
|
|
1291
|
-
await store().commitTransaction(req)
|
|
1292
|
-
|
|
1293
|
-
found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
1294
|
-
|
|
1295
|
-
should(found != null).be.True()
|
|
1296
|
-
} catch (e) {
|
|
1297
|
-
await store().rollbackTransaction(req)
|
|
1298
|
-
await store().rollbackTransaction(req2)
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1302
|
-
|
|
1303
|
-
should(found != null).be.True()
|
|
1304
|
-
})
|
|
1305
|
-
|
|
1306
|
-
it('should not be able to commit changes of transaction from another transaction (update)', async () => {
|
|
1307
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1308
|
-
const req = Request({})
|
|
1309
|
-
const req2 = Request({})
|
|
1310
|
-
|
|
1311
|
-
const t1 = {
|
|
1312
|
-
name: 't1',
|
|
1313
|
-
engine: 'none',
|
|
1314
|
-
recipe: 'html'
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
await getCollection(colName).insert(t1)
|
|
1318
|
-
|
|
1319
|
-
await store().beginTransaction(req)
|
|
1320
|
-
await store().beginTransaction(req2)
|
|
1321
|
-
|
|
1322
|
-
try {
|
|
1323
|
-
await getCollection(colName).update({
|
|
1324
|
-
name: 't1'
|
|
1325
|
-
}, {
|
|
1326
|
-
$set: {
|
|
1327
|
-
engine: 'handlebars'
|
|
1328
|
-
}
|
|
1329
|
-
}, req)
|
|
1330
|
-
|
|
1331
|
-
await store().commitTransaction(req2)
|
|
1332
|
-
|
|
1333
|
-
let found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1334
|
-
|
|
1335
|
-
should(found.engine).be.eql('none')
|
|
1336
|
-
|
|
1337
|
-
await store().commitTransaction(req)
|
|
1338
|
-
|
|
1339
|
-
found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
1340
|
-
|
|
1341
|
-
should(found.engine).be.eql('handlebars')
|
|
1342
|
-
} catch (e) {
|
|
1343
|
-
await store().rollbackTransaction(req)
|
|
1344
|
-
await store().rollbackTransaction(req2)
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1348
|
-
|
|
1349
|
-
should(found.engine).be.eql('handlebars')
|
|
1350
|
-
})
|
|
1351
|
-
|
|
1352
|
-
it('should not be able to commit changes of transaction from another transaction (remove)', async () => {
|
|
1353
|
-
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1354
|
-
const req = Request({})
|
|
1355
|
-
const req2 = Request({})
|
|
1356
|
-
|
|
1357
|
-
const t1 = {
|
|
1358
|
-
name: 't1',
|
|
1359
|
-
engine: 'none',
|
|
1360
|
-
recipe: 'html'
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
await getCollection(colName).insert(t1)
|
|
1364
|
-
|
|
1365
|
-
await store().beginTransaction(req)
|
|
1366
|
-
await store().beginTransaction(req2)
|
|
1367
|
-
|
|
1368
|
-
try {
|
|
1369
|
-
await getCollection(colName).remove({
|
|
1370
|
-
name: 't1'
|
|
1371
|
-
}, req)
|
|
1372
|
-
|
|
1373
|
-
await store().commitTransaction(req2)
|
|
1374
|
-
|
|
1375
|
-
let found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1376
|
-
|
|
1377
|
-
should(found != null).be.True()
|
|
1378
|
-
|
|
1379
|
-
await store().commitTransaction(req)
|
|
1380
|
-
|
|
1381
|
-
found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
1382
|
-
|
|
1383
|
-
should(found == null).be.True()
|
|
1384
|
-
} catch (e) {
|
|
1385
|
-
await store().rollbackTransaction(req)
|
|
1386
|
-
await store().rollbackTransaction(req2)
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1390
|
-
|
|
1391
|
-
should(found == null).be.True()
|
|
1392
|
-
})
|
|
1393
|
-
})
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
function init (store) {
|
|
1398
|
-
store().registerComplexType('CommonPhantomType', {
|
|
1399
|
-
header: { type: 'Edm.String', document: { extension: 'html', engine: true } }
|
|
1400
|
-
})
|
|
1401
|
-
|
|
1402
|
-
const templateType = {
|
|
1403
|
-
name: { type: 'Edm.String' },
|
|
1404
|
-
content: { type: 'Edm.String', document: { extension: 'html', engine: true } },
|
|
1405
|
-
recipe: { type: 'Edm.String' },
|
|
1406
|
-
engine: { type: 'Edm.String' },
|
|
1407
|
-
phantom: { type: 'jsreport.CommonPhantomType', schema: { type: 'null' } }
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
store().registerEntityType('CommonTemplateType', { ...templateType })
|
|
1411
|
-
store().registerEntityType('CommonTemplateType2', { ...templateType })
|
|
1412
|
-
|
|
1413
|
-
store().registerEntitySet('templates', {
|
|
1414
|
-
entityType: 'jsreport.CommonTemplateType',
|
|
1415
|
-
splitIntoDirectories: true
|
|
1416
|
-
})
|
|
1417
|
-
|
|
1418
|
-
store().registerEntitySet('templates2', {
|
|
1419
|
-
entityType: 'jsreport.CommonTemplateType2',
|
|
1420
|
-
splitIntoDirectories: true
|
|
1421
|
-
})
|
|
1422
|
-
|
|
1423
|
-
store().registerEntitySet('internalTemplates', {
|
|
1424
|
-
entityType: 'jsreport.CommonTemplateType',
|
|
1425
|
-
internal: true,
|
|
1426
|
-
splitIntoDirectories: true
|
|
1427
|
-
})
|
|
1428
|
-
|
|
1429
|
-
store().registerEntitySet('internalTemplates2', {
|
|
1430
|
-
entityType: 'jsreport.CommonTemplateType2',
|
|
1431
|
-
internal: true,
|
|
1432
|
-
splitIntoDirectories: true
|
|
1433
|
-
})
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
async function clean (store) {
|
|
1437
|
-
await Promise.all(Object.keys(store().collections).map(async (collectionName) => {
|
|
1438
|
-
const all = await store().collection(collectionName).find({})
|
|
1439
|
-
return Promise.all(all.map((e) => store().collection(collectionName).remove({ _id: e._id })))
|
|
1440
|
-
}))
|
|
1441
|
-
|
|
1442
|
-
await Promise.all(Object.keys(store().internalCollections).map(async (collectionName) => {
|
|
1443
|
-
const all = await store().internalCollection(collectionName).find({})
|
|
1444
|
-
return Promise.all(all.map((e) => store().internalCollection(collectionName).remove({ _id: e._id })))
|
|
1445
|
-
}))
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
module.exports.init = init
|
|
1449
|
-
module.exports.clean = clean
|
|
1
|
+
const should = require('should')
|
|
2
|
+
const Request = require('../../lib/shared/request')
|
|
3
|
+
|
|
4
|
+
module.exports = (store, runTransactions = true) => {
|
|
5
|
+
describe('public collection', () => {
|
|
6
|
+
collectionTests(store, undefined, runTransactions)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
describe('internal collection', () => {
|
|
10
|
+
collectionTests(store, true, runTransactions)
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function collectionTests (store, isInternal, runTransactions) {
|
|
15
|
+
function getCollection (name) {
|
|
16
|
+
if (!isInternal) {
|
|
17
|
+
return store().collection(name)
|
|
18
|
+
} else {
|
|
19
|
+
return store().internalCollection(name)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
it('insert and query', async () => {
|
|
24
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
25
|
+
|
|
26
|
+
await getCollection(colName).insert({
|
|
27
|
+
name: 'test',
|
|
28
|
+
engine: 'none',
|
|
29
|
+
recipe: 'html'
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const res = await getCollection(colName).find({ name: 'test' })
|
|
33
|
+
res.length.should.be.eql(1)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('insert and query with condition', async () => {
|
|
37
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
38
|
+
|
|
39
|
+
await getCollection(colName).insert({
|
|
40
|
+
name: 'test',
|
|
41
|
+
engine: 'none',
|
|
42
|
+
recipe: 'html'
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const res = await getCollection(colName).find({ name: 'diferent' })
|
|
46
|
+
res.length.should.be.eql(0)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('insert, update, query', async () => {
|
|
50
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
51
|
+
|
|
52
|
+
await getCollection(colName).insert({
|
|
53
|
+
name: 'test',
|
|
54
|
+
engine: 'none',
|
|
55
|
+
recipe: 'html'
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
await getCollection(colName).update({ name: 'test' }, { $set: { recipe: 'foo' } })
|
|
59
|
+
const res = await getCollection(colName).find({ name: 'test' })
|
|
60
|
+
res.length.should.be.eql(1)
|
|
61
|
+
res[0].recipe.should.be.eql('foo')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('insert remove query', async () => {
|
|
65
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
66
|
+
|
|
67
|
+
await getCollection(colName).insert({
|
|
68
|
+
name: 'test',
|
|
69
|
+
engine: 'none',
|
|
70
|
+
recipe: 'html'
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
await getCollection(colName).remove({ name: 'test' })
|
|
74
|
+
const res = await getCollection(colName).find({ name: 'test' })
|
|
75
|
+
res.length.should.be.eql(0)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('insert should return an object with _id set', async () => {
|
|
79
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
80
|
+
|
|
81
|
+
const doc = await getCollection(colName).insert({
|
|
82
|
+
name: 'test',
|
|
83
|
+
engine: 'none',
|
|
84
|
+
recipe: 'html'
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
doc.should.have.property('_id')
|
|
88
|
+
doc._id.should.be.ok()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('update with upsert', async () => {
|
|
92
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
93
|
+
|
|
94
|
+
await getCollection(colName).update({ name: 'test' }, {
|
|
95
|
+
$set: {
|
|
96
|
+
name: 'test2',
|
|
97
|
+
engine: 'none',
|
|
98
|
+
recipe: 'html'
|
|
99
|
+
}
|
|
100
|
+
}, { upsert: true })
|
|
101
|
+
const res = await getCollection(colName).find({ name: 'test2' })
|
|
102
|
+
res.length.should.be.eql(1)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('find should return clones', async () => {
|
|
106
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
107
|
+
|
|
108
|
+
await getCollection(colName).insert({
|
|
109
|
+
name: 'test',
|
|
110
|
+
engine: 'none',
|
|
111
|
+
recipe: 'html',
|
|
112
|
+
content: 'original',
|
|
113
|
+
phantom: { header: 'original' }
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const res = await getCollection(colName).find({})
|
|
117
|
+
res[0].content = 'modified'
|
|
118
|
+
res[0].phantom.header = 'modified'
|
|
119
|
+
const res2 = await getCollection(colName).find({})
|
|
120
|
+
res2[0].content.should.be.eql('original')
|
|
121
|
+
res2[0].phantom.header.should.be.eql('original')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('insert should use clones', async () => {
|
|
125
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
126
|
+
|
|
127
|
+
const doc = {
|
|
128
|
+
name: 'test',
|
|
129
|
+
engine: 'none',
|
|
130
|
+
recipe: 'html',
|
|
131
|
+
content: 'original',
|
|
132
|
+
phantom: { header: 'original' }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await getCollection(colName).insert(doc)
|
|
136
|
+
|
|
137
|
+
doc.content = 'modified'
|
|
138
|
+
doc.phantom.header = 'modified'
|
|
139
|
+
const res = await getCollection(colName).find({})
|
|
140
|
+
res[0].content.should.be.eql('original')
|
|
141
|
+
res[0].phantom.header.should.be.eql('original')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('skip and limit', async () => {
|
|
145
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
146
|
+
|
|
147
|
+
await getCollection(colName).insert({
|
|
148
|
+
name: '1',
|
|
149
|
+
engine: 'none',
|
|
150
|
+
recipe: 'html'
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
await getCollection(colName).insert({
|
|
154
|
+
name: '3',
|
|
155
|
+
engine: 'none',
|
|
156
|
+
recipe: 'html'
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
await getCollection(colName).insert({
|
|
160
|
+
name: '2',
|
|
161
|
+
engine: 'none',
|
|
162
|
+
recipe: 'html'
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const res = await getCollection(colName).find({}).sort({ name: 1 }).skip(1).limit(1).toArray()
|
|
166
|
+
res.length.should.be.eql(1)
|
|
167
|
+
res[0].name.should.be.eql('2')
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('$and', async () => {
|
|
171
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
172
|
+
|
|
173
|
+
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
174
|
+
await getCollection(colName).insert({ name: '2', engine: 'none', recipe: 'b' })
|
|
175
|
+
await getCollection(colName).insert({ name: '3', engine: 'none', recipe: 'b' })
|
|
176
|
+
|
|
177
|
+
const res = await getCollection(colName).find({ $and: [{ name: '2' }, { recipe: 'b' }] }).toArray()
|
|
178
|
+
res.length.should.be.eql(1)
|
|
179
|
+
res[0].name.should.be.eql('2')
|
|
180
|
+
res[0].recipe.should.be.eql('b')
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('projection', async () => {
|
|
184
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
185
|
+
|
|
186
|
+
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
187
|
+
|
|
188
|
+
const res = await getCollection(colName).find({}, { recipe: 1 })
|
|
189
|
+
res.length.should.be.eql(1)
|
|
190
|
+
res[0].should.not.have.property('name')
|
|
191
|
+
res[0].recipe.should.be.eql('a')
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('count', async () => {
|
|
195
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
196
|
+
|
|
197
|
+
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
198
|
+
|
|
199
|
+
const res = await getCollection(colName).find({}).count()
|
|
200
|
+
res.should.be.eql(1)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it('count without cursor', async () => {
|
|
204
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
205
|
+
|
|
206
|
+
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
207
|
+
|
|
208
|
+
const res = await getCollection(colName).count({})
|
|
209
|
+
res.should.be.eql(1)
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('projection should not be applied when second param is request', async () => {
|
|
213
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
214
|
+
|
|
215
|
+
await getCollection(colName).insert({ name: 'test', engine: 'none', recipe: 'html' })
|
|
216
|
+
const res = await getCollection(colName).find({ name: 'test' }, Request({ template: {} }))
|
|
217
|
+
res[0].name.should.be.eql('test')
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('update should return 1 if upsert', async () => {
|
|
221
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
222
|
+
|
|
223
|
+
const res = await getCollection(colName).update({ name: 'test' }, { $set: { name: 'test2', engine: 'none', recipe: 'html' } }, { upsert: true })
|
|
224
|
+
res.should.be.eql(1)
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
it('update should return number of updated items', async () => {
|
|
228
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
229
|
+
|
|
230
|
+
await getCollection(colName).insert({ name: '1', engine: 'none', recipe: 'a' })
|
|
231
|
+
await getCollection(colName).insert({ name: '2', engine: 'none', recipe: 'a' })
|
|
232
|
+
const res = await getCollection(colName).update({ recipe: 'a' }, { $set: { engine: 'test2' } })
|
|
233
|
+
res.should.be.eql(2)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('should validate duplicated _id on insert', async () => {
|
|
237
|
+
const newEntity = await store().collection('templates').insert({
|
|
238
|
+
name: 'a',
|
|
239
|
+
content: 'x',
|
|
240
|
+
engine: 'none',
|
|
241
|
+
recipe: 'html'
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
return should(store().collection('templates').insert({
|
|
245
|
+
_id: newEntity._id,
|
|
246
|
+
name: 'b',
|
|
247
|
+
content: 'x',
|
|
248
|
+
engine: 'none',
|
|
249
|
+
recipe: 'html'
|
|
250
|
+
})).be.rejected()
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('should validate duplicated _id on update', async () => {
|
|
254
|
+
const a = await store().collection('templates').insert({
|
|
255
|
+
name: 'a',
|
|
256
|
+
engine: 'none',
|
|
257
|
+
recipe: 'html'
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
const b = await store().collection('templates').insert({
|
|
261
|
+
name: 'b',
|
|
262
|
+
engine: 'none',
|
|
263
|
+
recipe: 'html'
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
return should(store().collection('templates').update({
|
|
267
|
+
_id: a._id
|
|
268
|
+
}, {
|
|
269
|
+
$set: {
|
|
270
|
+
_id: b._id
|
|
271
|
+
}
|
|
272
|
+
})).be.rejected()
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it('should validate duplicated shortid on upsert', async () => {
|
|
276
|
+
const a = await store().collection('templates').insert({
|
|
277
|
+
name: 'a',
|
|
278
|
+
engine: 'none',
|
|
279
|
+
recipe: 'html'
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
return should(store().collection('templates').update({
|
|
283
|
+
name: 'b'
|
|
284
|
+
}, {
|
|
285
|
+
$set: {
|
|
286
|
+
_id: a._id,
|
|
287
|
+
name: 'b'
|
|
288
|
+
}
|
|
289
|
+
}, { upsert: true })).be.rejected()
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
it('should validate duplicated shortid on insert', async () => {
|
|
293
|
+
await store().collection('templates').insert({
|
|
294
|
+
name: 'a',
|
|
295
|
+
shortid: 'a',
|
|
296
|
+
engine: 'none',
|
|
297
|
+
recipe: 'html'
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
return should(store().collection('templates').insert({
|
|
301
|
+
name: 'b',
|
|
302
|
+
shortid: 'a',
|
|
303
|
+
engine: 'none',
|
|
304
|
+
recipe: 'html'
|
|
305
|
+
})).be.rejected()
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
it('should validate duplicated shortid on update', async () => {
|
|
309
|
+
const a = await store().collection('templates').insert({
|
|
310
|
+
name: 'a',
|
|
311
|
+
shortid: 'a',
|
|
312
|
+
engine: 'none',
|
|
313
|
+
recipe: 'html'
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
await store().collection('templates').insert({
|
|
317
|
+
name: 'b',
|
|
318
|
+
shortid: 'b',
|
|
319
|
+
engine: 'none',
|
|
320
|
+
recipe: 'html'
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
return should(store().collection('templates').update({
|
|
324
|
+
_id: a._id
|
|
325
|
+
}, {
|
|
326
|
+
$set: {
|
|
327
|
+
shortid: 'b'
|
|
328
|
+
}
|
|
329
|
+
})).be.rejected()
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
it('should validate duplicated shortid on upsert', async () => {
|
|
333
|
+
await store().collection('templates').insert({
|
|
334
|
+
name: 'a',
|
|
335
|
+
shortid: 'a',
|
|
336
|
+
engine: 'none',
|
|
337
|
+
recipe: 'html'
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
return should(store().collection('templates').update({
|
|
341
|
+
name: 'b'
|
|
342
|
+
}, {
|
|
343
|
+
$set: {
|
|
344
|
+
name: 'b',
|
|
345
|
+
shortid: 'a'
|
|
346
|
+
}
|
|
347
|
+
}, { upsert: true })).be.rejected()
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
if (runTransactions) {
|
|
351
|
+
describe('transactions', () => {
|
|
352
|
+
it('should be able to start', async () => {
|
|
353
|
+
const req = Request({})
|
|
354
|
+
await store().beginTransaction(req)
|
|
355
|
+
req.context.storeTransaction.should.be.not.empty()
|
|
356
|
+
await store().commitTransaction(req)
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
it('should fail when trying to start more than once', async () => {
|
|
360
|
+
const req = Request({})
|
|
361
|
+
|
|
362
|
+
await store().beginTransaction(req)
|
|
363
|
+
|
|
364
|
+
try {
|
|
365
|
+
await store().beginTransaction(req)
|
|
366
|
+
throw new Error('it should have failed calling beginTransaction twice')
|
|
367
|
+
} catch (e) {
|
|
368
|
+
e.message.should.containEql('active transaction already exists')
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
await store().commitTransaction(req)
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
it('should fail when commit without start', async () => {
|
|
375
|
+
const req = Request({})
|
|
376
|
+
return should(store().commitTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
it('should fail when rollback without start', async () => {
|
|
380
|
+
const req = Request({})
|
|
381
|
+
return should(store().rollbackTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
it('should fail when commit more than once', async () => {
|
|
385
|
+
const req = Request({})
|
|
386
|
+
|
|
387
|
+
await store().beginTransaction(req)
|
|
388
|
+
await store().commitTransaction(req)
|
|
389
|
+
|
|
390
|
+
return should(store().commitTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
it('should fail when rollback more than once', async () => {
|
|
394
|
+
const req = Request({})
|
|
395
|
+
|
|
396
|
+
await store().beginTransaction(req)
|
|
397
|
+
await store().rollbackTransaction(req)
|
|
398
|
+
|
|
399
|
+
return should(store().rollbackTransaction(req)).be.rejectedWith(/without an active transaction/)
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
it('should fail when rollback after commit', async () => {
|
|
403
|
+
const req = Request({})
|
|
404
|
+
|
|
405
|
+
await store().beginTransaction(req)
|
|
406
|
+
await store().commitTransaction(req)
|
|
407
|
+
|
|
408
|
+
return should(store().rollbackTransaction(req)).rejectedWith(/without an active transaction/)
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
it('should fail when commit after rollback', async () => {
|
|
412
|
+
const req = Request({})
|
|
413
|
+
|
|
414
|
+
await store().beginTransaction(req)
|
|
415
|
+
await store().rollbackTransaction(req)
|
|
416
|
+
|
|
417
|
+
return should(store().commitTransaction(req)).rejectedWith(/without an active transaction/)
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
it('should be able to commit (insert)', async () => {
|
|
421
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
422
|
+
const req = Request({})
|
|
423
|
+
|
|
424
|
+
await store().beginTransaction(req)
|
|
425
|
+
|
|
426
|
+
try {
|
|
427
|
+
const t1 = {
|
|
428
|
+
name: 't1',
|
|
429
|
+
engine: 'none',
|
|
430
|
+
recipe: 'html'
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
await getCollection(colName).insert(t1, req)
|
|
434
|
+
|
|
435
|
+
await store().commitTransaction(req)
|
|
436
|
+
} catch (e) {
|
|
437
|
+
await store().rollbackTransaction(req)
|
|
438
|
+
throw e
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
442
|
+
|
|
443
|
+
should(found != null).be.True()
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
it('should be able to rollback (insert)', async () => {
|
|
447
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
448
|
+
const req = Request({})
|
|
449
|
+
await store().beginTransaction(req)
|
|
450
|
+
|
|
451
|
+
const t1 = {
|
|
452
|
+
name: 't1',
|
|
453
|
+
engine: 'none',
|
|
454
|
+
recipe: 'html'
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
await getCollection(colName).insert(t1, req)
|
|
458
|
+
|
|
459
|
+
await store().rollbackTransaction(req)
|
|
460
|
+
|
|
461
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
462
|
+
|
|
463
|
+
should(found == null).be.True()
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
it('should be able to commit (update)', async () => {
|
|
467
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
468
|
+
const req = Request({})
|
|
469
|
+
|
|
470
|
+
const t1 = {
|
|
471
|
+
name: 't1',
|
|
472
|
+
content: 't1',
|
|
473
|
+
engine: 'none',
|
|
474
|
+
recipe: 'html'
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
await getCollection(colName).insert(t1)
|
|
478
|
+
|
|
479
|
+
await store().beginTransaction(req)
|
|
480
|
+
|
|
481
|
+
try {
|
|
482
|
+
await getCollection(colName).update({
|
|
483
|
+
name: 't1'
|
|
484
|
+
}, {
|
|
485
|
+
$set: {
|
|
486
|
+
content: 't1-new',
|
|
487
|
+
engine: 'handlebars'
|
|
488
|
+
}
|
|
489
|
+
}, req)
|
|
490
|
+
|
|
491
|
+
await store().commitTransaction(req)
|
|
492
|
+
} catch (e) {
|
|
493
|
+
await store().rollbackTransaction(req)
|
|
494
|
+
throw e
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
498
|
+
|
|
499
|
+
should(found.engine).be.eql('handlebars')
|
|
500
|
+
should(found.content).be.eql('t1-new')
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
it('should be able to rollback (update)', async () => {
|
|
504
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
505
|
+
const req = Request({})
|
|
506
|
+
|
|
507
|
+
const t1 = {
|
|
508
|
+
name: 't1',
|
|
509
|
+
engine: 'none',
|
|
510
|
+
recipe: 'html'
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
await getCollection(colName).insert(t1)
|
|
514
|
+
|
|
515
|
+
await store().beginTransaction(req)
|
|
516
|
+
|
|
517
|
+
await getCollection(colName).update({
|
|
518
|
+
name: 't1'
|
|
519
|
+
}, {
|
|
520
|
+
$set: {
|
|
521
|
+
engine: 'handlebars'
|
|
522
|
+
}
|
|
523
|
+
}, req)
|
|
524
|
+
|
|
525
|
+
await store().rollbackTransaction(req)
|
|
526
|
+
|
|
527
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
528
|
+
|
|
529
|
+
should(found.engine).be.eql('none')
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
it('should be able to commit (upsert)', async () => {
|
|
533
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
534
|
+
const req = Request({})
|
|
535
|
+
|
|
536
|
+
const t1 = {
|
|
537
|
+
name: 't1',
|
|
538
|
+
engine: 'none',
|
|
539
|
+
recipe: 'html'
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
await store().beginTransaction(req)
|
|
543
|
+
|
|
544
|
+
try {
|
|
545
|
+
await getCollection(colName).insert(t1, req)
|
|
546
|
+
|
|
547
|
+
await getCollection(colName).update({
|
|
548
|
+
name: 't1'
|
|
549
|
+
}, {
|
|
550
|
+
$set: {
|
|
551
|
+
engine: 'handlebars'
|
|
552
|
+
}
|
|
553
|
+
}, req)
|
|
554
|
+
|
|
555
|
+
await store().commitTransaction(req)
|
|
556
|
+
} catch (e) {
|
|
557
|
+
await store().rollbackTransaction(req)
|
|
558
|
+
throw e
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
562
|
+
|
|
563
|
+
should(found != null).be.True()
|
|
564
|
+
})
|
|
565
|
+
|
|
566
|
+
it('should be able to rollback (upsert)', async () => {
|
|
567
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
568
|
+
const req = Request({})
|
|
569
|
+
|
|
570
|
+
const t1 = {
|
|
571
|
+
name: 't1',
|
|
572
|
+
engine: 'none',
|
|
573
|
+
recipe: 'html'
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
await store().beginTransaction(req)
|
|
577
|
+
|
|
578
|
+
await getCollection(colName).insert(t1, req)
|
|
579
|
+
|
|
580
|
+
await getCollection(colName).update({
|
|
581
|
+
name: 't1'
|
|
582
|
+
}, {
|
|
583
|
+
$set: {
|
|
584
|
+
engine: 'handlebars'
|
|
585
|
+
}
|
|
586
|
+
}, req)
|
|
587
|
+
|
|
588
|
+
await store().rollbackTransaction(req)
|
|
589
|
+
|
|
590
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
591
|
+
|
|
592
|
+
should(found == null).be.True()
|
|
593
|
+
})
|
|
594
|
+
|
|
595
|
+
it('should be able to commit (remove)', async () => {
|
|
596
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
597
|
+
const req = Request({})
|
|
598
|
+
|
|
599
|
+
const t1 = {
|
|
600
|
+
name: 't1',
|
|
601
|
+
engine: 'none',
|
|
602
|
+
recipe: 'html'
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
await getCollection(colName).insert(t1)
|
|
606
|
+
|
|
607
|
+
await store().beginTransaction(req)
|
|
608
|
+
|
|
609
|
+
try {
|
|
610
|
+
await getCollection(colName).remove({
|
|
611
|
+
name: 't1'
|
|
612
|
+
}, req)
|
|
613
|
+
|
|
614
|
+
await store().commitTransaction(req)
|
|
615
|
+
} catch (e) {
|
|
616
|
+
await store().rollbackTransaction(req)
|
|
617
|
+
throw e
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
621
|
+
|
|
622
|
+
should(found == null).be.True()
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
it('should be able to rollback (remove)', async () => {
|
|
626
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
627
|
+
const req = Request({})
|
|
628
|
+
|
|
629
|
+
const t1 = {
|
|
630
|
+
name: 't1',
|
|
631
|
+
engine: 'none',
|
|
632
|
+
recipe: 'html'
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
await getCollection(colName).insert(t1)
|
|
636
|
+
|
|
637
|
+
await store().beginTransaction(req)
|
|
638
|
+
|
|
639
|
+
await getCollection(colName).remove({
|
|
640
|
+
name: 't1'
|
|
641
|
+
}, req)
|
|
642
|
+
|
|
643
|
+
await store().rollbackTransaction(req)
|
|
644
|
+
|
|
645
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
646
|
+
|
|
647
|
+
should(found != null).be.True()
|
|
648
|
+
})
|
|
649
|
+
|
|
650
|
+
it('should be able to commit across collections', async () => {
|
|
651
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
652
|
+
const colName2 = !isInternal ? 'templates2' : 'internalTemplates2'
|
|
653
|
+
|
|
654
|
+
const req = Request({})
|
|
655
|
+
await store().beginTransaction(req)
|
|
656
|
+
|
|
657
|
+
try {
|
|
658
|
+
const t1 = {
|
|
659
|
+
name: 't1',
|
|
660
|
+
engine: 'none',
|
|
661
|
+
recipe: 'html'
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
const t2 = {
|
|
665
|
+
name: 't2',
|
|
666
|
+
engine: 'none',
|
|
667
|
+
recipe: 'html'
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
await getCollection(colName).insert(t1, req)
|
|
671
|
+
await getCollection(colName2).insert(t2, req)
|
|
672
|
+
|
|
673
|
+
await store().commitTransaction(req)
|
|
674
|
+
} catch (e) {
|
|
675
|
+
await store().rollbackTransaction(req)
|
|
676
|
+
throw e
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
680
|
+
const found2 = await getCollection(colName2).findOne({ name: 't2' })
|
|
681
|
+
|
|
682
|
+
should(found != null).be.True()
|
|
683
|
+
should(found2 != null).be.True()
|
|
684
|
+
})
|
|
685
|
+
|
|
686
|
+
it('should be able to rollback across collections', async () => {
|
|
687
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
688
|
+
const colName2 = !isInternal ? 'templates2' : 'internalTemplates2'
|
|
689
|
+
const req = Request({})
|
|
690
|
+
await store().beginTransaction(req)
|
|
691
|
+
|
|
692
|
+
const t1 = {
|
|
693
|
+
name: 't1',
|
|
694
|
+
engine: 'none',
|
|
695
|
+
recipe: 'html'
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
const t2 = {
|
|
699
|
+
name: 't2',
|
|
700
|
+
engine: 'none',
|
|
701
|
+
recipe: 'html'
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
await getCollection(colName).insert(t1, req)
|
|
705
|
+
await getCollection(colName).insert(t2, req)
|
|
706
|
+
|
|
707
|
+
await store().rollbackTransaction(req)
|
|
708
|
+
|
|
709
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
710
|
+
const found2 = await getCollection(colName2).findOne({ name: 't1' })
|
|
711
|
+
|
|
712
|
+
should(found == null).be.True()
|
|
713
|
+
should(found2 == null).be.True()
|
|
714
|
+
})
|
|
715
|
+
|
|
716
|
+
it('should be able to see entity created inside transaction', async () => {
|
|
717
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
718
|
+
const req = Request({})
|
|
719
|
+
await store().beginTransaction(req)
|
|
720
|
+
|
|
721
|
+
try {
|
|
722
|
+
const t1 = {
|
|
723
|
+
name: 't1',
|
|
724
|
+
engine: 'none',
|
|
725
|
+
recipe: 'html'
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
await getCollection(colName).insert(t1, req)
|
|
729
|
+
|
|
730
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
731
|
+
|
|
732
|
+
should(found != null).be.True()
|
|
733
|
+
|
|
734
|
+
await store().commitTransaction(req)
|
|
735
|
+
} catch (e) {
|
|
736
|
+
await store().rollbackTransaction(req)
|
|
737
|
+
throw e
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
741
|
+
|
|
742
|
+
should(found != null).be.True()
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
it('should be able to see entity updated inside transaction', async () => {
|
|
746
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
747
|
+
const req = Request({})
|
|
748
|
+
|
|
749
|
+
const t1 = {
|
|
750
|
+
name: 't1',
|
|
751
|
+
engine: 'none',
|
|
752
|
+
recipe: 'html'
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
await getCollection(colName).insert(t1)
|
|
756
|
+
|
|
757
|
+
await store().beginTransaction(req)
|
|
758
|
+
|
|
759
|
+
try {
|
|
760
|
+
await getCollection(colName).update({
|
|
761
|
+
name: 't1'
|
|
762
|
+
}, {
|
|
763
|
+
$set: {
|
|
764
|
+
engine: 'handlebars'
|
|
765
|
+
}
|
|
766
|
+
}, req)
|
|
767
|
+
|
|
768
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
769
|
+
|
|
770
|
+
should(found != null).be.True()
|
|
771
|
+
|
|
772
|
+
await store().commitTransaction(req)
|
|
773
|
+
} catch (e) {
|
|
774
|
+
await store().rollbackTransaction(req)
|
|
775
|
+
throw e
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
779
|
+
|
|
780
|
+
should(found != null).be.True()
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
it('should be able to see entity updated properties inside transaction', async () => {
|
|
784
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
785
|
+
const req = Request({})
|
|
786
|
+
|
|
787
|
+
const t1 = {
|
|
788
|
+
name: 't1',
|
|
789
|
+
engine: 'none',
|
|
790
|
+
recipe: 'html'
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
await getCollection(colName).insert(t1)
|
|
794
|
+
|
|
795
|
+
await store().beginTransaction(req)
|
|
796
|
+
|
|
797
|
+
try {
|
|
798
|
+
await getCollection(colName).update({
|
|
799
|
+
name: 't1'
|
|
800
|
+
}, {
|
|
801
|
+
$set: {
|
|
802
|
+
engine: 'handlebars'
|
|
803
|
+
}
|
|
804
|
+
}, req)
|
|
805
|
+
|
|
806
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
807
|
+
|
|
808
|
+
should(found.engine).be.eql('handlebars')
|
|
809
|
+
|
|
810
|
+
await store().commitTransaction(req)
|
|
811
|
+
} catch (e) {
|
|
812
|
+
await store().rollbackTransaction(req)
|
|
813
|
+
throw e
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
817
|
+
|
|
818
|
+
should(found.engine).be.eql('handlebars')
|
|
819
|
+
})
|
|
820
|
+
|
|
821
|
+
it('should be able to see entity upsert inside transaction', async () => {
|
|
822
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
823
|
+
const req = Request({})
|
|
824
|
+
|
|
825
|
+
const t1 = {
|
|
826
|
+
name: 't1',
|
|
827
|
+
engine: 'none',
|
|
828
|
+
recipe: 'html'
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
await store().beginTransaction(req)
|
|
832
|
+
|
|
833
|
+
try {
|
|
834
|
+
await getCollection(colName).insert(t1, req)
|
|
835
|
+
|
|
836
|
+
await getCollection(colName).update({
|
|
837
|
+
name: 't1'
|
|
838
|
+
}, {
|
|
839
|
+
$set: {
|
|
840
|
+
engine: 'handlebars'
|
|
841
|
+
}
|
|
842
|
+
}, req)
|
|
843
|
+
|
|
844
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
845
|
+
|
|
846
|
+
should(found != null).be.True()
|
|
847
|
+
|
|
848
|
+
await store().commitTransaction(req)
|
|
849
|
+
} catch (e) {
|
|
850
|
+
await store().rollbackTransaction(req)
|
|
851
|
+
throw e
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
855
|
+
|
|
856
|
+
should(found != null).be.True()
|
|
857
|
+
})
|
|
858
|
+
|
|
859
|
+
it('should not be able to see entity removed inside transaction', async () => {
|
|
860
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
861
|
+
const req = Request({})
|
|
862
|
+
|
|
863
|
+
const t1 = {
|
|
864
|
+
name: 't1',
|
|
865
|
+
engine: 'none',
|
|
866
|
+
recipe: 'html'
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
await getCollection(colName).insert(t1)
|
|
870
|
+
|
|
871
|
+
await store().beginTransaction(req)
|
|
872
|
+
|
|
873
|
+
try {
|
|
874
|
+
await getCollection(colName).remove({
|
|
875
|
+
name: 't1'
|
|
876
|
+
}, req)
|
|
877
|
+
|
|
878
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
879
|
+
|
|
880
|
+
should(found == null).be.True()
|
|
881
|
+
|
|
882
|
+
await store().commitTransaction(req)
|
|
883
|
+
} catch (e) {
|
|
884
|
+
await store().rollbackTransaction(req)
|
|
885
|
+
throw e
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
889
|
+
|
|
890
|
+
should(found == null).be.True()
|
|
891
|
+
})
|
|
892
|
+
|
|
893
|
+
it('should not be able to see entity created in transaction from outside', async () => {
|
|
894
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
895
|
+
const req = Request({})
|
|
896
|
+
await store().beginTransaction(req)
|
|
897
|
+
|
|
898
|
+
try {
|
|
899
|
+
const t1 = {
|
|
900
|
+
name: 't1',
|
|
901
|
+
engine: 'none',
|
|
902
|
+
recipe: 'html'
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
await getCollection(colName).insert(t1, req)
|
|
906
|
+
|
|
907
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
908
|
+
|
|
909
|
+
should(found == null).be.True()
|
|
910
|
+
|
|
911
|
+
await store().commitTransaction(req)
|
|
912
|
+
} catch (e) {
|
|
913
|
+
await store().rollbackTransaction(req)
|
|
914
|
+
throw e
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
918
|
+
|
|
919
|
+
should(found != null).be.True()
|
|
920
|
+
})
|
|
921
|
+
|
|
922
|
+
it('should be able to see entity updated in transaction from outside', async () => {
|
|
923
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
924
|
+
const req = Request({})
|
|
925
|
+
|
|
926
|
+
const t1 = {
|
|
927
|
+
name: 't1',
|
|
928
|
+
engine: 'none',
|
|
929
|
+
recipe: 'html'
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
await getCollection(colName).insert(t1)
|
|
933
|
+
|
|
934
|
+
await store().beginTransaction(req)
|
|
935
|
+
|
|
936
|
+
try {
|
|
937
|
+
await getCollection(colName).update({
|
|
938
|
+
name: 't1'
|
|
939
|
+
}, {
|
|
940
|
+
$set: {
|
|
941
|
+
engine: 'handlebars'
|
|
942
|
+
}
|
|
943
|
+
}, req)
|
|
944
|
+
|
|
945
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
946
|
+
|
|
947
|
+
should(found != null).be.True()
|
|
948
|
+
|
|
949
|
+
await store().commitTransaction(req)
|
|
950
|
+
} catch (e) {
|
|
951
|
+
await store().rollbackTransaction(req)
|
|
952
|
+
throw e
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
956
|
+
|
|
957
|
+
should(found != null).be.True()
|
|
958
|
+
})
|
|
959
|
+
|
|
960
|
+
it('should not be able to see entity updated properties from outside', async () => {
|
|
961
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
962
|
+
const req = Request({})
|
|
963
|
+
|
|
964
|
+
const t1 = {
|
|
965
|
+
name: 't1',
|
|
966
|
+
engine: 'none',
|
|
967
|
+
recipe: 'html'
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
await getCollection(colName).insert(t1)
|
|
971
|
+
|
|
972
|
+
await store().beginTransaction(req)
|
|
973
|
+
|
|
974
|
+
try {
|
|
975
|
+
await getCollection(colName).update({
|
|
976
|
+
name: 't1'
|
|
977
|
+
}, {
|
|
978
|
+
$set: {
|
|
979
|
+
engine: 'handlebars'
|
|
980
|
+
}
|
|
981
|
+
}, req)
|
|
982
|
+
|
|
983
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
984
|
+
|
|
985
|
+
should(found.engine).be.eql('none')
|
|
986
|
+
|
|
987
|
+
await store().commitTransaction(req)
|
|
988
|
+
} catch (e) {
|
|
989
|
+
await store().rollbackTransaction(req)
|
|
990
|
+
throw e
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
994
|
+
|
|
995
|
+
should(found.engine).be.eql('handlebars')
|
|
996
|
+
})
|
|
997
|
+
|
|
998
|
+
it('should not be able to see entity upsert in transaction from outside', async () => {
|
|
999
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1000
|
+
const req = Request({})
|
|
1001
|
+
|
|
1002
|
+
const t1 = {
|
|
1003
|
+
name: 't1',
|
|
1004
|
+
engine: 'none',
|
|
1005
|
+
recipe: 'html'
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
await store().beginTransaction(req)
|
|
1009
|
+
|
|
1010
|
+
try {
|
|
1011
|
+
await getCollection(colName).insert(t1, req)
|
|
1012
|
+
|
|
1013
|
+
await getCollection(colName).update({
|
|
1014
|
+
name: 't1'
|
|
1015
|
+
}, {
|
|
1016
|
+
$set: {
|
|
1017
|
+
engine: 'handlebars'
|
|
1018
|
+
}
|
|
1019
|
+
}, req)
|
|
1020
|
+
|
|
1021
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1022
|
+
|
|
1023
|
+
should(found == null).be.True()
|
|
1024
|
+
|
|
1025
|
+
await store().commitTransaction(req)
|
|
1026
|
+
} catch (e) {
|
|
1027
|
+
await store().rollbackTransaction(req)
|
|
1028
|
+
throw e
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1032
|
+
|
|
1033
|
+
should(found != null).be.True()
|
|
1034
|
+
})
|
|
1035
|
+
|
|
1036
|
+
it('should be able to see entity removed in transaction from outside', async () => {
|
|
1037
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1038
|
+
const req = Request({})
|
|
1039
|
+
|
|
1040
|
+
const t1 = {
|
|
1041
|
+
name: 't1',
|
|
1042
|
+
engine: 'none',
|
|
1043
|
+
recipe: 'html'
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
await getCollection(colName).insert(t1)
|
|
1047
|
+
|
|
1048
|
+
await store().beginTransaction(req)
|
|
1049
|
+
|
|
1050
|
+
try {
|
|
1051
|
+
await getCollection(colName).remove({
|
|
1052
|
+
name: 't1'
|
|
1053
|
+
}, req)
|
|
1054
|
+
|
|
1055
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1056
|
+
|
|
1057
|
+
should(found != null).be.True()
|
|
1058
|
+
|
|
1059
|
+
await store().commitTransaction(req)
|
|
1060
|
+
} catch (e) {
|
|
1061
|
+
await store().rollbackTransaction(req)
|
|
1062
|
+
throw e
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1066
|
+
|
|
1067
|
+
should(found == null).be.True()
|
|
1068
|
+
})
|
|
1069
|
+
|
|
1070
|
+
it('should not be able to see entity created in transaction from another transaction', async () => {
|
|
1071
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1072
|
+
const req = Request({})
|
|
1073
|
+
const req2 = Request({})
|
|
1074
|
+
|
|
1075
|
+
await store().beginTransaction(req)
|
|
1076
|
+
await store().beginTransaction(req2)
|
|
1077
|
+
|
|
1078
|
+
try {
|
|
1079
|
+
const t1 = {
|
|
1080
|
+
name: 't1',
|
|
1081
|
+
engine: 'none',
|
|
1082
|
+
recipe: 'html'
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
await getCollection(colName).insert(t1, req)
|
|
1086
|
+
|
|
1087
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1088
|
+
|
|
1089
|
+
should(found == null).be.True()
|
|
1090
|
+
|
|
1091
|
+
await store().commitTransaction(req)
|
|
1092
|
+
await store().commitTransaction(req2)
|
|
1093
|
+
} catch (e) {
|
|
1094
|
+
await store().rollbackTransaction(req)
|
|
1095
|
+
await store().rollbackTransaction(req2)
|
|
1096
|
+
throw e
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1100
|
+
|
|
1101
|
+
should(found != null).be.True()
|
|
1102
|
+
})
|
|
1103
|
+
|
|
1104
|
+
it('should be able to see entity updated in transaction from another transaction', async () => {
|
|
1105
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1106
|
+
const req = Request({})
|
|
1107
|
+
const req2 = Request({})
|
|
1108
|
+
|
|
1109
|
+
const t1 = {
|
|
1110
|
+
name: 't1',
|
|
1111
|
+
engine: 'none',
|
|
1112
|
+
recipe: 'html'
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
await getCollection(colName).insert(t1)
|
|
1116
|
+
|
|
1117
|
+
await store().beginTransaction(req)
|
|
1118
|
+
await store().beginTransaction(req2)
|
|
1119
|
+
|
|
1120
|
+
try {
|
|
1121
|
+
await getCollection(colName).update({
|
|
1122
|
+
name: 't1'
|
|
1123
|
+
}, {
|
|
1124
|
+
$set: {
|
|
1125
|
+
engine: 'handlebars'
|
|
1126
|
+
}
|
|
1127
|
+
}, req)
|
|
1128
|
+
|
|
1129
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1130
|
+
|
|
1131
|
+
should(found != null).be.True()
|
|
1132
|
+
|
|
1133
|
+
await store().commitTransaction(req)
|
|
1134
|
+
await store().commitTransaction(req2)
|
|
1135
|
+
} catch (e) {
|
|
1136
|
+
await store().rollbackTransaction(req)
|
|
1137
|
+
await store().rollbackTransaction(req2)
|
|
1138
|
+
throw e
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1142
|
+
|
|
1143
|
+
should(found != null).be.True()
|
|
1144
|
+
})
|
|
1145
|
+
|
|
1146
|
+
it('should not be able to see entity updated properties from another transaction', async () => {
|
|
1147
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1148
|
+
const req = Request({})
|
|
1149
|
+
const req2 = Request({})
|
|
1150
|
+
|
|
1151
|
+
const t1 = {
|
|
1152
|
+
name: 't1',
|
|
1153
|
+
engine: 'none',
|
|
1154
|
+
recipe: 'html'
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
await getCollection(colName).insert(t1)
|
|
1158
|
+
|
|
1159
|
+
await store().beginTransaction(req)
|
|
1160
|
+
await store().beginTransaction(req2)
|
|
1161
|
+
|
|
1162
|
+
try {
|
|
1163
|
+
await getCollection(colName).update({
|
|
1164
|
+
name: 't1'
|
|
1165
|
+
}, {
|
|
1166
|
+
$set: {
|
|
1167
|
+
engine: 'handlebars'
|
|
1168
|
+
}
|
|
1169
|
+
}, req)
|
|
1170
|
+
|
|
1171
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1172
|
+
|
|
1173
|
+
should(found.engine).be.eql('none')
|
|
1174
|
+
|
|
1175
|
+
await store().commitTransaction(req)
|
|
1176
|
+
await store().commitTransaction(req2)
|
|
1177
|
+
} catch (e) {
|
|
1178
|
+
await store().rollbackTransaction(req)
|
|
1179
|
+
await store().rollbackTransaction(req2)
|
|
1180
|
+
throw e
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1184
|
+
|
|
1185
|
+
should(found.engine).be.eql('handlebars')
|
|
1186
|
+
})
|
|
1187
|
+
|
|
1188
|
+
it('should not be able to see entity upsert in transaction from another transaction', async () => {
|
|
1189
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1190
|
+
const req = Request({})
|
|
1191
|
+
const req2 = Request({})
|
|
1192
|
+
|
|
1193
|
+
const t1 = {
|
|
1194
|
+
name: 't1',
|
|
1195
|
+
engine: 'none',
|
|
1196
|
+
recipe: 'html'
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
await store().beginTransaction(req)
|
|
1200
|
+
await store().beginTransaction(req2)
|
|
1201
|
+
|
|
1202
|
+
try {
|
|
1203
|
+
await getCollection(colName).insert(t1, req)
|
|
1204
|
+
|
|
1205
|
+
await getCollection(colName).update({
|
|
1206
|
+
name: 't1'
|
|
1207
|
+
}, {
|
|
1208
|
+
$set: {
|
|
1209
|
+
engine: 'handlebars'
|
|
1210
|
+
}
|
|
1211
|
+
}, req)
|
|
1212
|
+
|
|
1213
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1214
|
+
|
|
1215
|
+
should(found == null).be.True()
|
|
1216
|
+
|
|
1217
|
+
await store().commitTransaction(req)
|
|
1218
|
+
await store().commitTransaction(req2)
|
|
1219
|
+
} catch (e) {
|
|
1220
|
+
await store().rollbackTransaction(req)
|
|
1221
|
+
await store().rollbackTransaction(req2)
|
|
1222
|
+
throw e
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1226
|
+
|
|
1227
|
+
should(found != null).be.True()
|
|
1228
|
+
})
|
|
1229
|
+
|
|
1230
|
+
it('should be able to see entity removed in transaction from another transaction', async () => {
|
|
1231
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1232
|
+
const req = Request({})
|
|
1233
|
+
const req2 = Request({})
|
|
1234
|
+
|
|
1235
|
+
const t1 = {
|
|
1236
|
+
name: 't1',
|
|
1237
|
+
engine: 'none',
|
|
1238
|
+
recipe: 'html'
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
await getCollection(colName).insert(t1)
|
|
1242
|
+
|
|
1243
|
+
await store().beginTransaction(req)
|
|
1244
|
+
await store().beginTransaction(req2)
|
|
1245
|
+
|
|
1246
|
+
try {
|
|
1247
|
+
await getCollection(colName).remove({
|
|
1248
|
+
name: 't1'
|
|
1249
|
+
}, req)
|
|
1250
|
+
|
|
1251
|
+
const found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1252
|
+
|
|
1253
|
+
should(found != null).be.True()
|
|
1254
|
+
|
|
1255
|
+
await store().commitTransaction(req)
|
|
1256
|
+
await store().commitTransaction(req2)
|
|
1257
|
+
} catch (e) {
|
|
1258
|
+
await store().rollbackTransaction(req)
|
|
1259
|
+
await store().rollbackTransaction(req2)
|
|
1260
|
+
throw e
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1264
|
+
|
|
1265
|
+
should(found == null).be.True()
|
|
1266
|
+
})
|
|
1267
|
+
|
|
1268
|
+
it('should not be able to commit changes of transaction from another transaction (insert)', async () => {
|
|
1269
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1270
|
+
const req = Request({})
|
|
1271
|
+
const req2 = Request({})
|
|
1272
|
+
|
|
1273
|
+
const t1 = {
|
|
1274
|
+
name: 't1',
|
|
1275
|
+
engine: 'none',
|
|
1276
|
+
recipe: 'html'
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
await store().beginTransaction(req)
|
|
1280
|
+
await store().beginTransaction(req2)
|
|
1281
|
+
|
|
1282
|
+
try {
|
|
1283
|
+
await getCollection(colName).insert(t1, req)
|
|
1284
|
+
|
|
1285
|
+
await store().commitTransaction(req2)
|
|
1286
|
+
|
|
1287
|
+
let found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1288
|
+
|
|
1289
|
+
should(found == null).be.True()
|
|
1290
|
+
|
|
1291
|
+
await store().commitTransaction(req)
|
|
1292
|
+
|
|
1293
|
+
found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
1294
|
+
|
|
1295
|
+
should(found != null).be.True()
|
|
1296
|
+
} catch (e) {
|
|
1297
|
+
await store().rollbackTransaction(req)
|
|
1298
|
+
await store().rollbackTransaction(req2)
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1302
|
+
|
|
1303
|
+
should(found != null).be.True()
|
|
1304
|
+
})
|
|
1305
|
+
|
|
1306
|
+
it('should not be able to commit changes of transaction from another transaction (update)', async () => {
|
|
1307
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1308
|
+
const req = Request({})
|
|
1309
|
+
const req2 = Request({})
|
|
1310
|
+
|
|
1311
|
+
const t1 = {
|
|
1312
|
+
name: 't1',
|
|
1313
|
+
engine: 'none',
|
|
1314
|
+
recipe: 'html'
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
await getCollection(colName).insert(t1)
|
|
1318
|
+
|
|
1319
|
+
await store().beginTransaction(req)
|
|
1320
|
+
await store().beginTransaction(req2)
|
|
1321
|
+
|
|
1322
|
+
try {
|
|
1323
|
+
await getCollection(colName).update({
|
|
1324
|
+
name: 't1'
|
|
1325
|
+
}, {
|
|
1326
|
+
$set: {
|
|
1327
|
+
engine: 'handlebars'
|
|
1328
|
+
}
|
|
1329
|
+
}, req)
|
|
1330
|
+
|
|
1331
|
+
await store().commitTransaction(req2)
|
|
1332
|
+
|
|
1333
|
+
let found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1334
|
+
|
|
1335
|
+
should(found.engine).be.eql('none')
|
|
1336
|
+
|
|
1337
|
+
await store().commitTransaction(req)
|
|
1338
|
+
|
|
1339
|
+
found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
1340
|
+
|
|
1341
|
+
should(found.engine).be.eql('handlebars')
|
|
1342
|
+
} catch (e) {
|
|
1343
|
+
await store().rollbackTransaction(req)
|
|
1344
|
+
await store().rollbackTransaction(req2)
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1348
|
+
|
|
1349
|
+
should(found.engine).be.eql('handlebars')
|
|
1350
|
+
})
|
|
1351
|
+
|
|
1352
|
+
it('should not be able to commit changes of transaction from another transaction (remove)', async () => {
|
|
1353
|
+
const colName = !isInternal ? 'templates' : 'internalTemplates'
|
|
1354
|
+
const req = Request({})
|
|
1355
|
+
const req2 = Request({})
|
|
1356
|
+
|
|
1357
|
+
const t1 = {
|
|
1358
|
+
name: 't1',
|
|
1359
|
+
engine: 'none',
|
|
1360
|
+
recipe: 'html'
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
await getCollection(colName).insert(t1)
|
|
1364
|
+
|
|
1365
|
+
await store().beginTransaction(req)
|
|
1366
|
+
await store().beginTransaction(req2)
|
|
1367
|
+
|
|
1368
|
+
try {
|
|
1369
|
+
await getCollection(colName).remove({
|
|
1370
|
+
name: 't1'
|
|
1371
|
+
}, req)
|
|
1372
|
+
|
|
1373
|
+
await store().commitTransaction(req2)
|
|
1374
|
+
|
|
1375
|
+
let found = await getCollection(colName).findOne({ name: 't1' }, req2)
|
|
1376
|
+
|
|
1377
|
+
should(found != null).be.True()
|
|
1378
|
+
|
|
1379
|
+
await store().commitTransaction(req)
|
|
1380
|
+
|
|
1381
|
+
found = await getCollection(colName).findOne({ name: 't1' }, req)
|
|
1382
|
+
|
|
1383
|
+
should(found == null).be.True()
|
|
1384
|
+
} catch (e) {
|
|
1385
|
+
await store().rollbackTransaction(req)
|
|
1386
|
+
await store().rollbackTransaction(req2)
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
const found = await getCollection(colName).findOne({ name: 't1' })
|
|
1390
|
+
|
|
1391
|
+
should(found == null).be.True()
|
|
1392
|
+
})
|
|
1393
|
+
})
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
function init (store) {
|
|
1398
|
+
store().registerComplexType('CommonPhantomType', {
|
|
1399
|
+
header: { type: 'Edm.String', document: { extension: 'html', engine: true } }
|
|
1400
|
+
})
|
|
1401
|
+
|
|
1402
|
+
const templateType = {
|
|
1403
|
+
name: { type: 'Edm.String' },
|
|
1404
|
+
content: { type: 'Edm.String', document: { extension: 'html', engine: true } },
|
|
1405
|
+
recipe: { type: 'Edm.String' },
|
|
1406
|
+
engine: { type: 'Edm.String' },
|
|
1407
|
+
phantom: { type: 'jsreport.CommonPhantomType', schema: { type: 'null' } }
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
store().registerEntityType('CommonTemplateType', { ...templateType })
|
|
1411
|
+
store().registerEntityType('CommonTemplateType2', { ...templateType })
|
|
1412
|
+
|
|
1413
|
+
store().registerEntitySet('templates', {
|
|
1414
|
+
entityType: 'jsreport.CommonTemplateType',
|
|
1415
|
+
splitIntoDirectories: true
|
|
1416
|
+
})
|
|
1417
|
+
|
|
1418
|
+
store().registerEntitySet('templates2', {
|
|
1419
|
+
entityType: 'jsreport.CommonTemplateType2',
|
|
1420
|
+
splitIntoDirectories: true
|
|
1421
|
+
})
|
|
1422
|
+
|
|
1423
|
+
store().registerEntitySet('internalTemplates', {
|
|
1424
|
+
entityType: 'jsreport.CommonTemplateType',
|
|
1425
|
+
internal: true,
|
|
1426
|
+
splitIntoDirectories: true
|
|
1427
|
+
})
|
|
1428
|
+
|
|
1429
|
+
store().registerEntitySet('internalTemplates2', {
|
|
1430
|
+
entityType: 'jsreport.CommonTemplateType2',
|
|
1431
|
+
internal: true,
|
|
1432
|
+
splitIntoDirectories: true
|
|
1433
|
+
})
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
async function clean (store) {
|
|
1437
|
+
await Promise.all(Object.keys(store().collections).map(async (collectionName) => {
|
|
1438
|
+
const all = await store().collection(collectionName).find({})
|
|
1439
|
+
return Promise.all(all.map((e) => store().collection(collectionName).remove({ _id: e._id })))
|
|
1440
|
+
}))
|
|
1441
|
+
|
|
1442
|
+
await Promise.all(Object.keys(store().internalCollections).map(async (collectionName) => {
|
|
1443
|
+
const all = await store().internalCollection(collectionName).find({})
|
|
1444
|
+
return Promise.all(all.map((e) => store().internalCollection(collectionName).remove({ _id: e._id })))
|
|
1445
|
+
}))
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
module.exports.init = init
|
|
1449
|
+
module.exports.clean = clean
|