@entropic-bond/firebase 1.5.4 → 1.6.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/lib/auth/firebase-auth.d.ts +1 -0
- package/lib/auth/firebase-auth.js +93 -188
- package/lib/auth/firebase-auth.js.map +1 -1
- package/lib/auth/firebase-auth.spec.js +2 -2
- package/lib/auth/firebase-auth.spec.js.map +1 -1
- package/lib/cloud-storage/firebase-cloud-storage.js +35 -56
- package/lib/cloud-storage/firebase-cloud-storage.js.map +1 -1
- package/lib/cloud-storage/firebase-cloud-storage.spec.js +76 -198
- package/lib/cloud-storage/firebase-cloud-storage.spec.js.map +1 -1
- package/lib/firebase-helper.d.ts +1 -0
- package/lib/firebase-helper.js +25 -45
- package/lib/firebase-helper.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/mocks/test-user.js +110 -178
- package/lib/mocks/test-user.js.map +1 -1
- package/lib/store/firebase-datasource.js +48 -122
- package/lib/store/firebase-datasource.js.map +1 -1
- package/lib/store/firebase-datasource.spec.js +298 -691
- package/lib/store/firebase-datasource.spec.js.map +1 -1
- package/package.json +9 -9
|
@@ -8,721 +8,328 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
15
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
16
|
+
const entropic_bond_1 = require("entropic-bond");
|
|
17
|
+
const firebase_datasource_1 = require("./firebase-datasource");
|
|
18
|
+
const firebase_helper_1 = require("../firebase-helper");
|
|
19
|
+
const test_user_1 = require("../mocks/test-user");
|
|
20
|
+
const mock_data_json_1 = __importDefault(require("../mocks/mock-data.json"));
|
|
21
|
+
const firestore_1 = require("firebase/firestore");
|
|
49
22
|
function loadTestData(model) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
user = entropic_bond_1.Persistent.createInstance(users[key]);
|
|
59
|
-
promises.push(model.save(user));
|
|
60
|
-
}
|
|
61
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
62
|
-
case 1:
|
|
63
|
-
_a.sent();
|
|
64
|
-
return [2 /*return*/];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const users = mock_data_json_1.default.TestUser;
|
|
25
|
+
const promises = [];
|
|
26
|
+
for (const key in users) {
|
|
27
|
+
const user = entropic_bond_1.Persistent.createInstance(users[key]);
|
|
28
|
+
promises.push(model.save(user));
|
|
29
|
+
}
|
|
30
|
+
yield Promise.all(promises);
|
|
67
31
|
});
|
|
68
32
|
}
|
|
69
|
-
describe('Firestore Model',
|
|
70
|
-
|
|
71
|
-
|
|
33
|
+
describe('Firestore Model', () => {
|
|
34
|
+
let model;
|
|
35
|
+
let testUser;
|
|
72
36
|
firebase_helper_1.FirebaseHelper.setFirebaseConfig({
|
|
73
37
|
projectId: "demo-test",
|
|
74
38
|
});
|
|
75
39
|
firebase_helper_1.FirebaseHelper.useEmulator({ firestorePort: 9080 });
|
|
76
|
-
beforeEach(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return [2 /*return*/];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}); });
|
|
96
|
-
afterEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
-
return __generator(this, function (_a) {
|
|
98
|
-
switch (_a.label) {
|
|
99
|
-
case 0:
|
|
100
|
-
(0, firestore_1.terminate)(firebase_helper_1.FirebaseHelper.instance.firestore());
|
|
101
|
-
return [4 /*yield*/, (0, node_fetch_1.default)('http://localhost:9080/emulator/v1/projects/demo-test/databases/(default)/documents', {
|
|
102
|
-
method: 'DELETE'
|
|
103
|
-
})];
|
|
104
|
-
case 1:
|
|
105
|
-
_a.sent();
|
|
106
|
-
return [2 /*return*/];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}); });
|
|
110
|
-
it('should find document by id', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
111
|
-
var user;
|
|
112
|
-
return __generator(this, function (_a) {
|
|
113
|
-
switch (_a.label) {
|
|
114
|
-
case 0: return [4 /*yield*/, model.save(testUser)];
|
|
115
|
-
case 1:
|
|
116
|
-
_a.sent();
|
|
117
|
-
return [4 /*yield*/, model.findById(testUser.id)];
|
|
118
|
-
case 2:
|
|
119
|
-
user = _a.sent();
|
|
120
|
-
expect(user).toBeInstanceOf(test_user_1.TestUser);
|
|
121
|
-
expect(user.id).toEqual(testUser.id);
|
|
122
|
-
expect(user.name.firstName).toEqual('testUserFirstName');
|
|
123
|
-
return [2 /*return*/];
|
|
124
|
-
}
|
|
40
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
entropic_bond_1.Store.useDataSource(new firebase_datasource_1.FirebaseDatasource());
|
|
42
|
+
testUser = new test_user_1.TestUser();
|
|
43
|
+
testUser.name = {
|
|
44
|
+
firstName: 'testUserFirstName',
|
|
45
|
+
lastName: 'testUserLastName'
|
|
46
|
+
};
|
|
47
|
+
testUser.age = 35;
|
|
48
|
+
testUser.skills = ['lazy', 'dirty'];
|
|
49
|
+
model = entropic_bond_1.Store.getModel('TestUser');
|
|
50
|
+
yield loadTestData(model);
|
|
51
|
+
}));
|
|
52
|
+
afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
(0, firestore_1.terminate)(firebase_helper_1.FirebaseHelper.instance.firestore());
|
|
54
|
+
yield (0, node_fetch_1.default)('http://localhost:9080/emulator/v1/projects/demo-test/databases/(default)/documents', {
|
|
55
|
+
method: 'DELETE'
|
|
125
56
|
});
|
|
126
|
-
})
|
|
127
|
-
it('should
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
141
|
-
return [2 /*return*/];
|
|
142
|
-
}
|
|
57
|
+
}));
|
|
58
|
+
it('should find document by id', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
yield model.save(testUser);
|
|
60
|
+
const user = yield model.findById(testUser.id);
|
|
61
|
+
expect(user).toBeInstanceOf(test_user_1.TestUser);
|
|
62
|
+
expect(user.id).toEqual(testUser.id);
|
|
63
|
+
expect(user.name.firstName).toEqual('testUserFirstName');
|
|
64
|
+
}));
|
|
65
|
+
it('should write a document', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
yield model.save(testUser);
|
|
67
|
+
const newUser = yield model.findById(testUser.id);
|
|
68
|
+
expect(newUser.name).toEqual({
|
|
69
|
+
firstName: 'testUserFirstName',
|
|
70
|
+
lastName: 'testUserLastName'
|
|
143
71
|
});
|
|
144
|
-
})
|
|
145
|
-
it('should delete a document by id',
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
expect(newUser.age).toBe(35);
|
|
156
|
-
return [4 /*yield*/, model.delete(testUser.id)];
|
|
157
|
-
case 3:
|
|
158
|
-
_a.sent();
|
|
159
|
-
return [4 /*yield*/, model.findById(testUser.id)];
|
|
160
|
-
case 4:
|
|
161
|
-
deletedUser = _a.sent();
|
|
162
|
-
expect(deletedUser).toBeUndefined();
|
|
163
|
-
return [2 /*return*/];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}); });
|
|
167
|
-
it('should not throw if a document id doesn\'t exists', function (done) {
|
|
168
|
-
expect(function () {
|
|
72
|
+
}));
|
|
73
|
+
it('should delete a document by id', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
yield model.save(testUser);
|
|
75
|
+
const newUser = yield model.findById(testUser.id);
|
|
76
|
+
expect(newUser.age).toBe(35);
|
|
77
|
+
yield model.delete(testUser.id);
|
|
78
|
+
const deletedUser = yield model.findById(testUser.id);
|
|
79
|
+
expect(deletedUser).toBeUndefined();
|
|
80
|
+
}));
|
|
81
|
+
it('should not throw if a document id doesn\'t exists', (done) => {
|
|
82
|
+
expect(() => {
|
|
169
83
|
model.findById('nonExistingId')
|
|
170
84
|
.then(done)
|
|
171
85
|
.catch(done);
|
|
172
86
|
}).not.toThrow();
|
|
173
87
|
});
|
|
174
|
-
it('should return undefined if a document id doesn\'t exists',
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return __generator(this, function (_a) {
|
|
190
|
-
switch (_a.label) {
|
|
191
|
-
case 0: return [4 /*yield*/, model.save(testUser)];
|
|
192
|
-
case 1:
|
|
193
|
-
_a.sent();
|
|
194
|
-
return [4 /*yield*/, model.findById(testUser.id)];
|
|
195
|
-
case 2:
|
|
196
|
-
newUser = _a.sent();
|
|
197
|
-
expect(Array.isArray(newUser.skills)).toBeTruthy();
|
|
198
|
-
expect(newUser.skills).toEqual(expect.arrayContaining(['lazy', 'dirty']));
|
|
199
|
-
return [2 /*return*/];
|
|
200
|
-
}
|
|
88
|
+
it('should return undefined if a document id doesn\'t exists', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
expect(yield model.findById('nonExistingId')).toBeUndefined();
|
|
90
|
+
}));
|
|
91
|
+
it('should retrieve array fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
yield model.save(testUser);
|
|
93
|
+
const newUser = yield model.findById(testUser.id);
|
|
94
|
+
expect(Array.isArray(newUser.skills)).toBeTruthy();
|
|
95
|
+
expect(newUser.skills).toEqual(expect.arrayContaining(['lazy', 'dirty']));
|
|
96
|
+
}));
|
|
97
|
+
it('should retrieve object fields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
yield model.save(testUser);
|
|
99
|
+
const newUser = yield model.findById(testUser.id);
|
|
100
|
+
expect(newUser.name).toEqual({
|
|
101
|
+
firstName: 'testUserFirstName',
|
|
102
|
+
lastName: 'testUserLastName'
|
|
201
103
|
});
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
expect(newUser.name).toEqual({
|
|
214
|
-
firstName: 'testUserFirstName',
|
|
215
|
-
lastName: 'testUserLastName'
|
|
216
|
-
});
|
|
217
|
-
return [2 /*return*/];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}); });
|
|
221
|
-
describe('Generic find', function () {
|
|
222
|
-
it('should query all admins with query object', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
223
|
-
var admins;
|
|
224
|
-
return __generator(this, function (_a) {
|
|
225
|
-
switch (_a.label) {
|
|
226
|
-
case 0:
|
|
227
|
-
testUser.admin = true;
|
|
228
|
-
return [4 /*yield*/, model.save(testUser)];
|
|
229
|
-
case 1:
|
|
230
|
-
_a.sent();
|
|
231
|
-
return [4 /*yield*/, model.query({
|
|
232
|
-
operations: [{
|
|
233
|
-
property: 'admin',
|
|
234
|
-
operator: '==',
|
|
235
|
-
value: true
|
|
236
|
-
}]
|
|
237
|
-
})];
|
|
238
|
-
case 2:
|
|
239
|
-
admins = _a.sent();
|
|
240
|
-
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
241
|
-
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
242
|
-
return [2 /*return*/];
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}); });
|
|
246
|
-
it('should find all admins with where methods', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
247
|
-
var admins;
|
|
248
|
-
return __generator(this, function (_a) {
|
|
249
|
-
switch (_a.label) {
|
|
250
|
-
case 0: return [4 /*yield*/, model.find().where('admin', '==', true).get()];
|
|
251
|
-
case 1:
|
|
252
|
-
admins = _a.sent();
|
|
253
|
-
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
254
|
-
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
255
|
-
return [2 /*return*/];
|
|
256
|
-
}
|
|
104
|
+
}));
|
|
105
|
+
describe('Generic find', () => {
|
|
106
|
+
it('should query all admins with query object', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
testUser.admin = true;
|
|
108
|
+
yield model.save(testUser);
|
|
109
|
+
const admins = yield model.query({
|
|
110
|
+
operations: [{
|
|
111
|
+
property: 'admin',
|
|
112
|
+
operator: '==',
|
|
113
|
+
value: true
|
|
114
|
+
}]
|
|
257
115
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
116
|
+
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
117
|
+
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
118
|
+
}));
|
|
119
|
+
it('should find all admins with where methods', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
+
const admins = yield model.find().where('admin', '==', true).get();
|
|
121
|
+
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
122
|
+
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
123
|
+
}));
|
|
124
|
+
it('should find admins with age less than 56', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
const admins = yield model.find()
|
|
126
|
+
.where('admin', '==', true)
|
|
127
|
+
.where('age', '<', 50)
|
|
128
|
+
.get();
|
|
129
|
+
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
130
|
+
expect(admins[0].age).toBeLessThan(50);
|
|
131
|
+
}));
|
|
132
|
+
it('should query by subproperties', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const users = yield model.query({
|
|
134
|
+
operations: [
|
|
135
|
+
{
|
|
136
|
+
property: 'name',
|
|
137
|
+
operator: '==',
|
|
138
|
+
value: { firstName: 'userFirstName3' }
|
|
139
|
+
},
|
|
140
|
+
{ property: 'age', operator: '!=', value: 134 }
|
|
141
|
+
]
|
|
273
142
|
});
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
case 0: return [4 /*yield*/, model.find()
|
|
301
|
-
.where('name', '==', { firstName: 'userFirstName3' })
|
|
302
|
-
.get()];
|
|
303
|
-
case 1:
|
|
304
|
-
users = _a.sent();
|
|
305
|
-
expect(users[0].id).toBe('user3');
|
|
306
|
-
return [2 /*return*/];
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
}); });
|
|
310
|
-
it('should find by property path', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
311
|
-
var users;
|
|
312
|
-
return __generator(this, function (_a) {
|
|
313
|
-
switch (_a.label) {
|
|
314
|
-
case 0: return [4 /*yield*/, model.find()
|
|
315
|
-
.whereDeepProp('name.firstName', '==', 'userFirstName3')
|
|
316
|
-
.get()];
|
|
317
|
-
case 1:
|
|
318
|
-
users = _a.sent();
|
|
319
|
-
expect(users[0].id).toBe('user3');
|
|
320
|
-
return [2 /*return*/];
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
}); });
|
|
324
|
-
it('should find by superdeep property path', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
325
|
-
var users;
|
|
326
|
-
return __generator(this, function (_a) {
|
|
327
|
-
switch (_a.label) {
|
|
328
|
-
case 0: return [4 /*yield*/, model.find()
|
|
329
|
-
.whereDeepProp('name.ancestorName.father', '==', 'user3Father')
|
|
330
|
-
.get()];
|
|
331
|
-
case 1:
|
|
332
|
-
users = _a.sent();
|
|
333
|
-
expect(users[0].id).toEqual('user3');
|
|
334
|
-
return [2 /*return*/];
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
}); });
|
|
338
|
-
it('should find by swallow property path', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
339
|
-
var users;
|
|
340
|
-
return __generator(this, function (_a) {
|
|
341
|
-
switch (_a.label) {
|
|
342
|
-
case 0: return [4 /*yield*/, model.find()
|
|
343
|
-
.whereDeepProp('age', '==', 21)
|
|
344
|
-
.get()];
|
|
345
|
-
case 1:
|
|
346
|
-
users = _a.sent();
|
|
347
|
-
expect(users[0].id).toEqual('user2');
|
|
348
|
-
return [2 /*return*/];
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
}); });
|
|
143
|
+
expect(users[0].id).toBe('user3');
|
|
144
|
+
}));
|
|
145
|
+
it('should find by subproperties', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
const users = yield model.find()
|
|
147
|
+
.where('name', '==', { firstName: 'userFirstName3' })
|
|
148
|
+
.get();
|
|
149
|
+
expect(users[0].id).toBe('user3');
|
|
150
|
+
}));
|
|
151
|
+
it('should find by property path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
+
const users = yield model.find()
|
|
153
|
+
.whereDeepProp('name.firstName', '==', 'userFirstName3')
|
|
154
|
+
.get();
|
|
155
|
+
expect(users[0].id).toBe('user3');
|
|
156
|
+
}));
|
|
157
|
+
it('should find by superdeep property path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
+
const users = yield model.find()
|
|
159
|
+
.whereDeepProp('name.ancestorName.father', '==', 'user3Father')
|
|
160
|
+
.get();
|
|
161
|
+
expect(users[0].id).toEqual('user3');
|
|
162
|
+
}));
|
|
163
|
+
it('should find by swallow property path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
const users = yield model.find()
|
|
165
|
+
.whereDeepProp('age', '==', 21)
|
|
166
|
+
.get();
|
|
167
|
+
expect(users[0].id).toEqual('user2');
|
|
168
|
+
}));
|
|
352
169
|
});
|
|
353
|
-
describe('Derived classes should fit on parent collection',
|
|
354
|
-
it('should save derived object in parent collection',
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
_a.sent();
|
|
365
|
-
return [4 /*yield*/, model.findById(derived.id)];
|
|
366
|
-
case 2:
|
|
367
|
-
newUser = _a.sent();
|
|
368
|
-
expect(newUser).toBeInstanceOf(test_user_1.DerivedUser);
|
|
369
|
-
expect(newUser.salary).toBe(3900);
|
|
370
|
-
expect(newUser.className).toEqual('DerivedUser');
|
|
371
|
-
return [2 /*return*/];
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
}); });
|
|
170
|
+
describe('Derived classes should fit on parent collection', () => {
|
|
171
|
+
it('should save derived object in parent collection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
172
|
+
const derived = new test_user_1.DerivedUser();
|
|
173
|
+
derived.name = { firstName: 'Fulanito', lastName: 'Derived' };
|
|
174
|
+
derived.salary = 3900;
|
|
175
|
+
yield model.save(derived);
|
|
176
|
+
const newUser = yield model.findById(derived.id);
|
|
177
|
+
expect(newUser).toBeInstanceOf(test_user_1.DerivedUser);
|
|
178
|
+
expect(newUser.salary).toBe(3900);
|
|
179
|
+
expect(newUser.className).toEqual('DerivedUser');
|
|
180
|
+
}));
|
|
375
181
|
});
|
|
376
|
-
describe('References to documents',
|
|
377
|
-
|
|
378
|
-
beforeEach(
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
var loadedUser;
|
|
483
|
-
return __generator(this, function (_a) {
|
|
484
|
-
switch (_a.label) {
|
|
485
|
-
case 0: return [4 /*yield*/, model.findById(testUser.id)];
|
|
486
|
-
case 1:
|
|
487
|
-
loadedUser = _a.sent();
|
|
488
|
-
return [4 /*yield*/, entropic_bond_1.Store.populate(loadedUser.manyRefs)];
|
|
489
|
-
case 2:
|
|
490
|
-
_a.sent();
|
|
491
|
-
expect(loadedUser.manyRefs[0].year).toBe(2081);
|
|
492
|
-
expect(loadedUser.manyRefs[1].year).toBe(2082);
|
|
493
|
-
return [2 /*return*/];
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
}); });
|
|
497
|
-
it('should save a reference when declared @persistentAt', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
498
|
-
var loadedUser;
|
|
499
|
-
return __generator(this, function (_a) {
|
|
500
|
-
switch (_a.label) {
|
|
501
|
-
case 0: return [4 /*yield*/, model.findById(testUser.id)];
|
|
502
|
-
case 1:
|
|
503
|
-
loadedUser = _a.sent();
|
|
504
|
-
expect(loadedUser.derived.id).toEqual(testUser.derived.id);
|
|
505
|
-
expect(loadedUser.derived.salary).toBeUndefined();
|
|
506
|
-
return [4 /*yield*/, entropic_bond_1.Store.populate(loadedUser.derived)];
|
|
507
|
-
case 2:
|
|
508
|
-
_a.sent();
|
|
509
|
-
expect(loadedUser.derived.salary).toBe(1350);
|
|
510
|
-
expect(loadedUser.derived.id).toBe(testUser.derived.id);
|
|
511
|
-
return [2 /*return*/];
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
}); });
|
|
515
|
-
it('should populate from special collection when declared with @persistentRefAt', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
516
|
-
var loadedUser;
|
|
517
|
-
return __generator(this, function (_a) {
|
|
518
|
-
switch (_a.label) {
|
|
519
|
-
case 0: return [4 /*yield*/, model.findById('user6')];
|
|
520
|
-
case 1:
|
|
521
|
-
loadedUser = _a.sent();
|
|
522
|
-
return [4 /*yield*/, entropic_bond_1.Store.populate(loadedUser.derived)];
|
|
523
|
-
case 2:
|
|
524
|
-
_a.sent();
|
|
525
|
-
expect(loadedUser.derived.salary).toBe(2800);
|
|
526
|
-
expect(loadedUser.derived.id).toBe('user4');
|
|
527
|
-
return [2 /*return*/];
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
}); });
|
|
531
|
-
it('should save a reference when declared @persistentAt as array', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
532
|
-
var loadedUser;
|
|
533
|
-
return __generator(this, function (_a) {
|
|
534
|
-
switch (_a.label) {
|
|
535
|
-
case 0: return [4 /*yield*/, model.findById(testUser.id)];
|
|
536
|
-
case 1:
|
|
537
|
-
loadedUser = _a.sent();
|
|
538
|
-
expect(loadedUser.manyDerived[0].id).toEqual(testUser.manyDerived[0].id);
|
|
539
|
-
expect(loadedUser.manyDerived[0].salary).toBeUndefined();
|
|
540
|
-
expect(loadedUser.manyDerived[1].salary).toBeUndefined();
|
|
541
|
-
return [4 /*yield*/, entropic_bond_1.Store.populate(loadedUser.manyDerived)];
|
|
542
|
-
case 2:
|
|
543
|
-
_a.sent();
|
|
544
|
-
expect(loadedUser.manyDerived[0].salary).toBe(990);
|
|
545
|
-
expect(loadedUser.manyDerived[0].id).toBe(testUser.manyDerived[0].id);
|
|
546
|
-
expect(loadedUser.manyDerived[1].salary).toBe(1990);
|
|
547
|
-
expect(loadedUser.manyDerived[1].id).toBe(testUser.manyDerived[1].id);
|
|
548
|
-
return [2 /*return*/];
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
}); });
|
|
552
|
-
it('should not overwrite not filled ref in collection', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
553
|
-
var loadedUser, refInCollection;
|
|
554
|
-
return __generator(this, function (_a) {
|
|
555
|
-
switch (_a.label) {
|
|
556
|
-
case 0: return [4 /*yield*/, model.findById('user6')];
|
|
557
|
-
case 1:
|
|
558
|
-
loadedUser = _a.sent();
|
|
559
|
-
return [4 /*yield*/, model.save(loadedUser)];
|
|
560
|
-
case 2:
|
|
561
|
-
_a.sent();
|
|
562
|
-
return [4 /*yield*/, model.findById('user4')];
|
|
563
|
-
case 3:
|
|
564
|
-
refInCollection = _a.sent();
|
|
565
|
-
expect(refInCollection.salary).toBe(2800);
|
|
566
|
-
return [2 /*return*/];
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
}); });
|
|
570
|
-
it('should save loaded ref with assigned new instance', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
571
|
-
var loadedUser, refInCollection;
|
|
572
|
-
return __generator(this, function (_a) {
|
|
573
|
-
switch (_a.label) {
|
|
574
|
-
case 0: return [4 /*yield*/, model.findById('user6')];
|
|
575
|
-
case 1:
|
|
576
|
-
loadedUser = _a.sent();
|
|
577
|
-
loadedUser.derived = new test_user_1.DerivedUser();
|
|
578
|
-
loadedUser.derived.salary = 345;
|
|
579
|
-
return [4 /*yield*/, model.save(loadedUser)];
|
|
580
|
-
case 2:
|
|
581
|
-
_a.sent();
|
|
582
|
-
return [4 /*yield*/, model.findById(loadedUser.derived.id)];
|
|
583
|
-
case 3:
|
|
584
|
-
refInCollection = _a.sent();
|
|
585
|
-
expect(refInCollection.salary).toBe(345);
|
|
586
|
-
return [2 /*return*/];
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
}); });
|
|
590
|
-
it('should save loaded ref with modified ref data', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
591
|
-
var loadedUser, refInCollection;
|
|
592
|
-
return __generator(this, function (_a) {
|
|
593
|
-
switch (_a.label) {
|
|
594
|
-
case 0: return [4 /*yield*/, model.findById('user6')];
|
|
595
|
-
case 1:
|
|
596
|
-
loadedUser = _a.sent();
|
|
597
|
-
return [4 /*yield*/, entropic_bond_1.Store.populate(loadedUser.derived)];
|
|
598
|
-
case 2:
|
|
599
|
-
_a.sent();
|
|
600
|
-
loadedUser.derived.salary = 1623;
|
|
601
|
-
return [4 /*yield*/, model.save(loadedUser)];
|
|
602
|
-
case 3:
|
|
603
|
-
_a.sent();
|
|
604
|
-
return [4 /*yield*/, model.findById('user4')];
|
|
605
|
-
case 4:
|
|
606
|
-
refInCollection = _a.sent();
|
|
607
|
-
expect(refInCollection.salary).toBe(1623);
|
|
608
|
-
return [2 /*return*/];
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
}); });
|
|
182
|
+
describe('References to documents', () => {
|
|
183
|
+
let ref1, ref2;
|
|
184
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
+
testUser.documentRef = new test_user_1.SubClass();
|
|
186
|
+
testUser.documentRef.year = 2045;
|
|
187
|
+
ref1 = new test_user_1.SubClass();
|
|
188
|
+
ref1.year = 2081;
|
|
189
|
+
ref2 = new test_user_1.SubClass();
|
|
190
|
+
ref2.year = 2082;
|
|
191
|
+
testUser.manyRefs.push(ref1);
|
|
192
|
+
testUser.manyRefs.push(ref2);
|
|
193
|
+
testUser.derived = new test_user_1.DerivedUser();
|
|
194
|
+
testUser.derived.salary = 1350;
|
|
195
|
+
testUser.manyDerived = [new test_user_1.DerivedUser(), new test_user_1.DerivedUser()];
|
|
196
|
+
testUser.manyDerived[0].salary = 990;
|
|
197
|
+
testUser.manyDerived[1].salary = 1990;
|
|
198
|
+
yield model.save(testUser);
|
|
199
|
+
}));
|
|
200
|
+
it('should save a document as a reference', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
+
const subClassModel = entropic_bond_1.Store.getModel('SubClass');
|
|
202
|
+
expect(subClassModel).toBeDefined();
|
|
203
|
+
const newDocument = yield subClassModel.findById(testUser.documentRef.id);
|
|
204
|
+
expect(newDocument).toBeInstanceOf(test_user_1.SubClass);
|
|
205
|
+
expect(newDocument.year).toBe(2045);
|
|
206
|
+
}));
|
|
207
|
+
it('should read a swallow document reference', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
+
const loadedUser = yield model.findById(testUser.id);
|
|
209
|
+
expect(loadedUser.documentRef).toBeInstanceOf(test_user_1.SubClass);
|
|
210
|
+
expect(loadedUser.documentRef.id).toBeDefined();
|
|
211
|
+
expect(loadedUser.documentRef.year).toBeUndefined();
|
|
212
|
+
}));
|
|
213
|
+
it('should fill data of swallow document reference', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
214
|
+
const loadedUser = yield model.findById(testUser.id);
|
|
215
|
+
yield entropic_bond_1.Store.populate(loadedUser.documentRef);
|
|
216
|
+
expect(loadedUser.documentRef.id).toBeDefined();
|
|
217
|
+
expect(loadedUser.documentRef.year).toBe(2045);
|
|
218
|
+
}));
|
|
219
|
+
it('should save and array of references', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
220
|
+
const subClassModel = entropic_bond_1.Store.getModel('SubClass');
|
|
221
|
+
const newDocument = yield subClassModel.findById(testUser.documentRef.id);
|
|
222
|
+
expect(newDocument).toBeInstanceOf(test_user_1.SubClass);
|
|
223
|
+
expect(newDocument.year).toBe(2045);
|
|
224
|
+
}));
|
|
225
|
+
it('should read an array of references', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
226
|
+
const loadedUser = yield model.findById(testUser.id);
|
|
227
|
+
expect(loadedUser.manyRefs).toHaveLength(2);
|
|
228
|
+
expect(loadedUser.manyRefs[0]).toBeInstanceOf(test_user_1.SubClass);
|
|
229
|
+
expect(loadedUser.manyRefs[0].id).toEqual(testUser.manyRefs[0].id);
|
|
230
|
+
expect(loadedUser.manyRefs[0].year).toBeUndefined();
|
|
231
|
+
expect(loadedUser.manyRefs[1]).toBeInstanceOf(test_user_1.SubClass);
|
|
232
|
+
expect(loadedUser.manyRefs[1].id).toEqual(testUser.manyRefs[1].id);
|
|
233
|
+
expect(loadedUser.manyRefs[1].year).toBeUndefined();
|
|
234
|
+
}));
|
|
235
|
+
it('should fill array of refs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
236
|
+
const loadedUser = yield model.findById(testUser.id);
|
|
237
|
+
yield entropic_bond_1.Store.populate(loadedUser.manyRefs);
|
|
238
|
+
expect(loadedUser.manyRefs[0].year).toBe(2081);
|
|
239
|
+
expect(loadedUser.manyRefs[1].year).toBe(2082);
|
|
240
|
+
}));
|
|
241
|
+
it('should save a reference when declared @persistentAt', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
242
|
+
const loadedUser = yield model.findById(testUser.id);
|
|
243
|
+
expect(loadedUser.derived.id).toEqual(testUser.derived.id);
|
|
244
|
+
expect(loadedUser.derived.salary).toBeUndefined();
|
|
245
|
+
yield entropic_bond_1.Store.populate(loadedUser.derived);
|
|
246
|
+
expect(loadedUser.derived.salary).toBe(1350);
|
|
247
|
+
expect(loadedUser.derived.id).toBe(testUser.derived.id);
|
|
248
|
+
}));
|
|
249
|
+
it('should populate from special collection when declared with @persistentRefAt', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
250
|
+
const loadedUser = yield model.findById('user6');
|
|
251
|
+
yield entropic_bond_1.Store.populate(loadedUser.derived);
|
|
252
|
+
expect(loadedUser.derived.salary).toBe(2800);
|
|
253
|
+
expect(loadedUser.derived.id).toBe('user4');
|
|
254
|
+
}));
|
|
255
|
+
it('should save a reference when declared @persistentAt as array', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
256
|
+
const loadedUser = yield model.findById(testUser.id);
|
|
257
|
+
expect(loadedUser.manyDerived[0].id).toEqual(testUser.manyDerived[0].id);
|
|
258
|
+
expect(loadedUser.manyDerived[0].salary).toBeUndefined();
|
|
259
|
+
expect(loadedUser.manyDerived[1].salary).toBeUndefined();
|
|
260
|
+
yield entropic_bond_1.Store.populate(loadedUser.manyDerived);
|
|
261
|
+
expect(loadedUser.manyDerived[0].salary).toBe(990);
|
|
262
|
+
expect(loadedUser.manyDerived[0].id).toBe(testUser.manyDerived[0].id);
|
|
263
|
+
expect(loadedUser.manyDerived[1].salary).toBe(1990);
|
|
264
|
+
expect(loadedUser.manyDerived[1].id).toBe(testUser.manyDerived[1].id);
|
|
265
|
+
}));
|
|
266
|
+
it('should not overwrite not filled ref in collection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
267
|
+
const loadedUser = yield model.findById('user6');
|
|
268
|
+
yield model.save(loadedUser);
|
|
269
|
+
const refInCollection = yield model.findById('user4');
|
|
270
|
+
expect(refInCollection.salary).toBe(2800);
|
|
271
|
+
}));
|
|
272
|
+
it('should save loaded ref with assigned new instance', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
273
|
+
const loadedUser = yield model.findById('user6');
|
|
274
|
+
loadedUser.derived = new test_user_1.DerivedUser();
|
|
275
|
+
loadedUser.derived.salary = 345;
|
|
276
|
+
yield model.save(loadedUser);
|
|
277
|
+
const refInCollection = yield model.findById(loadedUser.derived.id);
|
|
278
|
+
expect(refInCollection.salary).toBe(345);
|
|
279
|
+
}));
|
|
280
|
+
it('should save loaded ref with modified ref data', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
+
const loadedUser = yield model.findById('user6');
|
|
282
|
+
yield entropic_bond_1.Store.populate(loadedUser.derived);
|
|
283
|
+
loadedUser.derived.salary = 1623;
|
|
284
|
+
yield model.save(loadedUser);
|
|
285
|
+
const refInCollection = yield model.findById('user4');
|
|
286
|
+
expect(refInCollection.salary).toBe(1623);
|
|
287
|
+
}));
|
|
612
288
|
});
|
|
613
|
-
describe('Operations on queries',
|
|
614
|
-
it('should limit the result set',
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
})
|
|
630
|
-
it('should sort
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
var docs;
|
|
658
|
-
return __generator(this, function (_a) {
|
|
659
|
-
switch (_a.label) {
|
|
660
|
-
case 0: return [4 /*yield*/, model.find().orderByDeepProp('name.firstName', 'desc').get()];
|
|
661
|
-
case 1:
|
|
662
|
-
docs = _a.sent();
|
|
663
|
-
expect(docs[0].id).toEqual('user6');
|
|
664
|
-
expect(docs[1].id).toEqual('user5');
|
|
665
|
-
return [2 /*return*/];
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
}); });
|
|
669
|
-
it('should sort by swallow property path', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
670
|
-
var docs;
|
|
671
|
-
return __generator(this, function (_a) {
|
|
672
|
-
switch (_a.label) {
|
|
673
|
-
case 0: return [4 /*yield*/, model.find().orderByDeepProp('age').get()];
|
|
674
|
-
case 1:
|
|
675
|
-
docs = _a.sent();
|
|
676
|
-
expect(docs[0].id).toEqual('user2');
|
|
677
|
-
expect(docs[1].id).toEqual('user1');
|
|
678
|
-
return [2 /*return*/];
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
}); });
|
|
682
|
-
describe('Data Cursors', function () {
|
|
683
|
-
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
684
|
-
return __generator(this, function (_a) {
|
|
685
|
-
switch (_a.label) {
|
|
686
|
-
case 0: return [4 /*yield*/, model.find().get(2)];
|
|
687
|
-
case 1:
|
|
688
|
-
_a.sent();
|
|
689
|
-
return [2 /*return*/];
|
|
690
|
-
}
|
|
691
|
-
});
|
|
692
|
-
}); });
|
|
693
|
-
it('should get next result set', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
694
|
-
var docs, mockDataArr;
|
|
695
|
-
return __generator(this, function (_a) {
|
|
696
|
-
switch (_a.label) {
|
|
697
|
-
case 0: return [4 /*yield*/, model.next()];
|
|
698
|
-
case 1:
|
|
699
|
-
docs = _a.sent();
|
|
700
|
-
mockDataArr = Object.values(mock_data_json_1.default.TestUser);
|
|
701
|
-
expect(docs).toHaveLength(2);
|
|
702
|
-
expect(docs[0].id).toEqual(mockDataArr[2].id);
|
|
703
|
-
expect(docs[0].id).toEqual('user3');
|
|
704
|
-
return [2 /*return*/];
|
|
705
|
-
}
|
|
706
|
-
});
|
|
707
|
-
}); });
|
|
708
|
-
it('should not go beyond the end of result set', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
709
|
-
var docs;
|
|
710
|
-
return __generator(this, function (_a) {
|
|
711
|
-
switch (_a.label) {
|
|
712
|
-
case 0: return [4 /*yield*/, model.next()];
|
|
713
|
-
case 1:
|
|
714
|
-
_a.sent();
|
|
715
|
-
return [4 /*yield*/, model.next()];
|
|
716
|
-
case 2:
|
|
717
|
-
_a.sent();
|
|
718
|
-
return [4 /*yield*/, model.next()];
|
|
719
|
-
case 3:
|
|
720
|
-
docs = _a.sent();
|
|
721
|
-
expect(docs).toHaveLength(0);
|
|
722
|
-
return [2 /*return*/];
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
}); });
|
|
289
|
+
describe('Operations on queries', () => {
|
|
290
|
+
it('should limit the result set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
291
|
+
const unlimited = yield model.find().get();
|
|
292
|
+
const limited = yield model.find().limit(2).get();
|
|
293
|
+
expect(unlimited.length).not.toBe(limited.length);
|
|
294
|
+
expect(limited).toHaveLength(2);
|
|
295
|
+
}));
|
|
296
|
+
it('should sort ascending the result set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
297
|
+
const docs = yield model.find().orderBy('age').get();
|
|
298
|
+
expect(docs[0].id).toEqual('user2');
|
|
299
|
+
expect(docs[1].id).toEqual('user1');
|
|
300
|
+
}));
|
|
301
|
+
it('should sort descending the result set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
|
+
const docs = yield model.find().orderBy('age', 'desc').get();
|
|
303
|
+
expect(docs[0].id).toEqual('user3');
|
|
304
|
+
expect(docs[1].id).toEqual('user5');
|
|
305
|
+
}));
|
|
306
|
+
it('should sort by deep property path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
|
+
const docs = yield model.find().orderByDeepProp('name.firstName', 'desc').get();
|
|
308
|
+
expect(docs[0].id).toEqual('user6');
|
|
309
|
+
expect(docs[1].id).toEqual('user5');
|
|
310
|
+
}));
|
|
311
|
+
it('should sort by swallow property path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
312
|
+
const docs = yield model.find().orderByDeepProp('age').get();
|
|
313
|
+
expect(docs[0].id).toEqual('user2');
|
|
314
|
+
expect(docs[1].id).toEqual('user1');
|
|
315
|
+
}));
|
|
316
|
+
describe('Data Cursors', () => {
|
|
317
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
318
|
+
yield model.find().get(2);
|
|
319
|
+
}));
|
|
320
|
+
it('should get next result set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
321
|
+
const docs = yield model.next();
|
|
322
|
+
const mockDataArr = Object.values(mock_data_json_1.default.TestUser);
|
|
323
|
+
expect(docs).toHaveLength(2);
|
|
324
|
+
expect(docs[0].id).toEqual(mockDataArr[2].id);
|
|
325
|
+
expect(docs[0].id).toEqual('user3');
|
|
326
|
+
}));
|
|
327
|
+
it('should not go beyond the end of result set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
328
|
+
yield model.next();
|
|
329
|
+
yield model.next();
|
|
330
|
+
const docs = yield model.next();
|
|
331
|
+
expect(docs).toHaveLength(0);
|
|
332
|
+
}));
|
|
726
333
|
});
|
|
727
334
|
});
|
|
728
335
|
});
|