@sprucelabs/data-stores 19.3.3 → 20.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/.spruce/errors/dataStores/indexNotFound.schema.js +6 -0
- package/build/.spruce/errors/errors.types.d.ts +7 -0
- package/build/databases/MongoDatabase.js +10 -6
- package/build/databases/NeDbDatabase.js +6 -2
- package/build/errors/SpruceError.js +3 -0
- package/build/errors/indexNotFound.builder.d.ts +4 -0
- package/build/errors/indexNotFound.builder.js +4 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +7 -0
- package/build/esm/databases/MongoDatabase.js +10 -6
- package/build/esm/databases/NeDbDatabase.js +6 -2
- package/build/esm/errors/SpruceError.js +3 -0
- package/build/esm/errors/indexNotFound.builder.d.ts +4 -0
- package/build/esm/errors/indexNotFound.builder.js +4 -0
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/tests/databaseAssertUtil.d.ts +74 -67
- package/build/esm/tests/databaseAssertUtil.js +620 -244
- package/build/esm/tests/pluckAssertionMethods.d.ts +1 -1
- package/build/esm/types/database.types.d.ts +6 -0
- package/build/esm/types/query.types.d.ts +5 -4
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -1
- package/build/tests/databaseAssertUtil.d.ts +74 -67
- package/build/tests/databaseAssertUtil.js +599 -243
- package/build/tests/pluckAssertionMethods.d.ts +1 -1
- package/build/types/database.types.d.ts +6 -0
- package/build/types/query.types.d.ts +5 -4
- package/package.json +11 -11
|
@@ -10,17 +10,110 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { assertOptions } from '@sprucelabs/schema';
|
|
11
11
|
import { assert } from '@sprucelabs/test-utils';
|
|
12
12
|
import { errorAssert } from '@sprucelabs/test-utils';
|
|
13
|
-
import SpruceError from '../errors/SpruceError.js';
|
|
14
13
|
import generateId from '../utilities/generateId.js';
|
|
15
|
-
import pluckAssertionMethods from './pluckAssertionMethods.js';
|
|
16
14
|
const databaseAssertUtil = {
|
|
17
15
|
collectionName: 'test_collection',
|
|
18
|
-
runSuite(connect) {
|
|
16
|
+
runSuite(connect, tests) {
|
|
19
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
18
|
assertOptions({ connect }, ['connect']);
|
|
21
|
-
const methods =
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const methods = [
|
|
20
|
+
//connecting
|
|
21
|
+
'assertThrowsWithInvalidConnectionString',
|
|
22
|
+
'assertThrowsWhenCantConnect',
|
|
23
|
+
'assertThrowsWithBadDatabaseName',
|
|
24
|
+
//inserting
|
|
25
|
+
'assertEmptyDatabaseReturnsEmptyArray',
|
|
26
|
+
'assertKnowsIfConnectionClosed',
|
|
27
|
+
'assertFindOneOnEmptyDatabaseReturnsNull',
|
|
28
|
+
'assertCanSortDesc',
|
|
29
|
+
'assertCanSortAsc',
|
|
30
|
+
'assertCanSortById',
|
|
31
|
+
'assertCanQueryWithOr',
|
|
32
|
+
'generateIdDifferentEachTime',
|
|
33
|
+
'assertInsertingGeneratesId',
|
|
34
|
+
'assertCanCreateMany',
|
|
35
|
+
'assertCanLimitResults',
|
|
36
|
+
'assertCanCreateWithObjectField',
|
|
37
|
+
//counting
|
|
38
|
+
'assertCanCountOnId',
|
|
39
|
+
'assertCanCount',
|
|
40
|
+
//updating
|
|
41
|
+
'assertThrowsWhenUpdatingRecordNotFound',
|
|
42
|
+
'assertCanUpdate',
|
|
43
|
+
'assertCanUpdateMany',
|
|
44
|
+
'assertCanPushOntoArrayValue',
|
|
45
|
+
'canUpdateWithObjectField',
|
|
46
|
+
'canUpdateFieldInObjectFieldWithTargettedWhere',
|
|
47
|
+
'assertCanSaveAndGetNullAndUndefined',
|
|
48
|
+
//upserting
|
|
49
|
+
'assertCanUpsertOne',
|
|
50
|
+
'assertCanUpsertNull',
|
|
51
|
+
'assertCanPushToArrayOnUpsert',
|
|
52
|
+
//finding
|
|
53
|
+
'assertEmptyDatabaseReturnsEmptyArray',
|
|
54
|
+
'assertFindOneOnEmptyDatabaseReturnsNull',
|
|
55
|
+
'assertCanLimitResults',
|
|
56
|
+
'assertCanLimitResultsToZero',
|
|
57
|
+
'assertCanFindWithBooleanField',
|
|
58
|
+
'assertCanQueryByGtLtGteLte',
|
|
59
|
+
'assertCanQueryPathWithDotSyntax',
|
|
60
|
+
'assertCanReturnOnlySelectFields',
|
|
61
|
+
'assertCanSearchByRegex',
|
|
62
|
+
'assertCanFindWithNe',
|
|
63
|
+
'assertCanFindWithIn',
|
|
64
|
+
//deleting
|
|
65
|
+
'assertCanDeleteRecord',
|
|
66
|
+
'assertCanDeleteOne',
|
|
67
|
+
//indexing
|
|
68
|
+
'assertHasNoUniqueIndexToStart',
|
|
69
|
+
'assertCanCreateUniqueIndex',
|
|
70
|
+
'assertCanCreateMultiFieldUniqueIndex',
|
|
71
|
+
'assertCantCreateUniqueIndexTwice',
|
|
72
|
+
'assertCanDropUniqueIndex',
|
|
73
|
+
'assertCanDropCompoundUniqueIndex',
|
|
74
|
+
'assertCantDropUniqueIndexThatDoesntExist',
|
|
75
|
+
'assertCantDropIndexWhenNoIndexExists',
|
|
76
|
+
'assertCantDropCompoundUniqueIndexThatDoesntExist',
|
|
77
|
+
'assertSyncingUniqueIndexsAddsMissingIndexes',
|
|
78
|
+
'assertSyncingUniqueIndexsSkipsExistingIndexs',
|
|
79
|
+
'assertSyncingUniqueIndexesRemovesExtraIndexes',
|
|
80
|
+
'assertSyncingUniqueIndexesIsRaceProof',
|
|
81
|
+
'assertSyncingIndexesDoesNotAddAndRemove',
|
|
82
|
+
'assertUniqueIndexBlocksDuplicates',
|
|
83
|
+
'assertDuplicateKeyThrowsOnInsert',
|
|
84
|
+
'assertSettingUniqueIndexViolationThrowsSpruceError',
|
|
85
|
+
'assertCanCreateUniqueIndexOnNestedField',
|
|
86
|
+
'assertUpsertWithUniqueIndex',
|
|
87
|
+
'assertNestedFieldIndexUpdates',
|
|
88
|
+
'assertHasNoIndexToStart',
|
|
89
|
+
'assertCanCreateIndex',
|
|
90
|
+
'assertCantCreateSameIndexTwice',
|
|
91
|
+
'assertCanCreateMultiFieldIndex',
|
|
92
|
+
'assertCanDropIndex',
|
|
93
|
+
'assertCanDropCompoundIndex',
|
|
94
|
+
'assertCantDropCompoundIndexThatDoesNotExist',
|
|
95
|
+
'assertSyncIndexesSkipsExisting',
|
|
96
|
+
'assertSyncIndexesRemovesExtraIndexes',
|
|
97
|
+
'assertSyncIndexesHandlesRaceConditions',
|
|
98
|
+
'assertSyncIndexesDoesNotRemoveExisting',
|
|
99
|
+
'assertDuplicateFieldsWithMultipleUniqueIndexesWorkAsExpected',
|
|
100
|
+
];
|
|
101
|
+
const db = yield connectToDabatase(connect);
|
|
102
|
+
yield db.dropDatabase();
|
|
103
|
+
yield this.shutdown(db);
|
|
104
|
+
const toRun = tests !== null && tests !== void 0 ? tests : methods;
|
|
105
|
+
for (const method of toRun) {
|
|
106
|
+
try {
|
|
107
|
+
//@ts-ignore
|
|
108
|
+
yield this[method](connect);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
const prefix = `Error in ${method}:\n\n `;
|
|
112
|
+
err.message = `${prefix} ${err.message}`;
|
|
113
|
+
err.stack = `${prefix} ${err.stack}`;
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
24
117
|
});
|
|
25
118
|
},
|
|
26
119
|
_getFilteredIndexes(db) {
|
|
@@ -34,17 +127,36 @@ const databaseAssertUtil = {
|
|
|
34
127
|
_assertUpdateUpdatedRightNumberOfRecords(db, search, updates, expectedUpdateCount) {
|
|
35
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
129
|
const updatedCount = yield db.update(this.collectionName, search, updates);
|
|
37
|
-
assert.isEqual(updatedCount, expectedUpdateCount);
|
|
130
|
+
assert.isEqual(updatedCount, expectedUpdateCount, 'db.update() did not update the expected amount of records! Make sure it returns an integer of the number of records updated.');
|
|
38
131
|
const count = yield db.count(this.collectionName, updates);
|
|
39
132
|
assert.isEqual(count, expectedUpdateCount);
|
|
40
133
|
});
|
|
41
134
|
},
|
|
135
|
+
generateIdDifferentEachTime(connect) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const db = yield connectToDabatase(connect);
|
|
138
|
+
const id1 = db.generateId();
|
|
139
|
+
const id2 = db.generateId();
|
|
140
|
+
assert.isNotEqual(id1, id2, 'generateId() must generate a different id each time');
|
|
141
|
+
yield this.shutdown(db);
|
|
142
|
+
});
|
|
143
|
+
},
|
|
42
144
|
assertCanSortDesc(connect) {
|
|
43
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const db = yield connect
|
|
45
|
-
yield db.createOne(this.collectionName, {
|
|
46
|
-
|
|
47
|
-
|
|
146
|
+
const db = yield connectToDabatase(connect);
|
|
147
|
+
const second = yield db.createOne(this.collectionName, {
|
|
148
|
+
name: 'second',
|
|
149
|
+
count: 1,
|
|
150
|
+
});
|
|
151
|
+
const third = yield db.createOne(this.collectionName, {
|
|
152
|
+
name: 'third',
|
|
153
|
+
count: 5,
|
|
154
|
+
});
|
|
155
|
+
const first = yield db.createOne(this.collectionName, {
|
|
156
|
+
name: 'first',
|
|
157
|
+
count: -1,
|
|
158
|
+
});
|
|
159
|
+
assert.isFunction(db.find, `db.find() must be a function.`);
|
|
48
160
|
const results = yield db.find(this.collectionName, {}, {
|
|
49
161
|
sort: [
|
|
50
162
|
{
|
|
@@ -53,20 +165,25 @@ const databaseAssertUtil = {
|
|
|
53
165
|
},
|
|
54
166
|
],
|
|
55
167
|
});
|
|
56
|
-
assert.
|
|
57
|
-
assert.
|
|
58
|
-
assert.isEqual(results[
|
|
168
|
+
assert.isBelow(results.length, 4, `You are not resetting data when .dropDatabase() is called. If you can't drop the database in your env, then you need to clear at all rows in all tables! Got back ${results.length} records!`);
|
|
169
|
+
assert.isLength(results, 3, `Should have 3 records back from find() after 3 createOne()s. Make sure your createOne() is inserting records! I only got back ${results.length} records!`);
|
|
170
|
+
assert.isEqual(results[0].name, 'third', `first record should be named "third" when sorting desc by name. Make sure you are sorting using the "sort" option.`);
|
|
171
|
+
assert.isEqual(results[1].name, 'second', `second record should be named "second" when sorting desc by name.`);
|
|
172
|
+
assert.isEqual(results[2].name, 'first', `third record should be named "first" when sorting desc by name.`);
|
|
173
|
+
assert.isEqualDeep(results[0], third, `createOne() is not returning the record that was created!`);
|
|
174
|
+
assert.isEqualDeep(results[1], second, `createOne() is not returning the record that was created!`);
|
|
175
|
+
assert.isEqualDeep(results[2], first, `createOne() is not returning the record that was created!`);
|
|
59
176
|
const result = yield db.findOne(this.collectionName, undefined, {
|
|
60
177
|
sort: [{ field: 'count', direction: 'desc' }],
|
|
61
178
|
});
|
|
62
|
-
assert.isTruthy(result);
|
|
63
|
-
assert.isEqual(result.name, 'third');
|
|
179
|
+
assert.isTruthy(result, 'findOne() should return a record!');
|
|
180
|
+
assert.isEqual(result.name, 'third', 'findOne() should honor sort!');
|
|
64
181
|
yield this.shutdown(db);
|
|
65
182
|
});
|
|
66
183
|
},
|
|
67
184
|
assertCanSortAsc(connect) {
|
|
68
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const db = yield connect
|
|
186
|
+
const db = yield connectToDabatase(connect);
|
|
70
187
|
yield db.createOne(this.collectionName, { name: 'second', count: 1 });
|
|
71
188
|
yield db.createOne(this.collectionName, { name: 'third', count: 5 });
|
|
72
189
|
yield db.createOne(this.collectionName, { name: 'first', count: -1 });
|
|
@@ -78,9 +195,9 @@ const databaseAssertUtil = {
|
|
|
78
195
|
},
|
|
79
196
|
],
|
|
80
197
|
});
|
|
81
|
-
assert.isEqual(results[0].name, 'first');
|
|
82
|
-
assert.isEqual(results[1].name, 'second');
|
|
83
|
-
assert.isEqual(results[2].name, 'third');
|
|
198
|
+
assert.isEqual(results[0].name, 'first', 'find is not sorting ascending');
|
|
199
|
+
assert.isEqual(results[1].name, 'second', 'find is not sorting ascending');
|
|
200
|
+
assert.isEqual(results[2].name, 'third', 'find is not sorting ascending');
|
|
84
201
|
const result = yield db.findOne(this.collectionName, undefined, {
|
|
85
202
|
sort: [{ field: 'count', direction: 'asc' }],
|
|
86
203
|
});
|
|
@@ -91,86 +208,96 @@ const databaseAssertUtil = {
|
|
|
91
208
|
},
|
|
92
209
|
assertInsertingGeneratesId(connect) {
|
|
93
210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const db = yield connect
|
|
211
|
+
const db = yield connectToDabatase(connect);
|
|
212
|
+
const name = generateId();
|
|
95
213
|
const inserted = yield db.createOne(this.collectionName, {
|
|
96
|
-
name
|
|
214
|
+
name,
|
|
97
215
|
});
|
|
98
|
-
assert.isTruthy(inserted);
|
|
99
|
-
assert.
|
|
100
|
-
assert.isEqual(inserted.name, '
|
|
216
|
+
assert.isTruthy(inserted, "createOne() didn't return anything!");
|
|
217
|
+
assert.isTruthy(inserted.id, 'createOne() record id is missing!');
|
|
218
|
+
assert.isEqual(inserted.name, name, 'createOne() record name field was not set to ' + name);
|
|
101
219
|
yield this.shutdown(db);
|
|
102
220
|
});
|
|
103
221
|
},
|
|
104
222
|
assertThrowsWhenUpdatingRecordNotFound(connect) {
|
|
105
223
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const db = yield connect
|
|
107
|
-
|
|
108
|
-
|
|
224
|
+
const db = yield connectToDabatase(connect);
|
|
225
|
+
assert.isFunction(db.generateId, `db.generateId() must be a function that returns a unique identifier.`);
|
|
226
|
+
assert.isFunction(db.updateOne, 'You must implement updateOne() in your database adapter.');
|
|
227
|
+
yield this._assertThrowsExpectedNotFoundOnUpdateOne(db, {
|
|
228
|
+
id: db.generateId(),
|
|
229
|
+
});
|
|
230
|
+
yield this._assertThrowsExpectedNotFoundOnUpdateOne(db, { count: 10 });
|
|
109
231
|
yield this.shutdown(db);
|
|
110
232
|
});
|
|
111
233
|
},
|
|
112
234
|
shutdown(db) {
|
|
113
235
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
|
|
115
|
-
|
|
236
|
+
if (db.isConnected()) {
|
|
237
|
+
yield db.dropDatabase();
|
|
238
|
+
yield db.close();
|
|
239
|
+
}
|
|
116
240
|
});
|
|
117
241
|
},
|
|
118
242
|
assertCanCreateUniqueIndex(connect) {
|
|
119
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
const db = yield connect
|
|
244
|
+
const db = yield connectToDabatase(connect);
|
|
121
245
|
yield db.createUniqueIndex(this.collectionName, ['uniqueField']);
|
|
122
246
|
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
123
|
-
assert.isLength(indexes, 1);
|
|
124
|
-
assert.isLength(indexes[0], 1);
|
|
125
|
-
assert.isEqual(indexes[0][0], 'uniqueField');
|
|
247
|
+
assert.isLength(indexes, 1, 'getUniqueIndexes() did not return the unique index I tried to create!');
|
|
248
|
+
assert.isLength(indexes[0], 1, 'getUniqueIndexes() needs to return an array of arrays. Each item in the array should be an array of fields that make up the unique index.');
|
|
249
|
+
assert.isEqual(indexes[0][0].toLowerCase(), 'uniqueField'.toLowerCase(), 'getUniqueIndexes() did not add the expected field to the first unique index.');
|
|
126
250
|
yield db.createUniqueIndex(this.collectionName, ['uniqueField2']);
|
|
127
251
|
indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
128
252
|
assert.isLength(indexes, 2);
|
|
129
|
-
assert.isEqual(indexes[1][0], 'uniqueField2');
|
|
253
|
+
assert.isEqual(indexes[1][0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
|
130
254
|
yield db.createUniqueIndex(this.collectionName, [
|
|
131
255
|
'uniqueField3',
|
|
132
256
|
'uniqueField4',
|
|
133
257
|
]);
|
|
134
258
|
indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
135
259
|
assert.isLength(indexes, 3);
|
|
136
|
-
assert.isEqual(indexes[2][0], 'uniqueField3');
|
|
137
|
-
assert.isEqual(indexes[2][1], 'uniqueField4');
|
|
260
|
+
assert.isEqual(indexes[2][0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
|
261
|
+
assert.isEqual(indexes[2][1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
|
138
262
|
yield this.shutdown(db);
|
|
139
263
|
});
|
|
140
264
|
},
|
|
141
265
|
assertHasNoUniqueIndexToStart(connect) {
|
|
142
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
const db = yield connect
|
|
267
|
+
const db = yield connectToDabatase(connect);
|
|
144
268
|
const indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
145
|
-
assert.isLength(indexes, 0);
|
|
269
|
+
assert.isLength(indexes, 0, "getUniqueIndexes() should return an empty array when there are no unique indexes (primary key indexes don't count!). Also, make sure that dropDatabase() in your adapter clears out any unique indexes you've created.");
|
|
146
270
|
yield this.shutdown(db);
|
|
147
271
|
});
|
|
148
272
|
},
|
|
149
|
-
|
|
273
|
+
assertCanUpsertOne(connect) {
|
|
150
274
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const db = yield connect
|
|
275
|
+
const db = yield connectToDabatase(connect);
|
|
152
276
|
const id = db.generateId();
|
|
153
277
|
const created = yield db.upsertOne(this.collectionName, { id }, {
|
|
154
278
|
id,
|
|
155
279
|
name: 'first',
|
|
156
280
|
});
|
|
157
|
-
assert.isTruthy(created);
|
|
281
|
+
assert.isTruthy(created, 'upsertOne() should return the record it created!');
|
|
158
282
|
assert.isEqual(created.name, 'first');
|
|
159
|
-
assert.isEqual(created.id
|
|
283
|
+
assert.isEqual(`${created.id}`, `${id}`, 'ids do not match!');
|
|
160
284
|
const upserted = yield db.upsertOne(this.collectionName, { id }, { name: 'second' });
|
|
161
|
-
|
|
285
|
+
const id2 = db.generateId();
|
|
286
|
+
yield db.upsertOne(this.collectionName, { id: id2 }, { name: 'second', id: id2 });
|
|
162
287
|
assert.isTruthy(upserted);
|
|
163
288
|
assert.isEqual(created.id, upserted.id);
|
|
164
289
|
assert.isEqual(upserted.name, 'second');
|
|
165
290
|
const upserted2 = yield db.upsertOne(this.collectionName, { id }, { name: 'third' });
|
|
166
291
|
assert.isTruthy(upserted2);
|
|
167
292
|
assert.isEqual(upserted2.name, 'third');
|
|
293
|
+
const match = yield db.findOne(this.collectionName, { id });
|
|
294
|
+
assert.isEqualDeep(match, upserted2, 'upsertOne() did not update the record!');
|
|
168
295
|
yield this.shutdown(db);
|
|
169
296
|
});
|
|
170
297
|
},
|
|
171
298
|
assertCanDeleteOne(connect) {
|
|
172
299
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
const db = yield connect
|
|
300
|
+
const db = yield connectToDabatase(connect);
|
|
174
301
|
yield db.create(this.collectionName, [
|
|
175
302
|
{
|
|
176
303
|
name: 'a record',
|
|
@@ -184,13 +311,13 @@ const databaseAssertUtil = {
|
|
|
184
311
|
]);
|
|
185
312
|
yield db.deleteOne(this.collectionName, { name: 'a record' });
|
|
186
313
|
const count = yield db.count(this.collectionName);
|
|
187
|
-
assert.isEqual(count, 2);
|
|
314
|
+
assert.isEqual(count, 2, 'deleteOne() did not delete a single record!');
|
|
188
315
|
yield this.shutdown(db);
|
|
189
316
|
});
|
|
190
317
|
},
|
|
191
318
|
assertCanDeleteRecord(connect) {
|
|
192
319
|
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
const db = yield connect
|
|
320
|
+
const db = yield connectToDabatase(connect);
|
|
194
321
|
const created = yield db.createOne(this.collectionName, {
|
|
195
322
|
id: db.generateId(),
|
|
196
323
|
name: 'first',
|
|
@@ -207,7 +334,7 @@ const databaseAssertUtil = {
|
|
|
207
334
|
const matchedAfterDelete = yield db.findOne(this.collectionName, {
|
|
208
335
|
id: created.id,
|
|
209
336
|
});
|
|
210
|
-
assert.isFalsy(matchedAfterDelete);
|
|
337
|
+
assert.isFalsy(matchedAfterDelete, `Record with the id of ${created.id} was not deleted!`);
|
|
211
338
|
yield db.create(this.collectionName, [
|
|
212
339
|
{
|
|
213
340
|
name: 'a record',
|
|
@@ -220,13 +347,13 @@ const databaseAssertUtil = {
|
|
|
220
347
|
},
|
|
221
348
|
]);
|
|
222
349
|
const manyDeleted = yield db.delete(this.collectionName, {});
|
|
223
|
-
assert.isEqual(manyDeleted, 3);
|
|
350
|
+
assert.isEqual(manyDeleted, 3, `delete() did not return the total recrods deleted!`);
|
|
224
351
|
yield this.shutdown(db);
|
|
225
352
|
});
|
|
226
353
|
},
|
|
227
354
|
assertCanLimitResultsToZero(connect) {
|
|
228
355
|
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
-
const db = yield connect
|
|
356
|
+
const db = yield connectToDabatase(connect);
|
|
230
357
|
yield db.createOne(this.collectionName, {
|
|
231
358
|
id: db.generateId(),
|
|
232
359
|
name: 'first',
|
|
@@ -249,7 +376,7 @@ const databaseAssertUtil = {
|
|
|
249
376
|
},
|
|
250
377
|
assertCanLimitResults(connect) {
|
|
251
378
|
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
-
const db = yield connect
|
|
379
|
+
const db = yield connectToDabatase(connect);
|
|
253
380
|
yield db.createOne(this.collectionName, {
|
|
254
381
|
id: db.generateId(),
|
|
255
382
|
name: 'first',
|
|
@@ -274,7 +401,7 @@ const databaseAssertUtil = {
|
|
|
274
401
|
},
|
|
275
402
|
assertFindOneOnEmptyDatabaseReturnsNull(connect) {
|
|
276
403
|
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
-
const db = yield connect
|
|
404
|
+
const db = yield connectToDabatase(connect);
|
|
278
405
|
const results = yield db.findOne(this.collectionName, { id: '111' });
|
|
279
406
|
assert.isFalsy(results);
|
|
280
407
|
yield this.shutdown(db);
|
|
@@ -282,7 +409,7 @@ const databaseAssertUtil = {
|
|
|
282
409
|
},
|
|
283
410
|
assertEmptyDatabaseReturnsEmptyArray(connect) {
|
|
284
411
|
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
const db = yield connect
|
|
412
|
+
const db = yield connectToDabatase(connect);
|
|
286
413
|
const results = yield db.find(this.collectionName, { id: '111' });
|
|
287
414
|
assert.isLength(results, 0);
|
|
288
415
|
yield this.shutdown(db);
|
|
@@ -290,9 +417,10 @@ const databaseAssertUtil = {
|
|
|
290
417
|
},
|
|
291
418
|
assertCanPushOntoArrayValue(connect) {
|
|
292
419
|
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
const db = yield connect
|
|
420
|
+
const db = yield connectToDabatase(connect);
|
|
294
421
|
const inserted = yield db.createOne(this.collectionName, {
|
|
295
422
|
id: db.generateId(),
|
|
423
|
+
name: 'nope',
|
|
296
424
|
names: ['first'],
|
|
297
425
|
});
|
|
298
426
|
const updated = yield db.updateOne(this.collectionName, { id: inserted.id }, {
|
|
@@ -305,14 +433,79 @@ const databaseAssertUtil = {
|
|
|
305
433
|
yield this.shutdown(db);
|
|
306
434
|
});
|
|
307
435
|
},
|
|
436
|
+
assertCanCreateWithObjectField(connect) {
|
|
437
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
438
|
+
const db = yield connectToDabatase(connect);
|
|
439
|
+
const values = {
|
|
440
|
+
name: 'first',
|
|
441
|
+
target: {
|
|
442
|
+
organizationId: generateId(),
|
|
443
|
+
locationId: generateId(),
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
let created;
|
|
447
|
+
try {
|
|
448
|
+
created = yield db.createOne(this.collectionName, values);
|
|
449
|
+
}
|
|
450
|
+
catch (_a) {
|
|
451
|
+
assert.fail('createOne() tried to create a record with an object field. Make sure the target field handles objects!');
|
|
452
|
+
}
|
|
453
|
+
const matched = yield db.findOne(this.collectionName, { id: created.id });
|
|
454
|
+
assert.isEqualDeep(matched, Object.assign(Object.assign({}, created), { id: matched.id }));
|
|
455
|
+
yield this.shutdown(db);
|
|
456
|
+
});
|
|
457
|
+
},
|
|
458
|
+
canUpdateWithObjectField(connect) {
|
|
459
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
460
|
+
const db = yield connectToDabatase(connect);
|
|
461
|
+
const values = {
|
|
462
|
+
name: 'first',
|
|
463
|
+
target: {
|
|
464
|
+
organizationId: generateId(),
|
|
465
|
+
locationId: generateId(),
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
const created = yield db.createOne(this.collectionName, values);
|
|
469
|
+
const target = {
|
|
470
|
+
organizationId: 'hey',
|
|
471
|
+
locationId: 'there',
|
|
472
|
+
};
|
|
473
|
+
yield db.updateOne(this.collectionName, { id: created.id }, {
|
|
474
|
+
target,
|
|
475
|
+
});
|
|
476
|
+
const matched = yield db.findOne(this.collectionName, { id: created.id });
|
|
477
|
+
assert.isEqualDeep(matched.target, target);
|
|
478
|
+
yield this.shutdown(db);
|
|
479
|
+
});
|
|
480
|
+
},
|
|
481
|
+
canUpdateFieldInObjectFieldWithTargettedWhere(connect) {
|
|
482
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
483
|
+
const db = yield connectToDabatase(connect);
|
|
484
|
+
const target = {
|
|
485
|
+
organizationId: generateId(),
|
|
486
|
+
locationId: generateId(),
|
|
487
|
+
};
|
|
488
|
+
const values = {
|
|
489
|
+
name: 'first',
|
|
490
|
+
target,
|
|
491
|
+
};
|
|
492
|
+
const created = yield db.createOne(this.collectionName, values);
|
|
493
|
+
yield db.updateOne(this.collectionName, { id: created.id }, {
|
|
494
|
+
'target.organizationId': 'oy oy',
|
|
495
|
+
});
|
|
496
|
+
const matched = yield db.findOne(this.collectionName, { id: created.id });
|
|
497
|
+
assert.isEqualDeep(matched.target, Object.assign(Object.assign({}, target), { organizationId: 'oy oy' }));
|
|
498
|
+
yield this.shutdown(db);
|
|
499
|
+
});
|
|
500
|
+
},
|
|
308
501
|
assertCanCreateMany(connect) {
|
|
309
502
|
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
-
const db = yield connect
|
|
503
|
+
const db = yield connectToDabatase(connect);
|
|
311
504
|
const values = [
|
|
312
|
-
{
|
|
313
|
-
{
|
|
314
|
-
{
|
|
315
|
-
{
|
|
505
|
+
{ name: 'ry' },
|
|
506
|
+
{ name: 'tay' },
|
|
507
|
+
{ name: 'bill' },
|
|
508
|
+
{ name: 'bob' },
|
|
316
509
|
];
|
|
317
510
|
const results = yield db.create(this.collectionName, values);
|
|
318
511
|
assert.isLength(results, values.length);
|
|
@@ -324,7 +517,7 @@ const databaseAssertUtil = {
|
|
|
324
517
|
},
|
|
325
518
|
assertCanUpdateMany(connect) {
|
|
326
519
|
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
-
const db = yield connect
|
|
520
|
+
const db = yield connectToDabatase(connect);
|
|
328
521
|
yield db.create(this.collectionName, [
|
|
329
522
|
{
|
|
330
523
|
name: 'one',
|
|
@@ -346,37 +539,38 @@ const databaseAssertUtil = {
|
|
|
346
539
|
},
|
|
347
540
|
assertCanQueryWithOr(connect) {
|
|
348
541
|
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
-
const db = yield connect
|
|
350
|
-
const
|
|
351
|
-
const
|
|
542
|
+
const db = yield connectToDabatase(connect);
|
|
543
|
+
const name1 = generateId();
|
|
544
|
+
const name2 = generateId();
|
|
545
|
+
assert.isFunction(db.create, 'db.create() must be a function that creates records and returns it.');
|
|
352
546
|
yield db.create(this.collectionName, [
|
|
353
547
|
{
|
|
354
548
|
isPublic: true,
|
|
355
|
-
|
|
549
|
+
name: name1,
|
|
356
550
|
},
|
|
357
551
|
{
|
|
358
|
-
|
|
552
|
+
name: name2,
|
|
359
553
|
},
|
|
360
554
|
]);
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
});
|
|
364
|
-
assert.isLength(matches, 2);
|
|
555
|
+
yield this._assert$orReturnsExpectedTotalRecords(db, [{ isPublic: true }, { name: name2 }], 2);
|
|
556
|
+
yield this._assert$orReturnsExpectedTotalRecords(db, [{ isPublic: true }], 1);
|
|
365
557
|
yield this.shutdown(db);
|
|
366
558
|
});
|
|
367
559
|
},
|
|
368
560
|
assertCanUpdate(connect) {
|
|
369
561
|
return __awaiter(this, void 0, void 0, function* () {
|
|
370
|
-
const db = yield connect
|
|
562
|
+
const db = yield connectToDabatase(connect);
|
|
371
563
|
const inserted = yield db.createOne(this.collectionName, {
|
|
372
564
|
id: db.generateId(),
|
|
373
565
|
name: 'first',
|
|
374
566
|
});
|
|
375
|
-
assert.
|
|
376
|
-
assert.
|
|
567
|
+
assert.isTruthy(inserted, 'createOne needs to return the record that was inserted!');
|
|
568
|
+
assert.isTruthy(inserted.id, `an id must be return with the record from createOne!`);
|
|
569
|
+
assert.isEqual(inserted.name, 'first', 'name did not set as expected on the inserted record');
|
|
377
570
|
const updated = yield db.updateOne(this.collectionName, { id: inserted.id }, {
|
|
378
571
|
name: 'updated',
|
|
379
572
|
});
|
|
573
|
+
assert.isTruthy(updated, `updateOne needs to return the record that was updated!`);
|
|
380
574
|
assert.isEqual(updated.id, inserted.id);
|
|
381
575
|
assert.isEqual(updated.name, 'updated');
|
|
382
576
|
yield this.shutdown(db);
|
|
@@ -384,7 +578,7 @@ const databaseAssertUtil = {
|
|
|
384
578
|
},
|
|
385
579
|
assertCanSortById(connect) {
|
|
386
580
|
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
-
const db = yield connect
|
|
581
|
+
const db = yield connectToDabatase(connect);
|
|
388
582
|
yield db.createOne(this.collectionName, {
|
|
389
583
|
id: db.generateId(),
|
|
390
584
|
name: 'first',
|
|
@@ -418,26 +612,33 @@ const databaseAssertUtil = {
|
|
|
418
612
|
},
|
|
419
613
|
assertCanCreateMultiFieldUniqueIndex(connect) {
|
|
420
614
|
return __awaiter(this, void 0, void 0, function* () {
|
|
421
|
-
const db = yield connect
|
|
615
|
+
const db = yield connectToDabatase(connect);
|
|
422
616
|
yield db.createUniqueIndex(this.collectionName, [
|
|
423
617
|
'uniqueField',
|
|
424
618
|
'uniqueField2',
|
|
425
619
|
]);
|
|
426
620
|
yield db.createOne(this.collectionName, {
|
|
621
|
+
name: generateId(),
|
|
427
622
|
uniqueField: 'hello world',
|
|
428
623
|
uniqueField2: 'hello again',
|
|
429
624
|
});
|
|
430
625
|
yield db.createOne(this.collectionName, {
|
|
626
|
+
name: generateId(),
|
|
431
627
|
uniqueField: 'hello world',
|
|
432
628
|
uniqueField2: 'unique',
|
|
433
629
|
});
|
|
434
630
|
let err = (yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
|
631
|
+
name: generateId(),
|
|
435
632
|
uniqueField: 'hello world',
|
|
436
633
|
uniqueField2: 'unique',
|
|
437
|
-
})));
|
|
634
|
+
}), undefined, `createOne() should throw a SpruceError with the code: DUPLICATE_RECORD`));
|
|
635
|
+
lowerCaseErrorDuplicateFields(err);
|
|
438
636
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
439
637
|
collectionName: this.collectionName,
|
|
440
|
-
duplicateFields: [
|
|
638
|
+
duplicateFields: [
|
|
639
|
+
'uniqueField'.toLowerCase(),
|
|
640
|
+
'uniqueField2'.toLowerCase(),
|
|
641
|
+
],
|
|
441
642
|
duplicateValues: ['hello world', 'unique'],
|
|
442
643
|
action: 'create',
|
|
443
644
|
});
|
|
@@ -445,6 +646,7 @@ const databaseAssertUtil = {
|
|
|
445
646
|
uniqueField: 'hello world',
|
|
446
647
|
uniqueField2: 'unique',
|
|
447
648
|
}, {
|
|
649
|
+
name: generateId(),
|
|
448
650
|
uniqueField: 'hello world',
|
|
449
651
|
uniqueField2: 'unique2',
|
|
450
652
|
});
|
|
@@ -452,12 +654,17 @@ const databaseAssertUtil = {
|
|
|
452
654
|
uniqueField: 'hello world',
|
|
453
655
|
uniqueField2: 'unique2',
|
|
454
656
|
}, {
|
|
657
|
+
name: generateId(),
|
|
455
658
|
uniqueField: 'hello world',
|
|
456
659
|
uniqueField2: 'hello again',
|
|
457
|
-
})));
|
|
660
|
+
}), undefined, 'upsertOne() should throw a SpruceError with the code: DUPLICATE_RECORD'));
|
|
661
|
+
lowerCaseErrorDuplicateFields(err);
|
|
458
662
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
459
663
|
collectionName: this.collectionName,
|
|
460
|
-
duplicateFields: [
|
|
664
|
+
duplicateFields: [
|
|
665
|
+
'uniqueField'.toLowerCase(),
|
|
666
|
+
'uniqueField2'.toLowerCase(),
|
|
667
|
+
],
|
|
461
668
|
duplicateValues: ['hello world', 'hello again'],
|
|
462
669
|
action: 'upsertOne',
|
|
463
670
|
});
|
|
@@ -466,37 +673,47 @@ const databaseAssertUtil = {
|
|
|
466
673
|
},
|
|
467
674
|
assertSettingUniqueIndexViolationThrowsSpruceError(connect) {
|
|
468
675
|
return __awaiter(this, void 0, void 0, function* () {
|
|
469
|
-
const db = yield connect
|
|
676
|
+
const db = yield connectToDabatase(connect);
|
|
470
677
|
yield db.createUniqueIndex(this.collectionName, ['randomUniqueField']);
|
|
471
678
|
yield db.createOne(this.collectionName, {
|
|
472
679
|
uniqueField: 'hello world',
|
|
473
680
|
randomUniqueField: '1',
|
|
681
|
+
name: generateId(),
|
|
474
682
|
});
|
|
475
683
|
yield db.createOne(this.collectionName, {
|
|
476
684
|
uniqueField: 'hello world',
|
|
477
685
|
randomUniqueField: '2',
|
|
686
|
+
name: generateId(),
|
|
478
687
|
});
|
|
479
688
|
let err = yield assert.doesThrowAsync(() => db.syncUniqueIndexes(this.collectionName, [['uniqueField']]));
|
|
480
|
-
assert.isTrue(err instanceof SpruceError);
|
|
481
689
|
errorAssert.assertError(err, 'DUPLICATE_KEY');
|
|
482
690
|
yield this.shutdown(db);
|
|
483
691
|
});
|
|
484
692
|
},
|
|
485
693
|
assertDuplicateKeyThrowsOnInsert(connect) {
|
|
486
694
|
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
-
const db = yield connect
|
|
695
|
+
const db = yield connectToDabatase(connect);
|
|
488
696
|
yield db.createUniqueIndex(this.collectionName, ['uniqueField']);
|
|
489
697
|
yield db.createOne(this.collectionName, {
|
|
490
698
|
uniqueField: 'hello world',
|
|
699
|
+
name: generateId(),
|
|
700
|
+
});
|
|
701
|
+
let err = yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
|
702
|
+
uniqueField: 'hello world',
|
|
703
|
+
name: generateId(),
|
|
704
|
+
}));
|
|
705
|
+
lowerCaseErrorDuplicateFields(err);
|
|
706
|
+
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
707
|
+
duplicateFields: ['uniquefield'],
|
|
708
|
+
duplicateValues: ['hello world'],
|
|
709
|
+
collectionName: this.collectionName,
|
|
491
710
|
});
|
|
492
|
-
let err = yield assert.doesThrowAsync(() => db.createOne(this.collectionName, { uniqueField: 'hello world' }));
|
|
493
|
-
assert.isTrue(err instanceof SpruceError);
|
|
494
711
|
yield this.shutdown(db);
|
|
495
712
|
});
|
|
496
713
|
},
|
|
497
714
|
assertSyncingIndexesDoesNotAddAndRemove(connect) {
|
|
498
715
|
return __awaiter(this, void 0, void 0, function* () {
|
|
499
|
-
const db = yield connect
|
|
716
|
+
const db = yield connectToDabatase(connect);
|
|
500
717
|
yield db.createUniqueIndex(this.collectionName, ['otherField']);
|
|
501
718
|
yield db.createUniqueIndex(this.collectionName, ['someField']);
|
|
502
719
|
db.createUniqueIndex = () => {
|
|
@@ -514,24 +731,24 @@ const databaseAssertUtil = {
|
|
|
514
731
|
},
|
|
515
732
|
assertSyncingUniqueIndexesRemovesExtraIndexes(connect) {
|
|
516
733
|
return __awaiter(this, void 0, void 0, function* () {
|
|
517
|
-
const db = yield connect
|
|
734
|
+
const db = yield connectToDabatase(connect);
|
|
518
735
|
yield db.syncUniqueIndexes(this.collectionName, [
|
|
519
736
|
['uniqueField'],
|
|
520
737
|
['someField'],
|
|
521
738
|
['otherField', 'otherField2'],
|
|
522
739
|
]);
|
|
523
740
|
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
524
|
-
assert.isLength(indexes, 3);
|
|
741
|
+
assert.isLength(indexes, 3, 'syncUniqueIndexes() should have created 3 indexes.');
|
|
525
742
|
yield db.syncUniqueIndexes(this.collectionName, [['uniqueField']]);
|
|
526
743
|
indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
527
744
|
assert.isLength(indexes, 1);
|
|
528
|
-
assert.isEqual(indexes[0][0], '
|
|
745
|
+
assert.isEqual(indexes[0][0].toLowerCase(), 'uniquefield');
|
|
529
746
|
yield this.shutdown(db);
|
|
530
747
|
});
|
|
531
748
|
},
|
|
532
749
|
assertSyncingUniqueIndexsSkipsExistingIndexs(connect) {
|
|
533
750
|
return __awaiter(this, void 0, void 0, function* () {
|
|
534
|
-
const db = yield connect
|
|
751
|
+
const db = yield connectToDabatase(connect);
|
|
535
752
|
yield db.syncUniqueIndexes(this.collectionName, [['uniqueField']]);
|
|
536
753
|
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
537
754
|
assert.isLength(indexes, 1);
|
|
@@ -547,54 +764,66 @@ const databaseAssertUtil = {
|
|
|
547
764
|
},
|
|
548
765
|
assertSyncingUniqueIndexsAddsMissingIndexes(connect) {
|
|
549
766
|
return __awaiter(this, void 0, void 0, function* () {
|
|
550
|
-
const db = yield connect
|
|
767
|
+
const db = yield connectToDabatase(connect);
|
|
551
768
|
yield db.syncUniqueIndexes(this.collectionName, [['uniqueField']]);
|
|
552
769
|
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
553
|
-
assert.isLength(indexes, 1);
|
|
770
|
+
assert.isLength(indexes, 1, 'There should be 1 index after syncing.');
|
|
554
771
|
yield db.syncUniqueIndexes(this.collectionName, [['someField']]);
|
|
555
772
|
indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
556
|
-
assert.isLength(indexes, 1);
|
|
773
|
+
assert.isLength(indexes, 1, 'There should now be 2 indexes after syncing.');
|
|
557
774
|
yield db.syncUniqueIndexes(this.collectionName, [
|
|
558
775
|
['uniqueField'],
|
|
559
776
|
['someField'],
|
|
560
777
|
]);
|
|
561
778
|
indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
562
|
-
assert.isLength(indexes, 2);
|
|
779
|
+
assert.isLength(indexes, 2, 'There should still be 2 indexes after syncing.');
|
|
563
780
|
yield this.shutdown(db);
|
|
564
781
|
});
|
|
565
782
|
},
|
|
566
783
|
assertCantDropCompoundUniqueIndexThatDoesntExist(connect) {
|
|
567
784
|
return __awaiter(this, void 0, void 0, function* () {
|
|
568
|
-
const db = yield connect
|
|
785
|
+
const db = yield connectToDabatase(connect);
|
|
569
786
|
yield db.createUniqueIndex(this.collectionName, [
|
|
570
787
|
'someField',
|
|
571
788
|
'someOtherField',
|
|
572
789
|
]);
|
|
573
790
|
const err = yield assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['uniqueField', 'someOtherField']));
|
|
574
|
-
|
|
791
|
+
lowerCaseMissingIndexValues(err);
|
|
792
|
+
errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
|
793
|
+
collectionName: this.collectionName,
|
|
794
|
+
missingIndex: ['uniquefield', 'someotherfield'],
|
|
795
|
+
});
|
|
575
796
|
yield this.shutdown(db);
|
|
576
797
|
});
|
|
577
798
|
},
|
|
578
799
|
assertCantDropIndexWhenNoIndexExists(connect) {
|
|
579
800
|
return __awaiter(this, void 0, void 0, function* () {
|
|
580
|
-
const db = yield connect
|
|
801
|
+
const db = yield connectToDabatase(connect);
|
|
581
802
|
const err = yield assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['someOtherField']));
|
|
582
|
-
|
|
803
|
+
lowerCaseMissingIndexValues(err);
|
|
804
|
+
errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
|
805
|
+
collectionName: this.collectionName,
|
|
806
|
+
missingIndex: ['someotherfield'],
|
|
807
|
+
});
|
|
583
808
|
yield this.shutdown(db);
|
|
584
809
|
});
|
|
585
810
|
},
|
|
586
811
|
assertCantDropUniqueIndexThatDoesntExist(connect) {
|
|
587
812
|
return __awaiter(this, void 0, void 0, function* () {
|
|
588
|
-
const db = yield connect
|
|
813
|
+
const db = yield connectToDabatase(connect);
|
|
589
814
|
yield db.createUniqueIndex(this.collectionName, ['someField']);
|
|
590
815
|
const err = yield assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['someOtherField']));
|
|
591
|
-
|
|
816
|
+
lowerCaseMissingIndexValues(err);
|
|
817
|
+
errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
|
818
|
+
collectionName: this.collectionName,
|
|
819
|
+
missingIndex: ['someotherfield'],
|
|
820
|
+
});
|
|
592
821
|
yield this.shutdown(db);
|
|
593
822
|
});
|
|
594
823
|
},
|
|
595
824
|
assertCanDropCompoundUniqueIndex(connect) {
|
|
596
825
|
return __awaiter(this, void 0, void 0, function* () {
|
|
597
|
-
const db = yield connect
|
|
826
|
+
const db = yield connectToDabatase(connect);
|
|
598
827
|
yield db.createUniqueIndex(this.collectionName, ['someField', 'otherField']);
|
|
599
828
|
yield db.dropIndex(this.collectionName, ['someField', 'otherField']);
|
|
600
829
|
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
@@ -609,11 +838,11 @@ const databaseAssertUtil = {
|
|
|
609
838
|
},
|
|
610
839
|
assertCanDropUniqueIndex(connect) {
|
|
611
840
|
return __awaiter(this, void 0, void 0, function* () {
|
|
612
|
-
const db = yield connect
|
|
841
|
+
const db = yield connectToDabatase(connect);
|
|
613
842
|
yield db.createUniqueIndex(this.collectionName, ['someField']);
|
|
614
843
|
yield db.dropIndex(this.collectionName, ['someField']);
|
|
615
844
|
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
616
|
-
assert.isLength(indexes, 0);
|
|
845
|
+
assert.isLength(indexes, 0, 'getUniqueIndexes() still returned an index even though it should not have after dropIndex().');
|
|
617
846
|
yield db.createUniqueIndex(this.collectionName, ['someField2']);
|
|
618
847
|
yield db.createUniqueIndex(this.collectionName, ['someField3']);
|
|
619
848
|
yield db.dropIndex(this.collectionName, ['someField3']);
|
|
@@ -624,18 +853,14 @@ const databaseAssertUtil = {
|
|
|
624
853
|
},
|
|
625
854
|
assertCantCreateUniqueIndexTwice(connect) {
|
|
626
855
|
return __awaiter(this, void 0, void 0, function* () {
|
|
627
|
-
const db = yield connect
|
|
628
|
-
yield db
|
|
629
|
-
let indexes = yield db.getUniqueIndexes(this.collectionName);
|
|
630
|
-
assert.isLength(indexes, 1);
|
|
631
|
-
const err = yield assert.doesThrowAsync(() => db.createUniqueIndex(this.collectionName, ['uniqueField']));
|
|
632
|
-
errorAssert.assertError(err, 'INDEX_EXISTS');
|
|
856
|
+
const db = yield connectToDabatase(connect);
|
|
857
|
+
yield assertCantCreateUniqueIndexTwice(db, this.collectionName, ['uniqueField'], 1);
|
|
633
858
|
yield this.shutdown(db);
|
|
634
859
|
});
|
|
635
860
|
},
|
|
636
861
|
assertSyncingUniqueIndexesIsRaceProof(connect) {
|
|
637
862
|
return __awaiter(this, void 0, void 0, function* () {
|
|
638
|
-
const db = yield connect
|
|
863
|
+
const db = yield connectToDabatase(connect);
|
|
639
864
|
const syncs = [
|
|
640
865
|
db.syncUniqueIndexes(this.collectionName, [
|
|
641
866
|
['otherField', 'otherField2'],
|
|
@@ -674,25 +899,32 @@ const databaseAssertUtil = {
|
|
|
674
899
|
},
|
|
675
900
|
assertUniqueIndexBlocksDuplicates(connect) {
|
|
676
901
|
return __awaiter(this, void 0, void 0, function* () {
|
|
677
|
-
const db = yield connect
|
|
902
|
+
const db = yield connectToDabatase(connect);
|
|
678
903
|
yield db.createUniqueIndex(this.collectionName, ['uniqueField']);
|
|
679
904
|
yield db.createOne(this.collectionName, {
|
|
680
905
|
uniqueField: 'hello world',
|
|
906
|
+
name: 'hello world',
|
|
681
907
|
});
|
|
682
|
-
let err = (yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
|
908
|
+
let err = (yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
|
909
|
+
uniqueField: 'hello world',
|
|
910
|
+
name: 'hello world',
|
|
911
|
+
})));
|
|
912
|
+
lowerCaseStringArray(err, 'duplicateFields');
|
|
683
913
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
684
914
|
collectionName: this.collectionName,
|
|
685
|
-
duplicateFields: ['
|
|
915
|
+
duplicateFields: ['uniquefield'],
|
|
686
916
|
duplicateValues: ['hello world'],
|
|
687
917
|
action: 'create',
|
|
688
918
|
});
|
|
689
919
|
const created = yield db.createOne(this.collectionName, {
|
|
690
920
|
uniqueField: 'pass',
|
|
921
|
+
name: 'hello world',
|
|
691
922
|
});
|
|
692
923
|
err = (yield assert.doesThrowAsync(() => db.updateOne(this.collectionName, { id: created.id }, { uniqueField: 'hello world' })));
|
|
924
|
+
lowerCaseStringArray(err, 'duplicateFields');
|
|
693
925
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
694
926
|
collectionName: this.collectionName,
|
|
695
|
-
duplicateFields: ['
|
|
927
|
+
duplicateFields: ['uniquefield'],
|
|
696
928
|
duplicateValues: ['hello world'],
|
|
697
929
|
action: 'updateOne',
|
|
698
930
|
});
|
|
@@ -700,17 +932,20 @@ const databaseAssertUtil = {
|
|
|
700
932
|
for (let c = 0; c <= 10; c++) {
|
|
701
933
|
promises.push(db.createOne(this.collectionName, {
|
|
702
934
|
uniqueField: 'fast',
|
|
935
|
+
name: 'hello world',
|
|
703
936
|
}));
|
|
704
937
|
}
|
|
705
938
|
err = (yield assert.doesThrowAsync(() => Promise.all(promises)));
|
|
939
|
+
lowerCaseStringArray(err, 'duplicateFields');
|
|
706
940
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
707
|
-
duplicateFields: ['
|
|
941
|
+
duplicateFields: ['uniquefield'],
|
|
708
942
|
duplicateValues: ['fast'],
|
|
709
943
|
});
|
|
710
944
|
promises = [];
|
|
711
945
|
for (let c = 0; c <= 10; c++) {
|
|
712
946
|
promises.push(db.upsertOne(this.collectionName, { uniqueField: `${c}` }, {
|
|
713
947
|
uniqueField: 'upsertFast',
|
|
948
|
+
name: 'hello world',
|
|
714
949
|
}));
|
|
715
950
|
}
|
|
716
951
|
err = (yield assert.doesThrowAsync(() => Promise.all(promises)));
|
|
@@ -719,13 +954,21 @@ const databaseAssertUtil = {
|
|
|
719
954
|
});
|
|
720
955
|
},
|
|
721
956
|
assertCanCreateUniqueIndexOnNestedField(connect) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
yield
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
957
|
+
var _a;
|
|
958
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
959
|
+
const db = yield connectToDabatase(connect);
|
|
960
|
+
try {
|
|
961
|
+
yield db.createUniqueIndex(this.collectionName, [
|
|
962
|
+
'target.organizationId',
|
|
963
|
+
'slug',
|
|
964
|
+
]);
|
|
965
|
+
}
|
|
966
|
+
catch (err) {
|
|
967
|
+
assert.fail((_a = `Trying to create a unique index on target.organizationId and slug failed.\n\n` +
|
|
968
|
+
err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
969
|
+
}
|
|
728
970
|
yield db.createOne(this.collectionName, {
|
|
971
|
+
name: generateId(),
|
|
729
972
|
target: {
|
|
730
973
|
organizationId: 'go!',
|
|
731
974
|
locationId: null,
|
|
@@ -733,6 +976,7 @@ const databaseAssertUtil = {
|
|
|
733
976
|
slug: 'a slug',
|
|
734
977
|
});
|
|
735
978
|
const err = yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
|
979
|
+
name: generateId(),
|
|
736
980
|
target: {
|
|
737
981
|
organizationId: 'go!',
|
|
738
982
|
locationId: null,
|
|
@@ -750,6 +994,7 @@ const databaseAssertUtil = {
|
|
|
750
994
|
organizationId: 'go!',
|
|
751
995
|
},
|
|
752
996
|
}, {
|
|
997
|
+
name: 'test',
|
|
753
998
|
target: {
|
|
754
999
|
organizationId: 'go 2!',
|
|
755
1000
|
locationId: null,
|
|
@@ -761,8 +1006,11 @@ const databaseAssertUtil = {
|
|
|
761
1006
|
},
|
|
762
1007
|
assertCanPushToArrayOnUpsert(connect) {
|
|
763
1008
|
return __awaiter(this, void 0, void 0, function* () {
|
|
764
|
-
const db = yield connect
|
|
765
|
-
const record = yield db.createOne(this.collectionName, {
|
|
1009
|
+
const db = yield connectToDabatase(connect);
|
|
1010
|
+
const record = yield db.createOne(this.collectionName, {
|
|
1011
|
+
name: 'test',
|
|
1012
|
+
names: [],
|
|
1013
|
+
});
|
|
766
1014
|
yield db.updateOne(this.collectionName, {
|
|
767
1015
|
id: record.id,
|
|
768
1016
|
}, {
|
|
@@ -775,23 +1023,23 @@ const databaseAssertUtil = {
|
|
|
775
1023
|
},
|
|
776
1024
|
assertCanSearchByRegex(connect) {
|
|
777
1025
|
return __awaiter(this, void 0, void 0, function* () {
|
|
778
|
-
const db = yield connect
|
|
1026
|
+
const db = yield connectToDabatase(connect);
|
|
779
1027
|
yield db.create(this.collectionName, [
|
|
780
1028
|
{
|
|
781
1029
|
name: 'first',
|
|
782
|
-
|
|
1030
|
+
target: {
|
|
783
1031
|
score: 1,
|
|
784
1032
|
},
|
|
785
1033
|
},
|
|
786
1034
|
{
|
|
787
1035
|
name: 'second',
|
|
788
|
-
|
|
1036
|
+
target: {
|
|
789
1037
|
score: 2,
|
|
790
1038
|
},
|
|
791
1039
|
},
|
|
792
1040
|
{
|
|
793
1041
|
name: 'third',
|
|
794
|
-
|
|
1042
|
+
target: {
|
|
795
1043
|
score: 2,
|
|
796
1044
|
},
|
|
797
1045
|
},
|
|
@@ -801,29 +1049,29 @@ const databaseAssertUtil = {
|
|
|
801
1049
|
{
|
|
802
1050
|
name: 'first',
|
|
803
1051
|
},
|
|
804
|
-
]);
|
|
1052
|
+
], 'Searching by regex failed.!');
|
|
805
1053
|
yield this.shutdown(db);
|
|
806
1054
|
});
|
|
807
1055
|
},
|
|
808
1056
|
assertCanReturnOnlySelectFields(connect) {
|
|
809
1057
|
return __awaiter(this, void 0, void 0, function* () {
|
|
810
|
-
const db = yield connect
|
|
1058
|
+
const db = yield connectToDabatase(connect);
|
|
811
1059
|
yield db.create(this.collectionName, [
|
|
812
1060
|
{
|
|
813
1061
|
name: 'first',
|
|
814
|
-
|
|
1062
|
+
target: {
|
|
815
1063
|
score: 1,
|
|
816
1064
|
},
|
|
817
1065
|
},
|
|
818
1066
|
{
|
|
819
1067
|
name: 'second',
|
|
820
|
-
|
|
1068
|
+
target: {
|
|
821
1069
|
score: 2,
|
|
822
1070
|
},
|
|
823
1071
|
},
|
|
824
1072
|
{
|
|
825
1073
|
name: 'third',
|
|
826
|
-
|
|
1074
|
+
target: {
|
|
827
1075
|
score: 2,
|
|
828
1076
|
},
|
|
829
1077
|
},
|
|
@@ -840,26 +1088,30 @@ const databaseAssertUtil = {
|
|
|
840
1088
|
name: 'third',
|
|
841
1089
|
},
|
|
842
1090
|
]);
|
|
843
|
-
const first = yield db.findOne(this.collectionName, {}, { includeFields: ['
|
|
1091
|
+
const first = yield db.findOne(this.collectionName, {}, { includeFields: ['target'] });
|
|
844
1092
|
assert.isEqualDeep(first, {
|
|
845
|
-
|
|
1093
|
+
target: {
|
|
846
1094
|
score: 1,
|
|
847
1095
|
},
|
|
848
1096
|
});
|
|
849
1097
|
yield this.shutdown(db);
|
|
850
1098
|
});
|
|
851
1099
|
},
|
|
852
|
-
|
|
1100
|
+
assertThrowsWithBadDatabaseName(connect) {
|
|
853
1101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
854
|
-
const
|
|
1102
|
+
const { db, connectionStringWithRandomBadDatabaseName: connectionStringWithRandomBadDatabaseeName, badDatabaseName, } = yield connect();
|
|
1103
|
+
yield this.shutdown(db);
|
|
1104
|
+
const err = yield assert.doesThrowAsync(() => connect(connectionStringWithRandomBadDatabaseeName));
|
|
855
1105
|
errorAssert.assertError(err, 'INVALID_DATABASE_NAME', {
|
|
856
|
-
suppliedName:
|
|
1106
|
+
suppliedName: badDatabaseName,
|
|
857
1107
|
});
|
|
858
1108
|
});
|
|
859
1109
|
},
|
|
860
1110
|
assertThrowsWhenCantConnect(connect) {
|
|
861
1111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
862
|
-
const
|
|
1112
|
+
const { db, scheme } = yield connect();
|
|
1113
|
+
yield this.shutdown(db);
|
|
1114
|
+
const err = yield assert.doesThrowAsync(() => connect(`${scheme}localhost:9999`));
|
|
863
1115
|
errorAssert.assertError(err, 'UNABLE_TO_CONNECT_TO_DB');
|
|
864
1116
|
});
|
|
865
1117
|
},
|
|
@@ -871,101 +1123,107 @@ const databaseAssertUtil = {
|
|
|
871
1123
|
},
|
|
872
1124
|
assertKnowsIfConnectionClosed(connect) {
|
|
873
1125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
874
|
-
const db = yield connect
|
|
875
|
-
assert.
|
|
1126
|
+
const db = yield connectToDabatase(connect);
|
|
1127
|
+
assert.isFunction(db.isConnected, `db.isConnected() needs to be a function!`);
|
|
1128
|
+
assert.isTrue(db.isConnected(), 'isConnected() should return true when connected');
|
|
876
1129
|
yield db.close();
|
|
877
|
-
assert.isFalse(db.isConnected());
|
|
1130
|
+
assert.isFalse(db.isConnected(), 'isConnected() should return false when disconnected (after calling db.close())');
|
|
1131
|
+
yield this.shutdown(db);
|
|
878
1132
|
});
|
|
879
1133
|
},
|
|
880
1134
|
assertCanQueryPathWithDotSyntax(connect) {
|
|
881
1135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
882
|
-
const db = yield connect
|
|
1136
|
+
const db = yield connectToDabatase(connect);
|
|
883
1137
|
yield db.create(this.collectionName, [
|
|
884
1138
|
{
|
|
885
1139
|
name: 'first',
|
|
886
|
-
|
|
1140
|
+
target: {
|
|
887
1141
|
score: 1,
|
|
888
1142
|
},
|
|
889
1143
|
},
|
|
890
1144
|
{
|
|
891
1145
|
name: 'second',
|
|
892
|
-
|
|
1146
|
+
target: {
|
|
893
1147
|
score: 2,
|
|
894
1148
|
},
|
|
895
1149
|
},
|
|
896
1150
|
{
|
|
897
1151
|
name: 'third',
|
|
898
|
-
|
|
1152
|
+
target: {
|
|
899
1153
|
score: 2,
|
|
900
1154
|
},
|
|
901
1155
|
},
|
|
902
1156
|
]);
|
|
903
1157
|
const secondMatch = yield db.findOne(this.collectionName, {
|
|
904
|
-
'
|
|
1158
|
+
'target.score': 2,
|
|
905
1159
|
});
|
|
906
|
-
assert.isTruthy(secondMatch);
|
|
1160
|
+
assert.isTruthy(secondMatch, 'Could not match on path with dot syntax.');
|
|
907
1161
|
assert.isEqual(secondMatch.name, 'second');
|
|
908
1162
|
yield this.shutdown(db);
|
|
909
1163
|
});
|
|
910
1164
|
},
|
|
911
1165
|
assertCanQueryByGtLtGteLte(connect) {
|
|
912
1166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
913
|
-
const db = yield connect
|
|
1167
|
+
const db = yield connectToDabatase(connect);
|
|
914
1168
|
const created = yield db.create(this.collectionName, [
|
|
915
1169
|
{
|
|
916
|
-
|
|
1170
|
+
number: 1,
|
|
1171
|
+
name: generateId(),
|
|
917
1172
|
},
|
|
918
1173
|
{
|
|
919
|
-
|
|
1174
|
+
number: 2,
|
|
1175
|
+
name: generateId(),
|
|
920
1176
|
},
|
|
921
1177
|
{
|
|
922
|
-
|
|
1178
|
+
number: 3,
|
|
1179
|
+
name: generateId(),
|
|
923
1180
|
},
|
|
924
1181
|
{
|
|
925
|
-
|
|
1182
|
+
number: 4,
|
|
1183
|
+
name: generateId(),
|
|
926
1184
|
},
|
|
927
1185
|
]);
|
|
928
1186
|
const gtMatches = yield db.find(this.collectionName, {
|
|
929
|
-
|
|
1187
|
+
number: { $gt: 3 },
|
|
930
1188
|
});
|
|
931
|
-
assert.isLength(gtMatches, 1);
|
|
932
|
-
assert.isEqual(gtMatches[0].
|
|
1189
|
+
assert.isLength(gtMatches, 1, 'Expected 1 match for $gt: 3');
|
|
1190
|
+
assert.isEqual(gtMatches[0].number, 4, 'Did not match the expected result for $gt: 3');
|
|
933
1191
|
const gteMatches = yield db.find(this.collectionName, {
|
|
934
|
-
|
|
1192
|
+
number: { $gte: created[2].number },
|
|
935
1193
|
});
|
|
936
1194
|
assert.isLength(gteMatches, 2);
|
|
937
|
-
assert.isEqual(gteMatches[0].
|
|
938
|
-
assert.isEqual(gteMatches[1].
|
|
1195
|
+
assert.isEqual(gteMatches[0].number, 3);
|
|
1196
|
+
assert.isEqual(gteMatches[1].number, 4);
|
|
939
1197
|
const ltMatches = yield db.find(this.collectionName, {
|
|
940
|
-
|
|
1198
|
+
number: { $lt: created[2].number },
|
|
941
1199
|
});
|
|
942
1200
|
assert.isLength(ltMatches, 2);
|
|
943
|
-
assert.isEqual(ltMatches[0].
|
|
944
|
-
assert.isEqual(ltMatches[1].
|
|
1201
|
+
assert.isEqual(ltMatches[0].number, 1);
|
|
1202
|
+
assert.isEqual(ltMatches[1].number, 2);
|
|
945
1203
|
const lteMatches = yield db.find(this.collectionName, {
|
|
946
|
-
|
|
1204
|
+
number: { $lte: created[2].number },
|
|
947
1205
|
});
|
|
948
1206
|
assert.isLength(lteMatches, 3);
|
|
949
|
-
assert.isEqual(lteMatches[0].
|
|
950
|
-
assert.isEqual(lteMatches[1].
|
|
951
|
-
assert.isEqual(lteMatches[2].
|
|
1207
|
+
assert.isEqual(lteMatches[0].number, 1);
|
|
1208
|
+
assert.isEqual(lteMatches[1].number, 2);
|
|
1209
|
+
assert.isEqual(lteMatches[2].number, 3);
|
|
952
1210
|
yield this.shutdown(db);
|
|
953
1211
|
});
|
|
954
1212
|
},
|
|
955
1213
|
assertCanFindWithNe(connect) {
|
|
956
1214
|
return __awaiter(this, void 0, void 0, function* () {
|
|
957
|
-
const db = yield connect
|
|
1215
|
+
const db = yield connectToDabatase(connect);
|
|
958
1216
|
const record1 = yield db.createOne(this.collectionName, {
|
|
959
|
-
|
|
960
|
-
|
|
1217
|
+
name: 'bar',
|
|
1218
|
+
someField: 'world',
|
|
961
1219
|
});
|
|
962
1220
|
yield db.createOne(this.collectionName, {
|
|
963
|
-
|
|
964
|
-
|
|
1221
|
+
name: 'bar2',
|
|
1222
|
+
someField: 'world',
|
|
965
1223
|
});
|
|
966
1224
|
yield db.createOne(this.collectionName, {
|
|
967
|
-
|
|
968
|
-
|
|
1225
|
+
name: 'bar3',
|
|
1226
|
+
someField: 'planet',
|
|
969
1227
|
});
|
|
970
1228
|
const query = { id: { $ne: record1.id } };
|
|
971
1229
|
const results = yield db.find(this.collectionName, query);
|
|
@@ -975,18 +1233,18 @@ const databaseAssertUtil = {
|
|
|
975
1233
|
},
|
|
976
1234
|
assertCanFindWithIn(connect) {
|
|
977
1235
|
return __awaiter(this, void 0, void 0, function* () {
|
|
978
|
-
const db = yield connect
|
|
1236
|
+
const db = yield connectToDabatase(connect);
|
|
979
1237
|
const record1 = yield db.createOne(this.collectionName, {
|
|
980
|
-
|
|
981
|
-
|
|
1238
|
+
name: 'bar',
|
|
1239
|
+
otherField: 'world',
|
|
982
1240
|
});
|
|
983
1241
|
const record2 = yield db.createOne(this.collectionName, {
|
|
984
|
-
|
|
985
|
-
|
|
1242
|
+
name: 'bar2',
|
|
1243
|
+
otherField: 'world',
|
|
986
1244
|
});
|
|
987
1245
|
const record3 = yield db.createOne(this.collectionName, {
|
|
988
|
-
|
|
989
|
-
|
|
1246
|
+
name: 'bar3',
|
|
1247
|
+
otherField: 'planet',
|
|
990
1248
|
});
|
|
991
1249
|
const query = { id: { $in: [record1.id, record2.id, record3.id] } };
|
|
992
1250
|
const results = yield db.find(this.collectionName, query);
|
|
@@ -994,20 +1252,42 @@ const databaseAssertUtil = {
|
|
|
994
1252
|
yield this.shutdown(db);
|
|
995
1253
|
});
|
|
996
1254
|
},
|
|
1255
|
+
assertCanFindWithBooleanField(connect) {
|
|
1256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1257
|
+
const db = yield connectToDabatase(connect);
|
|
1258
|
+
const first = yield db.createOne(this.collectionName, {
|
|
1259
|
+
name: generateId(),
|
|
1260
|
+
isPublic: true,
|
|
1261
|
+
});
|
|
1262
|
+
const second = yield db.createOne(this.collectionName, {
|
|
1263
|
+
name: generateId(),
|
|
1264
|
+
isPublic: false,
|
|
1265
|
+
});
|
|
1266
|
+
const firstMatch = yield db.findOne(this.collectionName, {
|
|
1267
|
+
isPublic: true,
|
|
1268
|
+
});
|
|
1269
|
+
assert.isEqualDeep(firstMatch, first, `Searching where boolean field is true failed.`);
|
|
1270
|
+
const secondMatch = yield db.findOne(this.collectionName, {
|
|
1271
|
+
isPublic: false,
|
|
1272
|
+
});
|
|
1273
|
+
assert.isEqualDeep(secondMatch, second, `Searching where boolean field is false failed.`);
|
|
1274
|
+
yield this.shutdown(db);
|
|
1275
|
+
});
|
|
1276
|
+
},
|
|
997
1277
|
assertCanCountOnId(connect) {
|
|
998
1278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
999
|
-
const db = yield connect
|
|
1279
|
+
const db = yield connectToDabatase(connect);
|
|
1000
1280
|
const first = yield db.createOne(this.collectionName, {
|
|
1001
|
-
|
|
1002
|
-
|
|
1281
|
+
name: 'bar',
|
|
1282
|
+
otherField: 'world',
|
|
1003
1283
|
});
|
|
1004
1284
|
const second = yield db.createOne(this.collectionName, {
|
|
1005
|
-
|
|
1006
|
-
|
|
1285
|
+
name: 'bar2',
|
|
1286
|
+
otherField: 'world',
|
|
1007
1287
|
});
|
|
1008
1288
|
const third = yield db.createOne(this.collectionName, {
|
|
1009
|
-
|
|
1010
|
-
|
|
1289
|
+
name: 'bar3',
|
|
1290
|
+
otherField: 'planet',
|
|
1011
1291
|
});
|
|
1012
1292
|
const countFirst = yield db.count(this.collectionName, { id: first.id });
|
|
1013
1293
|
const countSecond = yield db.count(this.collectionName, {
|
|
@@ -1024,82 +1304,99 @@ const databaseAssertUtil = {
|
|
|
1024
1304
|
},
|
|
1025
1305
|
assertCanCount(connect) {
|
|
1026
1306
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1027
|
-
const db = yield connect
|
|
1028
|
-
yield db.createOne(this.collectionName, {
|
|
1029
|
-
|
|
1030
|
-
|
|
1307
|
+
const db = yield connectToDabatase(connect);
|
|
1308
|
+
yield db.createOne(this.collectionName, {
|
|
1309
|
+
name: 'bar',
|
|
1310
|
+
otherField: 'world',
|
|
1311
|
+
});
|
|
1312
|
+
yield db.createOne(this.collectionName, {
|
|
1313
|
+
name: 'bar2',
|
|
1314
|
+
otherField: 'world',
|
|
1315
|
+
});
|
|
1316
|
+
yield db.createOne(this.collectionName, {
|
|
1317
|
+
name: 'bar3',
|
|
1318
|
+
otherField: 'planet',
|
|
1319
|
+
});
|
|
1031
1320
|
const countAll = yield db.count(this.collectionName);
|
|
1032
1321
|
assert.isEqual(countAll, 3);
|
|
1033
1322
|
yield this.shutdown(db);
|
|
1034
1323
|
});
|
|
1035
1324
|
},
|
|
1036
1325
|
assertCanUpsertNull(connect) {
|
|
1326
|
+
var _a, _b;
|
|
1037
1327
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1038
|
-
const db = yield connect
|
|
1328
|
+
const db = yield connectToDabatase(connect);
|
|
1039
1329
|
const createdUndefined = yield db.upsertOne(this.collectionName, {
|
|
1040
1330
|
undefinedField: undefined,
|
|
1041
1331
|
}, {
|
|
1042
1332
|
undefinedField: undefined,
|
|
1333
|
+
name: generateId(),
|
|
1043
1334
|
});
|
|
1044
1335
|
assert.isTruthy(createdUndefined);
|
|
1045
|
-
assert.
|
|
1336
|
+
assert.isTrue(createdUndefined.undefinedField === null ||
|
|
1337
|
+
createdUndefined.undefinedfield === null);
|
|
1046
1338
|
const createdNull = yield db.upsertOne(this.collectionName, {
|
|
1047
1339
|
nullField: null,
|
|
1340
|
+
name: '234',
|
|
1048
1341
|
}, {
|
|
1049
1342
|
nullField: null,
|
|
1343
|
+
name: generateId(),
|
|
1050
1344
|
});
|
|
1051
1345
|
assert.isTruthy(createdNull);
|
|
1052
1346
|
let all = yield db.find(this.collectionName);
|
|
1053
|
-
assert.isLength(all, 2);
|
|
1347
|
+
assert.isLength(all, 2, 'I expected to find 2 records after 2 upserts.');
|
|
1054
1348
|
const updatedUndefined = yield db.upsertOne(this.collectionName, {
|
|
1055
1349
|
undefinedField: undefined,
|
|
1056
1350
|
}, { undefinedField: 'now defined' });
|
|
1057
1351
|
assert.isEqual(updatedUndefined.id, createdUndefined.id);
|
|
1058
|
-
assert.isEqual(updatedUndefined.undefinedField, 'now defined');
|
|
1352
|
+
assert.isEqual((_a = updatedUndefined.undefinedField) !== null && _a !== void 0 ? _a : updatedUndefined.undefinedfield, 'now defined');
|
|
1059
1353
|
const updatedNull = yield db.upsertOne(this.collectionName, {
|
|
1060
1354
|
nullField: null,
|
|
1061
1355
|
}, { nullField: 'now defined' });
|
|
1062
1356
|
assert.isEqual(updatedNull.id, createdNull.id);
|
|
1063
|
-
assert.isEqual(updatedNull.nullField, 'now defined');
|
|
1357
|
+
assert.isEqual((_b = updatedNull.nullField) !== null && _b !== void 0 ? _b : updatedNull.nullfield, 'now defined', 'nullField should have upserted to "now defined"');
|
|
1064
1358
|
all = yield db.find(this.collectionName);
|
|
1065
1359
|
assert.isLength(all, 2);
|
|
1066
1360
|
yield this.shutdown(db);
|
|
1067
1361
|
});
|
|
1068
1362
|
},
|
|
1069
1363
|
assertCanSaveAndGetNullAndUndefined(connect) {
|
|
1364
|
+
var _a, _b;
|
|
1070
1365
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1071
|
-
const db = yield connect
|
|
1366
|
+
const db = yield connectToDabatase(connect);
|
|
1072
1367
|
const created = yield db.createOne(this.collectionName, {
|
|
1073
1368
|
undefinedField: undefined,
|
|
1074
1369
|
nullField: null,
|
|
1370
|
+
name: 'hey',
|
|
1075
1371
|
});
|
|
1076
|
-
assert.
|
|
1077
|
-
assert.
|
|
1372
|
+
assert.isTrue(created.undefinedField === null || created.undefinedfield === null, 'undefinedField should be null');
|
|
1373
|
+
assert.isTrue(created.nullField === null || created.nullfield === null, 'nullField should be null');
|
|
1078
1374
|
const matchedUndefined = yield db.findOne(this.collectionName, {
|
|
1079
1375
|
undefinedField: undefined,
|
|
1080
1376
|
});
|
|
1081
1377
|
assert.isTruthy(matchedUndefined);
|
|
1082
|
-
assert.
|
|
1378
|
+
assert.isTrue(matchedUndefined.undefinedField === null ||
|
|
1379
|
+
matchedUndefined.undefinedfield === null, 'findOne should return null for undefinedField');
|
|
1083
1380
|
const matchedNull = yield db.findOne(this.collectionName, {
|
|
1084
1381
|
nullField: null,
|
|
1085
1382
|
});
|
|
1086
1383
|
assert.isTruthy(matchedNull);
|
|
1087
|
-
assert.
|
|
1384
|
+
assert.isTrue(matchedNull.nullField === null || matchedNull.nullfield === null, 'findOne should return null for nullField');
|
|
1088
1385
|
const updatedUndefined = yield db.updateOne(this.collectionName, {
|
|
1089
1386
|
undefinedField: undefined,
|
|
1090
1387
|
}, { undefinedField: 'now defined' });
|
|
1091
1388
|
assert.isEqual(updatedUndefined.id, created.id);
|
|
1092
|
-
assert.isEqual(updatedUndefined.undefinedField, 'now defined');
|
|
1389
|
+
assert.isEqual((_a = updatedUndefined.undefinedField) !== null && _a !== void 0 ? _a : updatedUndefined.undefinedfield, 'now defined');
|
|
1093
1390
|
const updatedNull = yield db.updateOne(this.collectionName, {
|
|
1094
1391
|
nullField: null,
|
|
1095
1392
|
}, { nullField: 'now defined' });
|
|
1096
|
-
assert.isEqual(updatedNull.nullField, 'now defined');
|
|
1393
|
+
assert.isEqual((_b = updatedNull.nullField) !== null && _b !== void 0 ? _b : updatedNull.nullfield, 'now defined');
|
|
1097
1394
|
yield this.shutdown(db);
|
|
1098
1395
|
});
|
|
1099
1396
|
},
|
|
1100
1397
|
assertSyncIndexesDoesNotRemoveExisting(connect) {
|
|
1101
1398
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1102
|
-
const db = yield connect
|
|
1399
|
+
const db = yield connectToDabatase(connect);
|
|
1103
1400
|
yield db.createIndex(this.collectionName, ['otherField']);
|
|
1104
1401
|
yield db.createIndex(this.collectionName, ['someField']);
|
|
1105
1402
|
db.createIndex = () => {
|
|
@@ -1114,29 +1411,29 @@ const databaseAssertUtil = {
|
|
|
1114
1411
|
},
|
|
1115
1412
|
assertSyncIndexesRemovesExtraIndexes(connect) {
|
|
1116
1413
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1117
|
-
const db = yield connect
|
|
1414
|
+
const db = yield connectToDabatase(connect);
|
|
1118
1415
|
yield db.syncIndexes(this.collectionName, [
|
|
1119
|
-
['
|
|
1416
|
+
['name'],
|
|
1120
1417
|
['someField'],
|
|
1121
1418
|
['otherField', 'otherField2'],
|
|
1122
1419
|
]);
|
|
1123
1420
|
let indexes = yield this._getFilteredIndexes(db);
|
|
1124
1421
|
assert.isLength(indexes, 3);
|
|
1125
|
-
yield db.syncIndexes(this.collectionName, [['
|
|
1422
|
+
yield db.syncIndexes(this.collectionName, [['name']]);
|
|
1126
1423
|
indexes = yield this._getFilteredIndexes(db);
|
|
1127
1424
|
assert.isLength(indexes, 1);
|
|
1128
|
-
assert.isEqual(indexes[0][0], '
|
|
1425
|
+
assert.isEqual(indexes[0][0], 'name');
|
|
1129
1426
|
yield this.shutdown(db);
|
|
1130
1427
|
});
|
|
1131
1428
|
},
|
|
1132
1429
|
assertSyncIndexesSkipsExisting(connect) {
|
|
1133
1430
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1134
|
-
const db = yield connect
|
|
1135
|
-
yield db.syncIndexes(this.collectionName, [['
|
|
1431
|
+
const db = yield connectToDabatase(connect);
|
|
1432
|
+
yield db.syncIndexes(this.collectionName, [['name']]);
|
|
1136
1433
|
let indexes = yield this._getFilteredIndexes(db);
|
|
1137
1434
|
assert.isLength(indexes, 1);
|
|
1138
1435
|
yield db.syncIndexes(this.collectionName, [
|
|
1139
|
-
['
|
|
1436
|
+
['name'],
|
|
1140
1437
|
['someField'],
|
|
1141
1438
|
['otherField', 'otherField2'],
|
|
1142
1439
|
]);
|
|
@@ -1147,16 +1444,19 @@ const databaseAssertUtil = {
|
|
|
1147
1444
|
},
|
|
1148
1445
|
assertCantDropCompoundIndexThatDoesNotExist(connect) {
|
|
1149
1446
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1150
|
-
const db = yield connect
|
|
1447
|
+
const db = yield connectToDabatase(connect);
|
|
1151
1448
|
yield db.createIndex(this.collectionName, ['someField', 'someOtherField']);
|
|
1152
1449
|
const err = yield assert.doesThrowAsync(() => db.dropIndex(this.collectionName, ['uniqueField', 'someOtherField']));
|
|
1153
|
-
errorAssert.assertError(err, 'INDEX_NOT_FOUND'
|
|
1450
|
+
errorAssert.assertError(err, 'INDEX_NOT_FOUND', {
|
|
1451
|
+
collectionName: this.collectionName,
|
|
1452
|
+
missingIndex: ['uniqueField', 'someOtherField'],
|
|
1453
|
+
});
|
|
1154
1454
|
yield this.shutdown(db);
|
|
1155
1455
|
});
|
|
1156
1456
|
},
|
|
1157
1457
|
assertCanDropCompoundIndex(connect) {
|
|
1158
1458
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1159
|
-
const db = yield connect
|
|
1459
|
+
const db = yield connectToDabatase(connect);
|
|
1160
1460
|
yield db.createIndex(this.collectionName, ['someField', 'otherField']);
|
|
1161
1461
|
yield db.dropIndex(this.collectionName, ['someField', 'otherField']);
|
|
1162
1462
|
let indexes = yield this._getFilteredIndexes(db);
|
|
@@ -1171,7 +1471,7 @@ const databaseAssertUtil = {
|
|
|
1171
1471
|
},
|
|
1172
1472
|
assertCanDropIndex(connect) {
|
|
1173
1473
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1174
|
-
const db = yield connect
|
|
1474
|
+
const db = yield connectToDabatase(connect);
|
|
1175
1475
|
yield db.createIndex(this.collectionName, ['someField']);
|
|
1176
1476
|
yield db.dropIndex(this.collectionName, ['someField']);
|
|
1177
1477
|
let indexes = yield this._getFilteredIndexes(db);
|
|
@@ -1184,58 +1484,70 @@ const databaseAssertUtil = {
|
|
|
1184
1484
|
yield this.shutdown(db);
|
|
1185
1485
|
});
|
|
1186
1486
|
},
|
|
1187
|
-
assertCanCreateMultiFieldIndex(connect
|
|
1487
|
+
assertCanCreateMultiFieldIndex(connect) {
|
|
1188
1488
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1489
|
+
yield this._assertCanCreateMultiFieldIndex(connect, [
|
|
1490
|
+
'otherField',
|
|
1491
|
+
'someField',
|
|
1492
|
+
]);
|
|
1493
|
+
yield this._assertCanCreateMultiFieldIndex(connect, [
|
|
1494
|
+
'someField',
|
|
1495
|
+
'otherField',
|
|
1496
|
+
]);
|
|
1497
|
+
yield this._assertCanCreateMultiFieldIndex(connect, [
|
|
1498
|
+
'otherField',
|
|
1499
|
+
'otherField2',
|
|
1500
|
+
]);
|
|
1501
|
+
yield this._assertCanCreateMultiFieldIndex(connect, [
|
|
1502
|
+
'otherField2',
|
|
1503
|
+
'otherField',
|
|
1504
|
+
]);
|
|
1195
1505
|
});
|
|
1196
1506
|
},
|
|
1197
1507
|
assertCantCreateSameIndexTwice(connect) {
|
|
1198
1508
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1199
|
-
const db = yield connect
|
|
1200
|
-
yield db.createIndex(this.collectionName, ['
|
|
1509
|
+
const db = yield connectToDabatase(connect);
|
|
1510
|
+
yield db.createIndex(this.collectionName, ['name']);
|
|
1201
1511
|
let indexes = yield this._getFilteredIndexes(db);
|
|
1202
1512
|
assert.isLength(indexes, 1);
|
|
1203
|
-
const err = yield assert.doesThrowAsync(() => db.createIndex(this.collectionName, ['
|
|
1513
|
+
const err = yield assert.doesThrowAsync(() => db.createIndex(this.collectionName, ['name']));
|
|
1204
1514
|
errorAssert.assertError(err, 'INDEX_EXISTS');
|
|
1205
1515
|
yield this.shutdown(db);
|
|
1206
1516
|
});
|
|
1207
1517
|
},
|
|
1208
1518
|
assertCanCreateIndex(connect) {
|
|
1209
1519
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1210
|
-
const db = yield connect
|
|
1211
|
-
yield db.createIndex(this.collectionName, ['
|
|
1520
|
+
const db = yield connectToDabatase(connect);
|
|
1521
|
+
yield db.createIndex(this.collectionName, ['uniqueField']);
|
|
1212
1522
|
let indexes = yield this._getFilteredIndexes(db);
|
|
1213
|
-
assert.
|
|
1214
|
-
assert.isLength(indexes
|
|
1215
|
-
assert.
|
|
1216
|
-
|
|
1523
|
+
assert.isArray(indexes, 'getIndexes() should return an array!');
|
|
1524
|
+
assert.isLength(indexes, 1, 'getIndexes() should return the one index that was created!');
|
|
1525
|
+
assert.isLength(indexes[0], 1, 'getIndexes() should return an array of arrays! It should be returing the first index I created!');
|
|
1526
|
+
assert.isEqual(indexes[0][0].toLowerCase(), 'uniqueField'.toLowerCase());
|
|
1527
|
+
yield db.createIndex(this.collectionName, ['uniqueField2']);
|
|
1217
1528
|
indexes = yield this._getFilteredIndexes(db);
|
|
1218
1529
|
assert.isLength(indexes, 2);
|
|
1219
|
-
assert.isEqual(indexes[1][0], '
|
|
1220
|
-
yield db.createIndex(this.collectionName, ['
|
|
1530
|
+
assert.isEqual(indexes[1][0].toLowerCase(), 'uniqueField2'.toLowerCase());
|
|
1531
|
+
yield db.createIndex(this.collectionName, ['uniqueField3', 'uniqueField4']);
|
|
1221
1532
|
indexes = yield this._getFilteredIndexes(db);
|
|
1222
1533
|
assert.isLength(indexes, 3);
|
|
1223
|
-
assert.isEqual(indexes[2][0], '
|
|
1224
|
-
assert.isEqual(indexes[2][1], '
|
|
1534
|
+
assert.isEqual(indexes[2][0].toLowerCase(), 'uniqueField3'.toLowerCase());
|
|
1535
|
+
assert.isEqual(indexes[2][1].toLowerCase(), 'uniqueField4'.toLowerCase());
|
|
1225
1536
|
yield this.shutdown(db);
|
|
1226
1537
|
});
|
|
1227
1538
|
},
|
|
1228
1539
|
assertHasNoIndexToStart(connect) {
|
|
1229
1540
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1230
|
-
const db = yield connect
|
|
1541
|
+
const db = yield connectToDabatase(connect);
|
|
1231
1542
|
const indexes = yield db.getIndexes(this.collectionName);
|
|
1232
1543
|
assert.isLength(indexes, 0);
|
|
1233
1544
|
yield this.shutdown(db);
|
|
1234
1545
|
});
|
|
1235
1546
|
},
|
|
1236
1547
|
assertNestedFieldIndexUpdates(connect) {
|
|
1548
|
+
var _a;
|
|
1237
1549
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1238
|
-
const db = yield connect
|
|
1550
|
+
const db = yield connectToDabatase(connect);
|
|
1239
1551
|
yield db.createUniqueIndex(this.collectionName, [
|
|
1240
1552
|
'target.organizationId',
|
|
1241
1553
|
'slug',
|
|
@@ -1245,6 +1557,7 @@ const databaseAssertUtil = {
|
|
|
1245
1557
|
organizationId: 'go!',
|
|
1246
1558
|
},
|
|
1247
1559
|
aNonIndexedField: true,
|
|
1560
|
+
name: 'squirrel',
|
|
1248
1561
|
slug: 'a slug',
|
|
1249
1562
|
});
|
|
1250
1563
|
const updated = yield db.updateOne(this.collectionName, { id: results.id }, {
|
|
@@ -1254,13 +1567,13 @@ const databaseAssertUtil = {
|
|
|
1254
1567
|
aNonIndexedField: false,
|
|
1255
1568
|
slug: 'a slug',
|
|
1256
1569
|
});
|
|
1257
|
-
assert.isEqual(updated.aNonIndexedField, false);
|
|
1570
|
+
assert.isEqual((_a = updated.aNonIndexedField) !== null && _a !== void 0 ? _a : updated.anonindexedfield, false);
|
|
1258
1571
|
yield this.shutdown(db);
|
|
1259
1572
|
});
|
|
1260
1573
|
},
|
|
1261
1574
|
assertUpsertWithUniqueIndex(connect) {
|
|
1262
1575
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1263
|
-
const db = yield connect
|
|
1576
|
+
const db = yield connectToDabatase(connect);
|
|
1264
1577
|
yield db.syncUniqueIndexes(this.collectionName, [
|
|
1265
1578
|
['name', 'target.organizationId'],
|
|
1266
1579
|
['slug', 'target.organizationId'],
|
|
@@ -1286,7 +1599,7 @@ const databaseAssertUtil = {
|
|
|
1286
1599
|
},
|
|
1287
1600
|
assertSyncIndexesHandlesRaceConditions(connect) {
|
|
1288
1601
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1289
|
-
const db = yield connect
|
|
1602
|
+
const db = yield connectToDabatase(connect);
|
|
1290
1603
|
const syncs = [
|
|
1291
1604
|
db.syncIndexes(this.collectionName, [['otherField', 'otherField2']]),
|
|
1292
1605
|
db.syncIndexes(this.collectionName, [['otherField', 'otherField2']]),
|
|
@@ -1305,35 +1618,98 @@ const databaseAssertUtil = {
|
|
|
1305
1618
|
},
|
|
1306
1619
|
assertDuplicateFieldsWithMultipleUniqueIndexesWorkAsExpected(connect) {
|
|
1307
1620
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1308
|
-
const db = yield connect
|
|
1309
|
-
yield db.createUniqueIndex(this.collectionName, ['
|
|
1621
|
+
const db = yield connectToDabatase(connect);
|
|
1622
|
+
yield db.createUniqueIndex(this.collectionName, ['uniqueField']);
|
|
1310
1623
|
yield db.createUniqueIndex(this.collectionName, ['uniqueField2']);
|
|
1311
1624
|
yield db.createOne(this.collectionName, {
|
|
1312
|
-
|
|
1625
|
+
name: generateId(),
|
|
1626
|
+
uniqueField: 'unique field 1',
|
|
1313
1627
|
uniqueField2: 'unique field 2',
|
|
1314
1628
|
});
|
|
1315
1629
|
let err = yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
|
1316
|
-
|
|
1630
|
+
name: generateId(),
|
|
1631
|
+
uniqueField: 'unique field 1',
|
|
1317
1632
|
uniqueField2: 'unique field 2',
|
|
1318
1633
|
}));
|
|
1634
|
+
lowerCaseStringArray(err, 'duplicateFields');
|
|
1319
1635
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
1320
1636
|
collectionName: this.collectionName,
|
|
1321
|
-
duplicateFields: ['
|
|
1637
|
+
duplicateFields: ['uniquefield'],
|
|
1322
1638
|
duplicateValues: ['unique field 1'],
|
|
1323
1639
|
action: 'create',
|
|
1324
1640
|
});
|
|
1325
1641
|
err = yield assert.doesThrowAsync(() => db.createOne(this.collectionName, {
|
|
1326
|
-
|
|
1642
|
+
name: generateId(),
|
|
1643
|
+
uniqueField: 'unique field 1.0',
|
|
1327
1644
|
uniqueField2: 'unique field 2',
|
|
1328
1645
|
}));
|
|
1646
|
+
lowerCaseStringArray(err, 'duplicateFields');
|
|
1329
1647
|
errorAssert.assertError(err, 'DUPLICATE_RECORD', {
|
|
1330
1648
|
collectionName: this.collectionName,
|
|
1331
|
-
duplicateFields: ['
|
|
1649
|
+
duplicateFields: ['uniquefield2'],
|
|
1332
1650
|
duplicateValues: ['unique field 2'],
|
|
1333
1651
|
action: 'create',
|
|
1334
1652
|
});
|
|
1335
1653
|
yield this.shutdown(db);
|
|
1336
1654
|
});
|
|
1337
1655
|
},
|
|
1656
|
+
_assertThrowsExpectedNotFoundOnUpdateOne(db, query) {
|
|
1657
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1658
|
+
const err = (yield assert.doesThrowAsync(() => db.updateOne(this.collectionName, query, { name: 'bar' }), undefined, `updateOne should throw a RECORD_NOT_FOUND when updating a record that cannot be found!`));
|
|
1659
|
+
errorAssert.assertError(err, 'RECORD_NOT_FOUND', {
|
|
1660
|
+
query,
|
|
1661
|
+
});
|
|
1662
|
+
});
|
|
1663
|
+
},
|
|
1664
|
+
_assert$orReturnsExpectedTotalRecords(db, $or, expected) {
|
|
1665
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1666
|
+
const matches = yield db.find(this.collectionName, {
|
|
1667
|
+
$or,
|
|
1668
|
+
});
|
|
1669
|
+
assert.isLength(matches, expected);
|
|
1670
|
+
});
|
|
1671
|
+
},
|
|
1672
|
+
_assertCanCreateMultiFieldIndex(connect, fields) {
|
|
1673
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1674
|
+
const db = yield connectToDabatase(connect);
|
|
1675
|
+
yield db.createIndex(this.collectionName, fields);
|
|
1676
|
+
const indexes = yield this._getFilteredIndexes(db);
|
|
1677
|
+
assert.isLength(indexes, 1, `getIndexes() should return the index it created. I expected 1 but got ${indexes.length}. Also, make sure you clear the indexes when resetting the database!`);
|
|
1678
|
+
assert.isEqualDeep(indexes[0].map((i) => i.toLowerCase()), fields.map((f) => f.toLowerCase()));
|
|
1679
|
+
yield this.shutdown(db);
|
|
1680
|
+
});
|
|
1681
|
+
},
|
|
1338
1682
|
};
|
|
1339
1683
|
export default databaseAssertUtil;
|
|
1684
|
+
function assertCantCreateUniqueIndexTwice(db, collectionName, fields, expectedTotalUniqueIndexes) {
|
|
1685
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1686
|
+
yield db.createUniqueIndex(collectionName, fields);
|
|
1687
|
+
let indexes = yield db.getUniqueIndexes(collectionName);
|
|
1688
|
+
assert.isLength(indexes, expectedTotalUniqueIndexes, 'getUniqueIndexes() should return total unique indexs');
|
|
1689
|
+
const err = yield assert.doesThrowAsync(() => db.createUniqueIndex(collectionName, ['uniqueField']), undefined, 'createUniqueIndex() should throw a DataStoreError({code: "INDEX_EXISTS"}) error.');
|
|
1690
|
+
errorAssert.assertError(err, 'INDEX_EXISTS', {
|
|
1691
|
+
collectionName,
|
|
1692
|
+
index: ['uniqueField'],
|
|
1693
|
+
});
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
function lowerCaseErrorDuplicateFields(err) {
|
|
1697
|
+
lowerCaseStringArray(err, 'duplicateFields');
|
|
1698
|
+
}
|
|
1699
|
+
function lowerCaseMissingIndexValues(err) {
|
|
1700
|
+
lowerCaseStringArray(err, 'missingIndex');
|
|
1701
|
+
}
|
|
1702
|
+
function lowerCaseStringArray(err, key) {
|
|
1703
|
+
var _a, _b;
|
|
1704
|
+
//@ts-ignore
|
|
1705
|
+
if ((_b = (_a = err.options) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.map) {
|
|
1706
|
+
//@ts-ignore
|
|
1707
|
+
err.options[key] = err.options[key].map((i) => i.toLowerCase());
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
function connectToDabatase(connect) {
|
|
1711
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1712
|
+
const { db } = yield connect();
|
|
1713
|
+
return db;
|
|
1714
|
+
});
|
|
1715
|
+
}
|