entropic-bond 1.40.5 → 1.40.7
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/auth-mock.js +15 -29
- package/lib/auth/auth-mock.js.map +1 -1
- package/lib/auth/auth-mock.spec.js +29 -35
- package/lib/auth/auth-mock.spec.js.map +1 -1
- package/lib/cloud-functions/cloud-functions-mock.spec.js +32 -41
- package/lib/cloud-functions/cloud-functions-mock.spec.js.map +1 -1
- package/lib/cloud-functions/cloud-functions.js +3 -12
- package/lib/cloud-functions/cloud-functions.js.map +1 -1
- package/lib/cloud-storage/cloud-storage.spec.js +49 -58
- package/lib/cloud-storage/cloud-storage.spec.js.map +1 -1
- package/lib/cloud-storage/stored-file.js +20 -33
- package/lib/cloud-storage/stored-file.js.map +1 -1
- package/lib/observable/observable.d.ts +12 -0
- package/lib/observable/observable.js +17 -3
- package/lib/observable/observable.js.map +1 -1
- package/lib/observable/observable.spec.js +7 -0
- package/lib/observable/observable.spec.js.map +1 -1
- package/lib/persistent/persistent.js +21 -7
- package/lib/persistent/persistent.js.map +1 -1
- package/lib/persistent/persistent.spec.js +18 -28
- package/lib/persistent/persistent.spec.js.map +1 -1
- package/lib/server-auth/server-auth-mock.js +6 -2
- package/lib/server-auth/server-auth-mock.js.map +1 -1
- package/lib/server-auth/server-auth-mock.spec.js +14 -23
- package/lib/server-auth/server-auth-mock.spec.js.map +1 -1
- package/lib/store/json-data-source.d.ts +8 -0
- package/lib/store/json-data-source.js +26 -1
- package/lib/store/json-data-source.js.map +1 -1
- package/lib/store/json-data-source.spec.js +40 -27
- package/lib/store/json-data-source.spec.js.map +1 -1
- package/lib/store/model.js +5 -1
- package/lib/store/model.js.map +1 -1
- package/lib/store/model.spec.js +181 -190
- package/lib/store/model.spec.js.map +1 -1
- package/lib/store/store.js +20 -31
- package/lib/store/store.js.map +1 -1
- package/lib/store/store.spec.js +4 -13
- package/lib/store/store.spec.js.map +1 -1
- package/package.json +3 -3
package/lib/store/model.spec.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -21,7 +12,7 @@ describe('Model', () => {
|
|
|
21
12
|
let model;
|
|
22
13
|
let testUser;
|
|
23
14
|
const rawData = () => store_1.Store.dataSource.rawData;
|
|
24
|
-
beforeEach(() =>
|
|
15
|
+
beforeEach(async () => {
|
|
25
16
|
store_1.Store.useDataSource(new json_data_source_1.JsonDataSource(JSON.parse(JSON.stringify(mock_data_json_1.default))));
|
|
26
17
|
testUser = new test_user_1.TestUser();
|
|
27
18
|
testUser.name = {
|
|
@@ -32,17 +23,17 @@ describe('Model', () => {
|
|
|
32
23
|
testUser.age = 35;
|
|
33
24
|
testUser.skills = ['lazy', 'dirty'];
|
|
34
25
|
model = store_1.Store.getModel('TestUser');
|
|
35
|
-
})
|
|
26
|
+
});
|
|
36
27
|
it('should get model from class name string and class instance', () => {
|
|
37
28
|
expect(store_1.Store.getModel(testUser).collectionName).toEqual(model.collectionName);
|
|
38
29
|
expect(model.collectionName).toEqual('TestUser');
|
|
39
30
|
});
|
|
40
|
-
it('should find document by id', () =>
|
|
41
|
-
const user =
|
|
31
|
+
it('should find document by id', async () => {
|
|
32
|
+
const user = await model.findById('user1');
|
|
42
33
|
expect(user).toBeInstanceOf(test_user_1.TestUser);
|
|
43
34
|
expect(user.id).toEqual('user1');
|
|
44
35
|
expect(user.name.firstName).toEqual('userFirstName1');
|
|
45
|
-
})
|
|
36
|
+
});
|
|
46
37
|
it('should not throw if a document id doesn\'t exists', (done) => {
|
|
47
38
|
expect(() => {
|
|
48
39
|
model.findById('nonExistingId')
|
|
@@ -50,18 +41,18 @@ describe('Model', () => {
|
|
|
50
41
|
.catch(done);
|
|
51
42
|
}).not.toThrow();
|
|
52
43
|
});
|
|
53
|
-
it('should return undefined if a document id doesn\'t exists', () =>
|
|
54
|
-
expect(
|
|
55
|
-
})
|
|
56
|
-
it('should return empty array if no document matches condition', () =>
|
|
57
|
-
expect(
|
|
58
|
-
})
|
|
59
|
-
it('should return all documents if no where specified', () =>
|
|
60
|
-
const docs =
|
|
44
|
+
it('should return undefined if a document id doesn\'t exists', async () => {
|
|
45
|
+
expect(await model.findById('nonExistingId')).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
it('should return empty array if no document matches condition', async () => {
|
|
48
|
+
expect(await model.find().where('age', '<', 0).get()).toHaveLength(0);
|
|
49
|
+
});
|
|
50
|
+
it('should return all documents if no where specified', async () => {
|
|
51
|
+
const docs = await model.find().get();
|
|
61
52
|
expect(docs.length).toBeGreaterThan(1);
|
|
62
|
-
})
|
|
63
|
-
it('should write a document', () =>
|
|
64
|
-
|
|
53
|
+
});
|
|
54
|
+
it('should write a document', async () => {
|
|
55
|
+
await model.save(testUser);
|
|
65
56
|
expect(rawData()['TestUser'][testUser.id]).toEqual(expect.objectContaining({
|
|
66
57
|
name: {
|
|
67
58
|
firstName: 'testUserFirstName',
|
|
@@ -69,15 +60,15 @@ describe('Model', () => {
|
|
|
69
60
|
ancestorName: {}
|
|
70
61
|
}
|
|
71
62
|
}));
|
|
72
|
-
})
|
|
73
|
-
it('should delete a document by id', () =>
|
|
63
|
+
});
|
|
64
|
+
it('should delete a document by id', async () => {
|
|
74
65
|
expect(rawData()['TestUser']['user1']).toBeDefined();
|
|
75
|
-
|
|
66
|
+
await model.delete('user1');
|
|
76
67
|
expect(rawData()['TestUser']['user1']).toBeUndefined();
|
|
77
|
-
})
|
|
68
|
+
});
|
|
78
69
|
describe('Generic find', () => {
|
|
79
|
-
it('should query all admins with query object', () =>
|
|
80
|
-
const admins =
|
|
70
|
+
it('should query all admins with query object', async () => {
|
|
71
|
+
const admins = await model.query({
|
|
81
72
|
operations: [{
|
|
82
73
|
property: 'admin',
|
|
83
74
|
operator: '==',
|
|
@@ -86,27 +77,27 @@ describe('Model', () => {
|
|
|
86
77
|
});
|
|
87
78
|
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
88
79
|
expect(admins).toHaveLength(2);
|
|
89
|
-
})
|
|
90
|
-
it('should query by instance', () =>
|
|
91
|
-
expect(
|
|
92
|
-
expect(
|
|
93
|
-
expect(
|
|
94
|
-
})
|
|
95
|
-
it('should find all admins with where methods', () =>
|
|
96
|
-
const admins =
|
|
80
|
+
});
|
|
81
|
+
it('should query by instance', async () => {
|
|
82
|
+
expect(await model.query({})).toHaveLength(6);
|
|
83
|
+
expect(await model.query({}, new test_user_1.DerivedUser())).toHaveLength(1);
|
|
84
|
+
expect(await model.query({}, 'TestUser')).toHaveLength(5);
|
|
85
|
+
});
|
|
86
|
+
it('should find all admins with where methods', async () => {
|
|
87
|
+
const admins = await model.find().where('admin', '==', true).get();
|
|
97
88
|
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
98
89
|
expect(admins).toHaveLength(2);
|
|
99
|
-
})
|
|
100
|
-
it('should find admins with age less than 56', () =>
|
|
101
|
-
const admins =
|
|
90
|
+
});
|
|
91
|
+
it('should find admins with age less than 56', async () => {
|
|
92
|
+
const admins = await model.find()
|
|
102
93
|
.where('admin', '==', true)
|
|
103
94
|
.where('age', '<', 50)
|
|
104
95
|
.get();
|
|
105
96
|
expect(admins).toHaveLength(1);
|
|
106
97
|
expect(admins[0].age).toBeLessThan(50);
|
|
107
|
-
})
|
|
108
|
-
it('should query by subproperties', () =>
|
|
109
|
-
const users =
|
|
98
|
+
});
|
|
99
|
+
it('should query by subproperties', async () => {
|
|
100
|
+
const users = await model.query({
|
|
110
101
|
operations: [
|
|
111
102
|
{
|
|
112
103
|
property: 'name',
|
|
@@ -117,63 +108,63 @@ describe('Model', () => {
|
|
|
117
108
|
]
|
|
118
109
|
});
|
|
119
110
|
expect(users[0].id).toBe('user3');
|
|
120
|
-
})
|
|
121
|
-
it('should find by subproperties', () =>
|
|
122
|
-
const users =
|
|
111
|
+
});
|
|
112
|
+
it('should find by subproperties', async () => {
|
|
113
|
+
const users = await model.find()
|
|
123
114
|
.where('name', '==', { firstName: 'userFirstName3' })
|
|
124
115
|
.get();
|
|
125
116
|
expect(users[0].id).toBe('user3');
|
|
126
|
-
})
|
|
127
|
-
it('should find by property path', () =>
|
|
128
|
-
const users =
|
|
117
|
+
});
|
|
118
|
+
it('should find by property path', async () => {
|
|
119
|
+
const users = await model.find()
|
|
129
120
|
.whereDeepProp('name.firstName', '==', 'userFirstName3')
|
|
130
121
|
.get();
|
|
131
122
|
expect(users[0].id).toBe('user3');
|
|
132
|
-
})
|
|
133
|
-
it('should find by superdeep property path', () =>
|
|
134
|
-
const users =
|
|
123
|
+
});
|
|
124
|
+
it('should find by superdeep property path', async () => {
|
|
125
|
+
const users = await model.find()
|
|
135
126
|
.whereDeepProp('name.ancestorName.father', '==', 'user3Father')
|
|
136
127
|
.get();
|
|
137
128
|
expect(users[0].id).toEqual('user3');
|
|
138
|
-
})
|
|
139
|
-
it('should find by swallow property path', () =>
|
|
140
|
-
const users =
|
|
129
|
+
});
|
|
130
|
+
it('should find by swallow property path', async () => {
|
|
131
|
+
const users = await model.find()
|
|
141
132
|
.whereDeepProp('age', '==', 21)
|
|
142
133
|
.get();
|
|
143
134
|
expect(users[0].id).toEqual('user2');
|
|
144
|
-
})
|
|
145
|
-
it('should return the whole collection on undefined query object', () =>
|
|
146
|
-
const users =
|
|
135
|
+
});
|
|
136
|
+
it('should return the whole collection on undefined query object', async () => {
|
|
137
|
+
const users = await model.query();
|
|
147
138
|
expect(users).toHaveLength(6);
|
|
148
|
-
})
|
|
149
|
-
it('should return the whole collection on empty query object', () =>
|
|
150
|
-
const users =
|
|
139
|
+
});
|
|
140
|
+
it('should return the whole collection on empty query object', async () => {
|
|
141
|
+
const users = await model.query({});
|
|
151
142
|
expect(users).toHaveLength(6);
|
|
152
|
-
})
|
|
143
|
+
});
|
|
153
144
|
});
|
|
154
145
|
describe('Derived classes should fit on parent collection', () => {
|
|
155
|
-
it('should save derived object in parent collection', () =>
|
|
146
|
+
it('should save derived object in parent collection', async () => {
|
|
156
147
|
const derived = new test_user_1.DerivedUser();
|
|
157
148
|
derived.name = { firstName: 'Fulanito', lastName: 'Derived', ancestorName: {} };
|
|
158
149
|
derived.salary = 3900;
|
|
159
|
-
|
|
150
|
+
await model.save(derived);
|
|
160
151
|
expect(rawData()['TestUser'][derived.id]['salary']).toBe(3900);
|
|
161
152
|
expect(rawData()['TestUser'][derived.id]['__className']).toEqual('DerivedUser');
|
|
162
|
-
})
|
|
163
|
-
it('should retrieve derived object by id ', () =>
|
|
164
|
-
const derived =
|
|
153
|
+
});
|
|
154
|
+
it('should retrieve derived object by id ', async () => {
|
|
155
|
+
const derived = await model.findById('user4');
|
|
165
156
|
expect(derived).toBeInstanceOf(test_user_1.DerivedUser);
|
|
166
157
|
expect(derived.salary).toBe(2800);
|
|
167
|
-
})
|
|
168
|
-
it('should find instances of derived classes', () =>
|
|
169
|
-
const derived =
|
|
158
|
+
});
|
|
159
|
+
it('should find instances of derived classes', async () => {
|
|
160
|
+
const derived = await model.find().instanceOf('DerivedUser').get();
|
|
170
161
|
expect(derived[0]).toBeInstanceOf(test_user_1.DerivedUser);
|
|
171
162
|
expect(derived[0].salary).toBe(2800);
|
|
172
|
-
})
|
|
163
|
+
});
|
|
173
164
|
});
|
|
174
165
|
describe('References to documents', () => {
|
|
175
166
|
let ref1, ref2;
|
|
176
|
-
beforeEach(() =>
|
|
167
|
+
beforeEach(async () => {
|
|
177
168
|
testUser.documentRef = new test_user_1.SubClass();
|
|
178
169
|
testUser.documentRef.year = 2045;
|
|
179
170
|
ref1 = new test_user_1.SubClass();
|
|
@@ -187,35 +178,35 @@ describe('Model', () => {
|
|
|
187
178
|
testUser.manyDerived = [new test_user_1.DerivedUser(), new test_user_1.DerivedUser()];
|
|
188
179
|
testUser.manyDerived[0].salary = 990;
|
|
189
180
|
testUser.manyDerived[1].salary = 1990;
|
|
190
|
-
|
|
191
|
-
})
|
|
192
|
-
it('should save a document as a reference', () =>
|
|
181
|
+
await model.save(testUser);
|
|
182
|
+
});
|
|
183
|
+
it('should save a document as a reference', async () => {
|
|
193
184
|
expect(rawData()['SubClass']).toBeDefined();
|
|
194
185
|
expect(rawData()['SubClass'][testUser.documentRef.id]).toEqual(expect.objectContaining({
|
|
195
186
|
__className: 'SubClass',
|
|
196
187
|
year: 2045
|
|
197
188
|
}));
|
|
198
|
-
})
|
|
199
|
-
it('should read a swallow document reference', () =>
|
|
200
|
-
const loadedUser =
|
|
189
|
+
});
|
|
190
|
+
it('should read a swallow document reference', async () => {
|
|
191
|
+
const loadedUser = await model.findById(testUser.id);
|
|
201
192
|
expect(loadedUser.documentRef).toBeInstanceOf(test_user_1.SubClass);
|
|
202
193
|
expect(loadedUser.documentRef.id).toBeDefined();
|
|
203
194
|
expect(loadedUser.documentRef.year).toBeUndefined();
|
|
204
|
-
})
|
|
205
|
-
it('should fill data of swallow document reference', () =>
|
|
206
|
-
const loadedUser =
|
|
207
|
-
|
|
195
|
+
});
|
|
196
|
+
it('should fill data of swallow document reference', async () => {
|
|
197
|
+
const loadedUser = await model.findById(testUser.id);
|
|
198
|
+
await store_1.Store.populate(loadedUser.documentRef);
|
|
208
199
|
expect(loadedUser.documentRef.id).toBeDefined();
|
|
209
200
|
expect(loadedUser.documentRef.year).toBe(2045);
|
|
210
|
-
})
|
|
201
|
+
});
|
|
211
202
|
it('should save and array of references', () => {
|
|
212
203
|
expect(rawData()['SubClass'][ref1.id]).toBeDefined();
|
|
213
204
|
expect(rawData()['SubClass'][ref1.id]['year']).toBe(2081);
|
|
214
205
|
expect(rawData()['SubClass'][ref2.id]).toBeDefined();
|
|
215
206
|
expect(rawData()['SubClass'][ref2.id]['year']).toBe(2082);
|
|
216
207
|
});
|
|
217
|
-
it('should read an array of references', () =>
|
|
218
|
-
const loadedUser =
|
|
208
|
+
it('should read an array of references', async () => {
|
|
209
|
+
const loadedUser = await model.findById(testUser.id);
|
|
219
210
|
expect(loadedUser.manyRefs).toHaveLength(2);
|
|
220
211
|
expect(loadedUser.manyRefs[0]).toBeInstanceOf(test_user_1.SubClass);
|
|
221
212
|
expect(loadedUser.manyRefs[0].id).toEqual(testUser.manyRefs[0].id);
|
|
@@ -223,168 +214,168 @@ describe('Model', () => {
|
|
|
223
214
|
expect(loadedUser.manyRefs[1]).toBeInstanceOf(test_user_1.SubClass);
|
|
224
215
|
expect(loadedUser.manyRefs[1].id).toEqual(testUser.manyRefs[1].id);
|
|
225
216
|
expect(loadedUser.manyRefs[1].year).toBeUndefined();
|
|
226
|
-
})
|
|
227
|
-
it('should fill array of refs', () =>
|
|
228
|
-
const loadedUser =
|
|
229
|
-
|
|
217
|
+
});
|
|
218
|
+
it('should fill array of refs', async () => {
|
|
219
|
+
const loadedUser = await model.findById(testUser.id);
|
|
220
|
+
await store_1.Store.populate(loadedUser.manyRefs);
|
|
230
221
|
expect(loadedUser.manyRefs[0].year).toBe(2081);
|
|
231
222
|
expect(loadedUser.manyRefs[1].year).toBe(2082);
|
|
232
|
-
})
|
|
233
|
-
it('should save a reference when declared @persistentAt', () =>
|
|
234
|
-
const loadedUser =
|
|
223
|
+
});
|
|
224
|
+
it('should save a reference when declared @persistentAt', async () => {
|
|
225
|
+
const loadedUser = await model.findById(testUser.id);
|
|
235
226
|
expect(loadedUser.derived.id).toEqual(testUser.derived.id);
|
|
236
227
|
expect(loadedUser.derived.salary).toBeUndefined();
|
|
237
|
-
|
|
228
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
238
229
|
expect(loadedUser.derived.salary).toBe(1350);
|
|
239
230
|
expect(loadedUser.derived.id).toBe(testUser.derived.id);
|
|
240
|
-
})
|
|
241
|
-
it('should populate from special collection when declared with @persistentRefAt', () =>
|
|
242
|
-
const loadedUser =
|
|
243
|
-
|
|
231
|
+
});
|
|
232
|
+
it('should populate from special collection when declared with @persistentRefAt', async () => {
|
|
233
|
+
const loadedUser = await model.findById('user6');
|
|
234
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
244
235
|
expect(loadedUser.derived.salary).toBe(2800);
|
|
245
236
|
expect(loadedUser.derived.id).toBe('user4');
|
|
246
|
-
})
|
|
247
|
-
it('should save a reference when declared @persistentAt as array', () =>
|
|
248
|
-
const loadedUser =
|
|
237
|
+
});
|
|
238
|
+
it('should save a reference when declared @persistentAt as array', async () => {
|
|
239
|
+
const loadedUser = await model.findById(testUser.id);
|
|
249
240
|
expect(loadedUser.manyDerived[0].id).toEqual(testUser.manyDerived[0].id);
|
|
250
241
|
expect(loadedUser.manyDerived[0].salary).toBeUndefined();
|
|
251
242
|
expect(loadedUser.manyDerived[1].salary).toBeUndefined();
|
|
252
|
-
|
|
243
|
+
await store_1.Store.populate(loadedUser.manyDerived);
|
|
253
244
|
expect(loadedUser.manyDerived[0].salary).toBe(990);
|
|
254
245
|
expect(loadedUser.manyDerived[0].id).toBe(testUser.manyDerived[0].id);
|
|
255
246
|
expect(loadedUser.manyDerived[1].salary).toBe(1990);
|
|
256
247
|
expect(loadedUser.manyDerived[1].id).toBe(testUser.manyDerived[1].id);
|
|
257
|
-
})
|
|
258
|
-
it('should not overwrite not filled ref in collection', () =>
|
|
259
|
-
const loadedUser =
|
|
260
|
-
|
|
261
|
-
const refInCollection =
|
|
248
|
+
});
|
|
249
|
+
it('should not overwrite not filled ref in collection', async () => {
|
|
250
|
+
const loadedUser = await model.findById('user6');
|
|
251
|
+
await model.save(loadedUser);
|
|
252
|
+
const refInCollection = await model.findById('user4');
|
|
262
253
|
expect(refInCollection.salary).toBe(2800);
|
|
263
|
-
})
|
|
264
|
-
it('should save loaded ref with assigned new instance', () =>
|
|
265
|
-
const loadedUser =
|
|
254
|
+
});
|
|
255
|
+
it('should save loaded ref with assigned new instance', async () => {
|
|
256
|
+
const loadedUser = await model.findById('user6');
|
|
266
257
|
loadedUser.derived = new test_user_1.DerivedUser();
|
|
267
258
|
loadedUser.derived.salary = 345;
|
|
268
|
-
|
|
269
|
-
const refInCollection =
|
|
259
|
+
await model.save(loadedUser);
|
|
260
|
+
const refInCollection = await model.findById(loadedUser.derived.id);
|
|
270
261
|
expect(refInCollection.salary).toBe(345);
|
|
271
|
-
})
|
|
272
|
-
it('should save loaded ref with modified ref data', () =>
|
|
273
|
-
const loadedUser =
|
|
274
|
-
|
|
262
|
+
});
|
|
263
|
+
it('should save loaded ref with modified ref data', async () => {
|
|
264
|
+
const loadedUser = await model.findById('user6');
|
|
265
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
275
266
|
loadedUser.derived.salary = 1623;
|
|
276
|
-
|
|
277
|
-
const refInCollection =
|
|
267
|
+
await model.save(loadedUser);
|
|
268
|
+
const refInCollection = await model.findById('user4');
|
|
278
269
|
expect(refInCollection.salary).toBe(1623);
|
|
279
|
-
})
|
|
280
|
-
it('should find by object ref', () =>
|
|
281
|
-
const loadedDerived =
|
|
282
|
-
const loadedUser =
|
|
270
|
+
});
|
|
271
|
+
it('should find by object ref', async () => {
|
|
272
|
+
const loadedDerived = await model.findById('user4');
|
|
273
|
+
const loadedUser = await model.find().where('derived', '==', loadedDerived).get();
|
|
283
274
|
expect(loadedUser[0].id).toEqual('user6');
|
|
284
|
-
})
|
|
285
|
-
it('should not throw on calling populate several times on same object', () =>
|
|
286
|
-
const loadedUser =
|
|
287
|
-
|
|
275
|
+
});
|
|
276
|
+
it('should not throw on calling populate several times on same object', async () => {
|
|
277
|
+
const loadedUser = await model.findById('user6');
|
|
278
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
288
279
|
expect(loadedUser.derived['_documentRef']).not.toBeDefined();
|
|
289
280
|
let thrown = false;
|
|
290
281
|
try {
|
|
291
|
-
|
|
282
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
292
283
|
}
|
|
293
284
|
catch (err) {
|
|
294
285
|
thrown = true;
|
|
295
286
|
}
|
|
296
287
|
expect(thrown).toBeFalsy();
|
|
297
|
-
})
|
|
298
|
-
it('should not throw on populating undefined instances', () =>
|
|
299
|
-
const loadedUser =
|
|
288
|
+
});
|
|
289
|
+
it('should not throw on populating undefined instances', async () => {
|
|
290
|
+
const loadedUser = await model.findById('user6');
|
|
300
291
|
loadedUser.derived = undefined;
|
|
301
292
|
let thrown = false;
|
|
302
293
|
try {
|
|
303
|
-
|
|
294
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
304
295
|
}
|
|
305
296
|
catch (err) {
|
|
306
297
|
thrown = true;
|
|
307
298
|
}
|
|
308
299
|
expect(thrown).toBeFalsy();
|
|
309
|
-
})
|
|
310
|
-
it('should not throw on populating non existing reference', () =>
|
|
311
|
-
const loadedUser =
|
|
300
|
+
});
|
|
301
|
+
it('should not throw on populating non existing reference', async () => {
|
|
302
|
+
const loadedUser = await model.findById('user6');
|
|
312
303
|
loadedUser.derived['_id'] = 'non-existing';
|
|
313
304
|
let thrown = false;
|
|
314
305
|
try {
|
|
315
|
-
|
|
306
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
316
307
|
}
|
|
317
308
|
catch (err) {
|
|
318
309
|
thrown = true;
|
|
319
310
|
}
|
|
320
311
|
expect(thrown).toBeFalsy();
|
|
321
|
-
})
|
|
322
|
-
it('should remove deleted references when populating from the returned array', () =>
|
|
323
|
-
const loadedUser =
|
|
312
|
+
});
|
|
313
|
+
it('should remove deleted references when populating from the returned array', async () => {
|
|
314
|
+
const loadedUser = await model.findById(testUser.id);
|
|
324
315
|
const deletedId = loadedUser.manyDerived[0].id;
|
|
325
|
-
|
|
326
|
-
const manyDerived =
|
|
316
|
+
await model.delete(deletedId);
|
|
317
|
+
const manyDerived = await store_1.Store.populate(loadedUser.manyDerived);
|
|
327
318
|
expect(manyDerived[0].id).not.toBe(deletedId);
|
|
328
319
|
expect(manyDerived).toHaveLength(1);
|
|
329
|
-
})
|
|
330
|
-
it('should report if populated for single reference', () =>
|
|
331
|
-
const loadedUser =
|
|
320
|
+
});
|
|
321
|
+
it('should report if populated for single reference', async () => {
|
|
322
|
+
const loadedUser = await model.findById('user6');
|
|
332
323
|
expect(store_1.Store.isPopulated(loadedUser.derived)).toBeFalsy();
|
|
333
|
-
|
|
324
|
+
await store_1.Store.populate(loadedUser.derived);
|
|
334
325
|
expect(store_1.Store.isPopulated(loadedUser.derived)).toBeTruthy();
|
|
335
|
-
})
|
|
336
|
-
it('should report if populated for multiple references', () =>
|
|
337
|
-
const loadedUser =
|
|
326
|
+
});
|
|
327
|
+
it('should report if populated for multiple references', async () => {
|
|
328
|
+
const loadedUser = await model.findById(testUser.id);
|
|
338
329
|
expect(store_1.Store.isPopulated(loadedUser.manyDerived)).toBeFalsy();
|
|
339
|
-
|
|
330
|
+
await store_1.Store.populate(loadedUser.manyDerived);
|
|
340
331
|
expect(store_1.Store.isPopulated(loadedUser.manyDerived)).toBeTruthy();
|
|
341
|
-
})
|
|
332
|
+
});
|
|
342
333
|
});
|
|
343
334
|
describe('Operations on queries', () => {
|
|
344
|
-
it('should limit the result set', () =>
|
|
345
|
-
const unlimited =
|
|
346
|
-
const limited =
|
|
335
|
+
it('should limit the result set', async () => {
|
|
336
|
+
const unlimited = await model.find().get();
|
|
337
|
+
const limited = await model.find().limit(2).get();
|
|
347
338
|
expect(unlimited.length).not.toBe(limited.length);
|
|
348
339
|
expect(limited).toHaveLength(2);
|
|
349
|
-
})
|
|
350
|
-
it('should sort ascending the result set', () =>
|
|
351
|
-
const docs =
|
|
340
|
+
});
|
|
341
|
+
it('should sort ascending the result set', async () => {
|
|
342
|
+
const docs = await model.find().orderBy('age').get();
|
|
352
343
|
expect(docs[0].id).toEqual('user2');
|
|
353
344
|
expect(docs[1].id).toEqual('user1');
|
|
354
|
-
})
|
|
355
|
-
it('should sort descending the result set', () =>
|
|
356
|
-
const docs =
|
|
345
|
+
});
|
|
346
|
+
it('should sort descending the result set', async () => {
|
|
347
|
+
const docs = await model.find().orderBy('age', 'desc').get();
|
|
357
348
|
expect(docs[0].id).toEqual('user3');
|
|
358
349
|
expect(docs[1].id).toEqual('user5');
|
|
359
|
-
})
|
|
360
|
-
it('should sort by deep property path', () =>
|
|
361
|
-
const docs =
|
|
350
|
+
});
|
|
351
|
+
it('should sort by deep property path', async () => {
|
|
352
|
+
const docs = await model.find().orderByDeepProp('name.firstName', 'desc').get();
|
|
362
353
|
expect(docs[0].id).toEqual('user6');
|
|
363
354
|
expect(docs[1].id).toEqual('user5');
|
|
364
|
-
})
|
|
365
|
-
it('should sort by swallow property path', () =>
|
|
366
|
-
const docs =
|
|
355
|
+
});
|
|
356
|
+
it('should sort by swallow property path', async () => {
|
|
357
|
+
const docs = await model.find().orderByDeepProp('age').get();
|
|
367
358
|
expect(docs[0].id).toEqual('user2');
|
|
368
359
|
expect(docs[1].id).toEqual('user1');
|
|
369
|
-
})
|
|
370
|
-
it('should count the documents in the collection', () =>
|
|
371
|
-
expect(
|
|
372
|
-
})
|
|
360
|
+
});
|
|
361
|
+
it('should count the documents in the collection', async () => {
|
|
362
|
+
expect(await model.find().count()).toBe(6);
|
|
363
|
+
});
|
|
373
364
|
describe('Data Cursors', () => {
|
|
374
|
-
beforeEach(() =>
|
|
375
|
-
|
|
376
|
-
})
|
|
377
|
-
it('should get next result set', () =>
|
|
378
|
-
const docs =
|
|
365
|
+
beforeEach(async () => {
|
|
366
|
+
await model.find().get(2);
|
|
367
|
+
});
|
|
368
|
+
it('should get next result set', async () => {
|
|
369
|
+
const docs = await model.next();
|
|
379
370
|
expect(docs).toHaveLength(2);
|
|
380
371
|
expect(docs[0].id).toEqual('user3');
|
|
381
|
-
})
|
|
382
|
-
it('should not go beyond the end of result set', () =>
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const docs =
|
|
372
|
+
});
|
|
373
|
+
it('should not go beyond the end of result set', async () => {
|
|
374
|
+
await model.next();
|
|
375
|
+
await model.next();
|
|
376
|
+
const docs = await model.next();
|
|
386
377
|
expect(docs).toHaveLength(0);
|
|
387
|
-
})
|
|
378
|
+
});
|
|
388
379
|
});
|
|
389
380
|
});
|
|
390
381
|
describe('Utility methods', () => {
|
|
@@ -415,26 +406,26 @@ describe('Model', () => {
|
|
|
415
406
|
});
|
|
416
407
|
describe('SubCollections', () => {
|
|
417
408
|
let subCollectionModel;
|
|
418
|
-
beforeEach(() =>
|
|
419
|
-
const user =
|
|
409
|
+
beforeEach(async () => {
|
|
410
|
+
const user = await model.findById('user1');
|
|
420
411
|
subCollectionModel = store_1.Store.getModelForSubCollection(user, 'SubClass');
|
|
421
|
-
})
|
|
412
|
+
});
|
|
422
413
|
it('should get model for subCollection', () => {
|
|
423
414
|
const model = store_1.Store.getModelForSubCollection(testUser, 'SubClass');
|
|
424
415
|
expect(model.collectionName).toEqual(`TestUser/${testUser.id}/SubClass`);
|
|
425
416
|
});
|
|
426
|
-
it('should find subCollection document by id', () =>
|
|
427
|
-
const subClass =
|
|
417
|
+
it('should find subCollection document by id', async () => {
|
|
418
|
+
const subClass = await subCollectionModel.findById('subClass1');
|
|
428
419
|
expect(subClass).toBeInstanceOf(test_user_1.SubClass);
|
|
429
420
|
expect(subClass.year).toBe(1326);
|
|
430
|
-
})
|
|
431
|
-
it('should save data to subCollection', () =>
|
|
421
|
+
});
|
|
422
|
+
it('should save data to subCollection', async () => {
|
|
432
423
|
const subClass = new test_user_1.SubClass();
|
|
433
424
|
subClass.year = 3452;
|
|
434
|
-
|
|
435
|
-
const loaded =
|
|
425
|
+
await subCollectionModel.save(subClass);
|
|
426
|
+
const loaded = await subCollectionModel.findById(subClass.id);
|
|
436
427
|
expect(loaded.year).toBe(3452);
|
|
437
|
-
})
|
|
428
|
+
});
|
|
438
429
|
});
|
|
439
430
|
it('should pass Type tests', () => {
|
|
440
431
|
//@ts-expect-error
|