monastery 1.28.4 → 1.28.5
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/.eslintrc.json +30 -4
- package/lib/index.js +0 -1
- package/lib/model-crud.js +32 -16
- package/lib/model-validate.js +10 -8
- package/lib/model.js +12 -4
- package/lib/rules.js +9 -12
- package/lib/util.js +13 -7
- package/package.json +16 -15
- package/plugins/images/index.js +4 -4
- package/test/blacklisting.js +4 -8
- package/test/crud.js +28 -31
- package/test/model.js +22 -25
- package/test/monk.js +4 -4
- package/test/plugin-images.js +400 -390
- package/test/populate.js +15 -18
- package/test/util.js +8 -8
- package/test/validate.js +50 -43
- package/test/virtuals.js +2 -4
package/test/crud.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
let util = require('../lib/util')
|
|
1
|
+
// let util = require('../lib/util')
|
|
2
2
|
|
|
3
3
|
module.exports = function(monastery, opendb) {
|
|
4
4
|
|
|
5
|
-
test('Basic operator calls', async (
|
|
5
|
+
test('Basic operator calls', async () => {
|
|
6
6
|
let db = (await opendb(null)).db
|
|
7
7
|
let user = db.model('user', {
|
|
8
8
|
fields: { name: { type: 'string' }},
|
|
@@ -53,13 +53,14 @@ module.exports = function(monastery, opendb) {
|
|
|
53
53
|
expect(find6).toEqual({ _id: inserted2[0]._id, name: 'Martin Luther1' })
|
|
54
54
|
|
|
55
55
|
// Missing parameters
|
|
56
|
-
await expect(user.find()).rejects.toThrow(
|
|
57
|
-
await expect(user.find(undefined)).rejects.toThrow(
|
|
58
|
-
await expect(user.find({})).rejects.toThrow(
|
|
59
|
-
await expect(user.find({ query: null })).rejects.toThrow(
|
|
60
|
-
await expect(user.find({ query: undefined })).rejects.toThrow(
|
|
61
|
-
await expect(user.find({ query: { _id: undefined }}))
|
|
62
|
-
|
|
56
|
+
await expect(user.find()).rejects.toThrow('Please pass an object or MongoId to options.query')
|
|
57
|
+
await expect(user.find(undefined)).rejects.toThrow('Please pass an object or MongoId to options.query')
|
|
58
|
+
await expect(user.find({})).rejects.toThrow('Please pass an object or MongoId to options.query')
|
|
59
|
+
await expect(user.find({ query: null })).rejects.toThrow('Please pass an object or MongoId to options.query')
|
|
60
|
+
await expect(user.find({ query: undefined })).rejects.toThrow('Please pass an object or MongoId to options.query')
|
|
61
|
+
await expect(user.find({ query: { _id: undefined }}))
|
|
62
|
+
.rejects.toThrow('Please pass an object or MongoId to options.query')
|
|
63
|
+
await expect(user.find(1)).rejects.toThrow('Please pass an object or MongoId to options.query')
|
|
63
64
|
|
|
64
65
|
// Bad MongoID
|
|
65
66
|
await expect(user.find({ query: '' })).resolves.toEqual(null)
|
|
@@ -89,10 +90,10 @@ module.exports = function(monastery, opendb) {
|
|
|
89
90
|
|
|
90
91
|
// Update (no/empty data object)
|
|
91
92
|
await expect(user.update({ query: inserted._id, data: {}}))
|
|
92
|
-
.rejects.toThrow(
|
|
93
|
+
.rejects.toThrow('No valid data passed to user.update()')
|
|
93
94
|
|
|
94
95
|
await expect(user.update({ query: inserted._id }))
|
|
95
|
-
.rejects.toThrow(
|
|
96
|
+
.rejects.toThrow('No valid data passed to user.update()')
|
|
96
97
|
|
|
97
98
|
// Update (no/empty data object, but has update operators
|
|
98
99
|
await expect(user.update({ query: inserted._id, $set: { name: 'bruce' }}))
|
|
@@ -114,7 +115,7 @@ module.exports = function(monastery, opendb) {
|
|
|
114
115
|
expect(beforeValidateHookCalled).toEqual(false)
|
|
115
116
|
|
|
116
117
|
// Update multiple
|
|
117
|
-
|
|
118
|
+
await user.update({
|
|
118
119
|
query: { _id: { $in: [inserted2[0]._id, inserted2[1]._id] }},
|
|
119
120
|
data: { name: 'Martin Luther3' },
|
|
120
121
|
multi: true
|
|
@@ -137,10 +138,9 @@ module.exports = function(monastery, opendb) {
|
|
|
137
138
|
expect(remove.result).toEqual({ n: 1, ok: 1 })
|
|
138
139
|
|
|
139
140
|
db.close()
|
|
140
|
-
done()
|
|
141
141
|
})
|
|
142
142
|
|
|
143
|
-
test('Insert defaults', async (
|
|
143
|
+
test('Insert defaults', async () => {
|
|
144
144
|
let db = (await opendb(null, { defaultObjects: true, serverSelectionTimeoutMS: 2000 })).db
|
|
145
145
|
let db2 = (await opendb(null, { useMilliseconds: true, serverSelectionTimeoutMS: 2000 })).db
|
|
146
146
|
let user = db.model('user', { fields: {
|
|
@@ -192,10 +192,9 @@ module.exports = function(monastery, opendb) {
|
|
|
192
192
|
|
|
193
193
|
db.close()
|
|
194
194
|
db2.close()
|
|
195
|
-
done()
|
|
196
195
|
})
|
|
197
196
|
|
|
198
|
-
test('update defaults', async (
|
|
197
|
+
test('update defaults', async () => {
|
|
199
198
|
let db = (await opendb(null, { useMilliseconds: true, serverSelectionTimeoutMS: 2000 })).db
|
|
200
199
|
let user = db.model('user', {
|
|
201
200
|
fields: {
|
|
@@ -236,7 +235,7 @@ module.exports = function(monastery, opendb) {
|
|
|
236
235
|
query: inserted._id,
|
|
237
236
|
data: {},
|
|
238
237
|
timestamps: false
|
|
239
|
-
})).rejects.toThrow(
|
|
238
|
+
})).rejects.toThrow('No valid data passed to user.update()')
|
|
240
239
|
|
|
241
240
|
// UpdatedAt override (wont work)
|
|
242
241
|
let updated4 = await user.update({
|
|
@@ -254,12 +253,11 @@ module.exports = function(monastery, opendb) {
|
|
|
254
253
|
expect(updated5.updatedAt).toEqual(1)
|
|
255
254
|
|
|
256
255
|
db.close()
|
|
257
|
-
done()
|
|
258
256
|
})
|
|
259
257
|
|
|
260
|
-
test('Insert with id casting', async (
|
|
258
|
+
test('Insert with id casting', async () => {
|
|
261
259
|
let db = (await opendb(null)).db
|
|
262
|
-
|
|
260
|
+
db.model('company', { fields: {
|
|
263
261
|
name: { type: 'string' }
|
|
264
262
|
}})
|
|
265
263
|
let user = db.model('user', { fields: {
|
|
@@ -279,10 +277,9 @@ module.exports = function(monastery, opendb) {
|
|
|
279
277
|
})
|
|
280
278
|
|
|
281
279
|
db.close()
|
|
282
|
-
done()
|
|
283
280
|
})
|
|
284
281
|
|
|
285
|
-
test('Find default field population', async (
|
|
282
|
+
test('Find default field population', async () => {
|
|
286
283
|
let db = (await opendb(null)).db
|
|
287
284
|
let user = db.model('user', {
|
|
288
285
|
fields: {
|
|
@@ -308,7 +305,7 @@ module.exports = function(monastery, opendb) {
|
|
|
308
305
|
],
|
|
309
306
|
pet: { dog: inserted._id }
|
|
310
307
|
}})
|
|
311
|
-
|
|
308
|
+
await dog.update({
|
|
312
309
|
query: inserted._id,
|
|
313
310
|
data: { user: inserted2._id }
|
|
314
311
|
})
|
|
@@ -370,10 +367,9 @@ module.exports = function(monastery, opendb) {
|
|
|
370
367
|
})
|
|
371
368
|
|
|
372
369
|
db.close()
|
|
373
|
-
done()
|
|
374
370
|
})
|
|
375
371
|
|
|
376
|
-
test('Hooks', async (
|
|
372
|
+
test('Hooks', async () => {
|
|
377
373
|
let db = (await opendb(null)).db
|
|
378
374
|
let user = db.model('user', {
|
|
379
375
|
fields: {
|
|
@@ -412,8 +408,8 @@ module.exports = function(monastery, opendb) {
|
|
|
412
408
|
let userDoc = await user.insert({ data: { first: 'Martin', last: 'Luther' }})
|
|
413
409
|
|
|
414
410
|
// Catch insert (a)synchronous errors thrown in function or through `next(err)`
|
|
415
|
-
await expect(user.insert({ data: { first: '' } })).rejects.toThrow(
|
|
416
|
-
await expect(user.insert({ data: { first: 'Martin' } })).rejects.toThrow(
|
|
411
|
+
await expect(user.insert({ data: { first: '' } })).rejects.toThrow('beforeInsert error 1..')
|
|
412
|
+
await expect(user.insert({ data: { first: 'Martin' } })).rejects.toThrow('beforeInsert error 2..')
|
|
417
413
|
await expect(user.insert({ data: { first: 'Martin', last: 'Luther' } })).resolves.toEqual({
|
|
418
414
|
_id: expect.any(Object),
|
|
419
415
|
first: 'Martin',
|
|
@@ -421,15 +417,17 @@ module.exports = function(monastery, opendb) {
|
|
|
421
417
|
})
|
|
422
418
|
|
|
423
419
|
// Catch update (a)synchronous errors thrown in function or through `next(err)`
|
|
424
|
-
await expect(user.update({ query: userDoc._id, data: { first: '' } }))
|
|
425
|
-
|
|
420
|
+
await expect(user.update({ query: userDoc._id, data: { first: '' } }))
|
|
421
|
+
.rejects.toThrow('beforeUpdate error 1..')
|
|
422
|
+
await expect(user.update({ query: userDoc._id, data: { first: 'Martin' } }))
|
|
423
|
+
.rejects.toThrow('beforeUpdate error 2..')
|
|
426
424
|
await expect(user.update({ query: userDoc._id, data: { first: 'Martin', last: 'Luther' } })).resolves.toEqual({
|
|
427
425
|
first: 'Martin',
|
|
428
426
|
last: 'Luther'
|
|
429
427
|
})
|
|
430
428
|
|
|
431
429
|
// Catch remove synchronous errors through `next(err)`
|
|
432
|
-
await expect(user.remove({ query: userDoc._id })).rejects.toThrow(
|
|
430
|
+
await expect(user.remove({ query: userDoc._id })).rejects.toThrow('beforeRemove error..')
|
|
433
431
|
|
|
434
432
|
// After find continues series
|
|
435
433
|
await expect(user.find({ query: userDoc._id })).resolves.toEqual({
|
|
@@ -439,7 +437,6 @@ module.exports = function(monastery, opendb) {
|
|
|
439
437
|
})
|
|
440
438
|
|
|
441
439
|
db.close()
|
|
442
|
-
done()
|
|
443
440
|
})
|
|
444
441
|
|
|
445
442
|
}
|
package/test/model.js
CHANGED
|
@@ -19,13 +19,13 @@ module.exports = function(monastery, opendb) {
|
|
|
19
19
|
insertOnly: true,
|
|
20
20
|
isInteger: true,
|
|
21
21
|
timestampField: true,
|
|
22
|
-
type:
|
|
22
|
+
type: 'integer',
|
|
23
23
|
},
|
|
24
24
|
updatedAt: {
|
|
25
25
|
default: expect.any(Function),
|
|
26
26
|
isInteger: true,
|
|
27
27
|
timestampField: true,
|
|
28
|
-
type:
|
|
28
|
+
type: 'integer',
|
|
29
29
|
},
|
|
30
30
|
})
|
|
31
31
|
|
|
@@ -79,13 +79,13 @@ module.exports = function(monastery, opendb) {
|
|
|
79
79
|
insertOnly: true,
|
|
80
80
|
isInteger: true,
|
|
81
81
|
timestampField: true,
|
|
82
|
-
type:
|
|
82
|
+
type: 'integer'
|
|
83
83
|
},
|
|
84
84
|
updatedAt: {
|
|
85
85
|
default: expect.any(Function),
|
|
86
86
|
isInteger: true,
|
|
87
87
|
timestampField: true,
|
|
88
|
-
type:
|
|
88
|
+
type: 'integer'
|
|
89
89
|
}
|
|
90
90
|
})
|
|
91
91
|
})
|
|
@@ -115,7 +115,7 @@ module.exports = function(monastery, opendb) {
|
|
|
115
115
|
})
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
-
test('Model indexes', async (
|
|
118
|
+
test('Model indexes', async () => {
|
|
119
119
|
// Need to test different types of indexes
|
|
120
120
|
let db = (await opendb(null)).db
|
|
121
121
|
|
|
@@ -129,10 +129,10 @@ module.exports = function(monastery, opendb) {
|
|
|
129
129
|
|
|
130
130
|
// Unique & text index (after model initialisation, in serial)
|
|
131
131
|
let userIndexRawModel = db.model('userIndexRaw', {})
|
|
132
|
-
|
|
132
|
+
await userIndexRawModel._setupIndexes({
|
|
133
133
|
email: { type: 'string', index: 'unique' },
|
|
134
134
|
})
|
|
135
|
-
|
|
135
|
+
await userIndexRawModel._setupIndexes({
|
|
136
136
|
name: { type: 'string', index: 'text' },
|
|
137
137
|
})
|
|
138
138
|
let indexes = await db._db.collection('userIndexRaw').indexes()
|
|
@@ -170,28 +170,27 @@ module.exports = function(monastery, opendb) {
|
|
|
170
170
|
textIndexVersion: 3
|
|
171
171
|
})
|
|
172
172
|
|
|
173
|
-
// No text index change error, i.e. new Error(
|
|
173
|
+
// No text index change error, i.e. new Error('Index with name: text already exists with different options')
|
|
174
174
|
await expect(userIndexModel._setupIndexes({
|
|
175
175
|
name: { type: 'string', index: 'text' },
|
|
176
176
|
name2: { type: 'string', index: 'text' }
|
|
177
177
|
})).resolves.toEqual([{
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
'key': { 'name': 'text', 'name2': 'text' },
|
|
179
|
+
'name': 'text',
|
|
180
180
|
}])
|
|
181
181
|
|
|
182
182
|
// Text index on a different model
|
|
183
183
|
await expect(userIndexRawModel._setupIndexes({
|
|
184
184
|
name2: { type: 'string', index: 'text' }
|
|
185
185
|
})).resolves.toEqual([{
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
'key': {'name2': 'text'},
|
|
187
|
+
'name': 'text',
|
|
188
188
|
}])
|
|
189
189
|
|
|
190
190
|
db.close()
|
|
191
|
-
done()
|
|
192
191
|
})
|
|
193
192
|
|
|
194
|
-
test('Model 2dsphere indexes', async (
|
|
193
|
+
test('Model 2dsphere indexes', async () => {
|
|
195
194
|
// Setup. The tested model needs to be unique as race condition issue arises when the same model
|
|
196
195
|
// with text indexes are setup at the same time
|
|
197
196
|
let db = (await opendb(null)).db
|
|
@@ -217,10 +216,10 @@ module.exports = function(monastery, opendb) {
|
|
|
217
216
|
coordinates: expect.any(Array),
|
|
218
217
|
schema: {
|
|
219
218
|
default: undefined,
|
|
220
|
-
index:
|
|
219
|
+
index: '2dsphere',
|
|
221
220
|
isObject: true,
|
|
222
221
|
nullObject: undefined,
|
|
223
|
-
type:
|
|
222
|
+
type: 'object'
|
|
224
223
|
}
|
|
225
224
|
})
|
|
226
225
|
expect(db.user3.fields.location2).toEqual({
|
|
@@ -228,10 +227,10 @@ module.exports = function(monastery, opendb) {
|
|
|
228
227
|
coordinates: expect.any(Array),
|
|
229
228
|
schema: {
|
|
230
229
|
default: undefined,
|
|
231
|
-
index: { type:
|
|
230
|
+
index: { type: '2dsphere' },
|
|
232
231
|
isObject: true,
|
|
233
232
|
nullObject: undefined,
|
|
234
|
-
type:
|
|
233
|
+
type: 'object'
|
|
235
234
|
}
|
|
236
235
|
})
|
|
237
236
|
|
|
@@ -244,17 +243,16 @@ module.exports = function(monastery, opendb) {
|
|
|
244
243
|
_id: expect.any(Object),
|
|
245
244
|
location: {
|
|
246
245
|
coordinates: [172.5880385, -43.3311608],
|
|
247
|
-
type:
|
|
246
|
+
type: 'Point'
|
|
248
247
|
},
|
|
249
248
|
})
|
|
250
249
|
|
|
251
250
|
db.close()
|
|
252
|
-
done()
|
|
253
251
|
})
|
|
254
252
|
|
|
255
|
-
test('Model findBL, findBLProject', async (
|
|
253
|
+
test('Model findBL, findBLProject', async () => {
|
|
256
254
|
let db = (await opendb(null)).db
|
|
257
|
-
|
|
255
|
+
db.model('bird', { fields: {
|
|
258
256
|
name: { type: 'string' }
|
|
259
257
|
}})
|
|
260
258
|
let user = db.model('user', {
|
|
@@ -355,8 +353,8 @@ module.exports = function(monastery, opendb) {
|
|
|
355
353
|
'hiddenDeepModel': 0,
|
|
356
354
|
'hiddenDeepModels': 0,
|
|
357
355
|
// Deep model blacklists
|
|
358
|
-
|
|
359
|
-
|
|
356
|
+
'deepModel.myBird.password': 0,
|
|
357
|
+
'deepModel2.myBird.password': 0
|
|
360
358
|
})
|
|
361
359
|
|
|
362
360
|
// Test whitelisting
|
|
@@ -415,7 +413,6 @@ module.exports = function(monastery, opendb) {
|
|
|
415
413
|
})
|
|
416
414
|
|
|
417
415
|
db.close()
|
|
418
|
-
done()
|
|
419
416
|
})
|
|
420
417
|
|
|
421
418
|
}
|
package/test/monk.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module.exports = function(monastery, opendb) {
|
|
2
2
|
|
|
3
|
-
test('Monk confilicts', async (
|
|
3
|
+
test('Monk confilicts', async () => {
|
|
4
4
|
// Setup
|
|
5
5
|
let db = (await opendb(false)).db
|
|
6
6
|
let monkdb = require('monk')(':badconnection', () => {})
|
|
7
|
-
|
|
7
|
+
db.model('user', {})
|
|
8
8
|
let modelNamedConnected = db.model('connected', {})
|
|
9
9
|
|
|
10
10
|
// Any of our monastery properties already exist on the manager?
|
|
@@ -19,8 +19,8 @@ module.exports = function(monastery, opendb) {
|
|
|
19
19
|
expect(db.connected).toEqual(db.connected)
|
|
20
20
|
expect(db.model.connected).toEqual(modelNamedConnected)
|
|
21
21
|
|
|
22
|
-
// Close test since monk(uri) awaits upoin a connection
|
|
23
|
-
done()
|
|
22
|
+
// Close test since monk(uri) awaits upoin a connection (Update, done not needed in latest jest)
|
|
23
|
+
// done()
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
test('Monastery connect with promise', (done) => {
|