monastery 1.28.3 → 1.30.0

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/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: "integer",
22
+ type: 'integer',
23
23
  },
24
24
  updatedAt: {
25
25
  default: expect.any(Function),
26
26
  isInteger: true,
27
27
  timestampField: true,
28
- type: "integer",
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: "integer"
82
+ type: 'integer'
83
83
  },
84
84
  updatedAt: {
85
85
  default: expect.any(Function),
86
86
  isInteger: true,
87
87
  timestampField: true,
88
- type: "integer"
88
+ type: 'integer'
89
89
  }
90
90
  })
91
91
  })
@@ -115,11 +115,10 @@ module.exports = function(monastery, opendb) {
115
115
  })
116
116
  })
117
117
 
118
- test('Model indexes', async (done) => {
119
- // Need to test different types of indexes
118
+ test('Model indexes', async () => {
119
+ // Setup: Need to test different types of indexes
120
120
  let db = (await opendb(null)).db
121
-
122
- // Drop previously tested collections
121
+ // Setup: Drop previously tested collections
123
122
  if ((await db._db.listCollections().toArray()).find(o => o.name == 'userIndexRaw')) {
124
123
  await db._db.collection('userIndexRaw').drop()
125
124
  }
@@ -129,10 +128,10 @@ module.exports = function(monastery, opendb) {
129
128
 
130
129
  // Unique & text index (after model initialisation, in serial)
131
130
  let userIndexRawModel = db.model('userIndexRaw', {})
132
- let setupIndex1 = await userIndexRawModel._setupIndexes({
131
+ await userIndexRawModel._setupIndexes({
133
132
  email: { type: 'string', index: 'unique' },
134
133
  })
135
- let setupIndex2 = await userIndexRawModel._setupIndexes({
134
+ await userIndexRawModel._setupIndexes({
136
135
  name: { type: 'string', index: 'text' },
137
136
  })
138
137
  let indexes = await db._db.collection('userIndexRaw').indexes()
@@ -170,28 +169,117 @@ module.exports = function(monastery, opendb) {
170
169
  textIndexVersion: 3
171
170
  })
172
171
 
173
- // No text index change error, i.e. new Error("Index with name: text already exists with different options")
172
+ // No text index change error, i.e. new Error('Index with name: text already exists with different options')
174
173
  await expect(userIndexModel._setupIndexes({
175
174
  name: { type: 'string', index: 'text' },
176
175
  name2: { type: 'string', index: 'text' }
177
176
  })).resolves.toEqual([{
178
- "key": { "name": "text", "name2": "text" },
179
- "name": "text",
177
+ 'key': { 'name': 'text', 'name2': 'text' },
178
+ 'name': 'text',
180
179
  }])
181
180
 
182
181
  // Text index on a different model
183
182
  await expect(userIndexRawModel._setupIndexes({
184
183
  name2: { type: 'string', index: 'text' }
185
184
  })).resolves.toEqual([{
186
- "key": {"name2": "text"},
187
- "name": "text",
185
+ 'key': {'name2': 'text'},
186
+ 'name': 'text',
187
+ }])
188
+
189
+ db.close()
190
+ })
191
+
192
+ test('Model subdocument indexes', async () => {
193
+ // Setup: Need to test different types of indexes
194
+ let db = (await opendb(null)).db
195
+ // Setup: Drop previously tested collections
196
+ if ((await db._db.listCollections().toArray()).find(o => o.name == 'userIndexSubdoc')) {
197
+ await db._db.collection('userIndexSubdoc').drop()
198
+ }
199
+ // Run
200
+ let userModel = await db.model('userIndexSubdoc', {
201
+ fields: {}
202
+ })
203
+ await expect(userModel._setupIndexes(
204
+ {
205
+ animals: {
206
+ name: { type: 'string', index: 'unique' },
207
+ },
208
+ animals2: {
209
+ names: {
210
+ name: { type: 'string', index: 'unique' },
211
+ },
212
+ },
213
+ animals3: {
214
+ names: {
215
+ name: { type: 'string', index: 'text' },
216
+ },
217
+ },
218
+ }, {
219
+ dryRun: true
220
+ }
221
+ )).resolves.toEqual([{
222
+ 'key': { 'animals.name': 1 },
223
+ 'name': 'animals.name_1',
224
+ 'unique': true,
225
+ }, {
226
+ 'key': { 'animals2.names.name': 1 },
227
+ 'name': 'animals2.names.name_1',
228
+ 'unique': true,
229
+ }, {
230
+ 'key': { 'animals3.names.name': 'text' },
231
+ 'name': 'text',
188
232
  }])
189
233
 
190
234
  db.close()
191
- done()
192
235
  })
193
236
 
194
- test('Model 2dsphere indexes', async (done) => {
237
+ test('Model array indexes', async () => {
238
+ // Setup: Need to test different types of indexes
239
+ let db = (await opendb(null)).db
240
+ // Setup: Drop previously tested collections
241
+ if ((await db._db.listCollections().toArray()).find(o => o.name == 'userIndexArray')) {
242
+ await db._db.collection('userIndexArray').drop()
243
+ }
244
+ // Run
245
+ let userModel = await db.model('userIndexArray', {
246
+ fields: {}
247
+ })
248
+ await expect(userModel._setupIndexes(
249
+ {
250
+ animals: [{
251
+ name: { type: 'string', index: 'unique' },
252
+ }],
253
+ animals2: [{ type: 'string', index: true }],
254
+ animals3: [[{ type: 'string', index: true }]],
255
+ animals4: [{
256
+ names: [{
257
+ name: { type: 'string', index: 'unique' },
258
+ }],
259
+ }],
260
+ }, {
261
+ dryRun: true
262
+ }
263
+ )).resolves.toEqual([{
264
+ 'key': { 'animals.name': 1 },
265
+ 'name': 'animals.name_1',
266
+ 'unique': true,
267
+ }, {
268
+ 'key': { 'animals2': 1 },
269
+ 'name': 'animals2_1',
270
+ }, {
271
+ 'key': { 'animals3.0': 1 },
272
+ 'name': 'animals3.0_1',
273
+ }, {
274
+ 'key': { 'animals4.names.name': 1 },
275
+ 'name': 'animals4.names.name_1',
276
+ 'unique': true,
277
+ }])
278
+
279
+ db.close()
280
+ })
281
+
282
+ test('Model 2dsphere indexes', async () => {
195
283
  // Setup. The tested model needs to be unique as race condition issue arises when the same model
196
284
  // with text indexes are setup at the same time
197
285
  let db = (await opendb(null)).db
@@ -217,10 +305,10 @@ module.exports = function(monastery, opendb) {
217
305
  coordinates: expect.any(Array),
218
306
  schema: {
219
307
  default: undefined,
220
- index: "2dsphere",
308
+ index: '2dsphere',
221
309
  isObject: true,
222
310
  nullObject: undefined,
223
- type: "object"
311
+ type: 'object'
224
312
  }
225
313
  })
226
314
  expect(db.user3.fields.location2).toEqual({
@@ -228,10 +316,10 @@ module.exports = function(monastery, opendb) {
228
316
  coordinates: expect.any(Array),
229
317
  schema: {
230
318
  default: undefined,
231
- index: { type: "2dsphere" },
319
+ index: { type: '2dsphere' },
232
320
  isObject: true,
233
321
  nullObject: undefined,
234
- type: "object"
322
+ type: 'object'
235
323
  }
236
324
  })
237
325
 
@@ -244,17 +332,16 @@ module.exports = function(monastery, opendb) {
244
332
  _id: expect.any(Object),
245
333
  location: {
246
334
  coordinates: [172.5880385, -43.3311608],
247
- type: "Point"
335
+ type: 'Point'
248
336
  },
249
337
  })
250
338
 
251
339
  db.close()
252
- done()
253
340
  })
254
341
 
255
- test('Model findBL, findBLProject', async (done) => {
342
+ test('Model findBL, findBLProject', async () => {
256
343
  let db = (await opendb(null)).db
257
- let bird = db.model('bird', { fields: {
344
+ db.model('bird', { fields: {
258
345
  name: { type: 'string' }
259
346
  }})
260
347
  let user = db.model('user', {
@@ -355,8 +442,8 @@ module.exports = function(monastery, opendb) {
355
442
  'hiddenDeepModel': 0,
356
443
  'hiddenDeepModels': 0,
357
444
  // Deep model blacklists
358
- "deepModel.myBird.password": 0,
359
- "deepModel2.myBird.password": 0
445
+ 'deepModel.myBird.password': 0,
446
+ 'deepModel2.myBird.password': 0
360
447
  })
361
448
 
362
449
  // Test whitelisting
@@ -415,7 +502,6 @@ module.exports = function(monastery, opendb) {
415
502
  })
416
503
 
417
504
  db.close()
418
- done()
419
505
  })
420
506
 
421
507
  }
package/test/monk.js CHANGED
@@ -1,10 +1,10 @@
1
1
  module.exports = function(monastery, opendb) {
2
2
 
3
- test('Monk confilicts', async (done) => {
3
+ test('Monk confilicts', async () => {
4
4
  // Setup
5
5
  let db = (await opendb(false)).db
6
6
  let monkdb = require('monk')(':badconnection', () => {})
7
- let user = db.model('user', {})
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) => {