@entropic-bond/firebase 1.7.9 → 1.8.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 +3 -3
- package/lib/auth/firebase-auth.js +54 -41
- package/lib/auth/firebase-auth.js.map +1 -1
- package/lib/cloud-functions/firebase-cloud-functions.d.ts +1 -1
- package/lib/cloud-functions/firebase-cloud-functions.js +3 -14
- package/lib/cloud-functions/firebase-cloud-functions.js.map +1 -1
- package/lib/cloud-functions/firebase-cloud-functions.spec.d.ts +2 -2
- package/lib/cloud-functions/firebase-cloud-functions.spec.js +6 -15
- package/lib/cloud-functions/firebase-cloud-functions.spec.js.map +1 -1
- package/lib/cloud-storage/firebase-cloud-storage.js +14 -9
- package/lib/cloud-storage/firebase-cloud-storage.js.map +1 -1
- package/lib/cloud-storage/firebase-cloud-storage.spec.js +36 -44
- package/lib/cloud-storage/firebase-cloud-storage.spec.js.map +1 -1
- package/lib/firebase-helper.d.ts +9 -8
- package/lib/firebase-helper.js +17 -13
- package/lib/firebase-helper.js.map +1 -1
- package/lib/mocks/test-user.d.ts +18 -18
- package/lib/mocks/test-user.js.map +1 -1
- package/lib/store/firebase-datasource.d.ts +2 -0
- package/lib/store/firebase-datasource.js +31 -29
- package/lib/store/firebase-datasource.js.map +1 -1
- package/lib/store/firebase-datasource.spec.js +234 -222
- package/lib/store/firebase-datasource.spec.js.map +1 -1
- package/package.json +10 -10
|
@@ -1,44 +1,34 @@
|
|
|
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
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
16
6
|
const entropic_bond_1 = require("entropic-bond");
|
|
17
7
|
const firebase_datasource_1 = require("./firebase-datasource");
|
|
18
8
|
const firebase_helper_1 = require("../firebase-helper");
|
|
19
9
|
const test_user_1 = require("../mocks/test-user");
|
|
20
10
|
const mock_data_json_1 = __importDefault(require("../mocks/mock-data.json"));
|
|
21
|
-
const
|
|
22
|
-
function loadTestData(model) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
promises.push(model.save(user));
|
|
29
|
-
}
|
|
30
|
-
yield Promise.all(promises);
|
|
31
|
-
});
|
|
11
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
+
async function loadTestData(model) {
|
|
13
|
+
const users = Object.values(mock_data_json_1.default.TestUser);
|
|
14
|
+
await Promise.all(users.map(userObj => {
|
|
15
|
+
const user = entropic_bond_1.Persistent.createInstance(userObj);
|
|
16
|
+
return model.save(user);
|
|
17
|
+
}));
|
|
32
18
|
}
|
|
33
19
|
describe('Firestore Model', () => {
|
|
34
20
|
let model;
|
|
35
21
|
let testUser;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const host = 'localhost';
|
|
23
|
+
const firestorePort = 9080;
|
|
24
|
+
beforeAll(() => {
|
|
25
|
+
firebase_helper_1.FirebaseHelper.setFirebaseConfig({
|
|
26
|
+
projectId: "demo-test",
|
|
27
|
+
});
|
|
28
|
+
firebase_helper_1.FirebaseHelper.useEmulator({ host, firestorePort });
|
|
41
29
|
entropic_bond_1.Store.useDataSource(new firebase_datasource_1.FirebaseDatasource());
|
|
30
|
+
});
|
|
31
|
+
beforeEach(async () => {
|
|
42
32
|
testUser = new test_user_1.TestUser();
|
|
43
33
|
testUser.name = {
|
|
44
34
|
firstName: 'testUserFirstName',
|
|
@@ -47,37 +37,37 @@ describe('Firestore Model', () => {
|
|
|
47
37
|
testUser.age = 35;
|
|
48
38
|
testUser.skills = ['lazy', 'dirty'];
|
|
49
39
|
model = entropic_bond_1.Store.getModel('TestUser');
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
afterEach(() =>
|
|
53
|
-
|
|
54
|
-
yield (0, node_fetch_1.default)('http://localhost:9080/emulator/v1/projects/demo-test/databases/(default)/documents', {
|
|
40
|
+
await loadTestData(model);
|
|
41
|
+
});
|
|
42
|
+
afterEach(async () => {
|
|
43
|
+
await (0, node_fetch_1.default)(`http://${host}:${firestorePort}/emulator/v1/projects/demo-test/databases/(default)/documents`, {
|
|
55
44
|
method: 'DELETE'
|
|
56
45
|
});
|
|
57
|
-
})
|
|
58
|
-
it('should find document by id', () =>
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
});
|
|
47
|
+
it('should find document by id', async () => {
|
|
48
|
+
var _a;
|
|
49
|
+
await model.save(testUser);
|
|
50
|
+
const user = await model.findById(testUser.id);
|
|
61
51
|
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', () =>
|
|
66
|
-
|
|
67
|
-
const newUser =
|
|
68
|
-
expect(newUser.name).toEqual({
|
|
52
|
+
expect(user === null || user === void 0 ? void 0 : user.id).toEqual(testUser.id);
|
|
53
|
+
expect((_a = user === null || user === void 0 ? void 0 : user.name) === null || _a === void 0 ? void 0 : _a.firstName).toEqual('testUserFirstName');
|
|
54
|
+
});
|
|
55
|
+
it('should write a document', async () => {
|
|
56
|
+
await model.save(testUser);
|
|
57
|
+
const newUser = await model.findById(testUser.id);
|
|
58
|
+
expect(newUser === null || newUser === void 0 ? void 0 : newUser.name).toEqual({
|
|
69
59
|
firstName: 'testUserFirstName',
|
|
70
60
|
lastName: 'testUserLastName'
|
|
71
61
|
});
|
|
72
|
-
})
|
|
73
|
-
it('should delete a document by id', () =>
|
|
74
|
-
|
|
75
|
-
const newUser =
|
|
76
|
-
expect(newUser.age).toBe(35);
|
|
77
|
-
|
|
78
|
-
const deletedUser =
|
|
62
|
+
});
|
|
63
|
+
it('should delete a document by id', async () => {
|
|
64
|
+
await model.save(testUser);
|
|
65
|
+
const newUser = await model.findById(testUser.id);
|
|
66
|
+
expect(newUser === null || newUser === void 0 ? void 0 : newUser.age).toBe(35);
|
|
67
|
+
await model.delete(testUser.id);
|
|
68
|
+
const deletedUser = await model.findById(testUser.id);
|
|
79
69
|
expect(deletedUser).toBeUndefined();
|
|
80
|
-
})
|
|
70
|
+
});
|
|
81
71
|
it('should not throw if a document id doesn\'t exists', (done) => {
|
|
82
72
|
expect(() => {
|
|
83
73
|
model.findById('nonExistingId')
|
|
@@ -85,28 +75,28 @@ describe('Firestore Model', () => {
|
|
|
85
75
|
.catch(done);
|
|
86
76
|
}).not.toThrow();
|
|
87
77
|
});
|
|
88
|
-
it('should return undefined if a document id doesn\'t exists', () =>
|
|
89
|
-
expect(
|
|
90
|
-
})
|
|
91
|
-
it('should retrieve array fields', () =>
|
|
92
|
-
|
|
93
|
-
const newUser =
|
|
94
|
-
expect(Array.isArray(newUser.skills)).toBeTruthy();
|
|
95
|
-
expect(newUser.skills).toEqual(expect.arrayContaining(['lazy', 'dirty']));
|
|
96
|
-
})
|
|
97
|
-
it('should retrieve object fields', () =>
|
|
98
|
-
|
|
99
|
-
const newUser =
|
|
100
|
-
expect(newUser.name).toEqual({
|
|
78
|
+
it('should return undefined if a document id doesn\'t exists', async () => {
|
|
79
|
+
expect(await model.findById('nonExistingId')).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
it('should retrieve array fields', async () => {
|
|
82
|
+
await model.save(testUser);
|
|
83
|
+
const newUser = await model.findById(testUser.id);
|
|
84
|
+
expect(Array.isArray(newUser === null || newUser === void 0 ? void 0 : newUser.skills)).toBeTruthy();
|
|
85
|
+
expect(newUser === null || newUser === void 0 ? void 0 : newUser.skills).toEqual(expect.arrayContaining(['lazy', 'dirty']));
|
|
86
|
+
});
|
|
87
|
+
it('should retrieve object fields', async () => {
|
|
88
|
+
await model.save(testUser);
|
|
89
|
+
const newUser = await model.findById(testUser.id);
|
|
90
|
+
expect(newUser === null || newUser === void 0 ? void 0 : newUser.name).toEqual({
|
|
101
91
|
firstName: 'testUserFirstName',
|
|
102
92
|
lastName: 'testUserLastName'
|
|
103
93
|
});
|
|
104
|
-
})
|
|
94
|
+
});
|
|
105
95
|
describe('Generic find', () => {
|
|
106
|
-
it('should query all admins with query object', () =>
|
|
96
|
+
it('should query all admins with query object', async () => {
|
|
107
97
|
testUser.admin = true;
|
|
108
|
-
|
|
109
|
-
const admins =
|
|
98
|
+
await model.save(testUser);
|
|
99
|
+
const admins = await model.query({
|
|
110
100
|
operations: [{
|
|
111
101
|
property: 'admin',
|
|
112
102
|
operator: '==',
|
|
@@ -115,22 +105,24 @@ describe('Firestore Model', () => {
|
|
|
115
105
|
});
|
|
116
106
|
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
117
107
|
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
118
|
-
})
|
|
119
|
-
it('should find all admins with where methods', () =>
|
|
120
|
-
const admins =
|
|
108
|
+
});
|
|
109
|
+
it('should find all admins with where methods', async () => {
|
|
110
|
+
const admins = await model.find().where('admin', '==', true).get();
|
|
121
111
|
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
122
112
|
expect(admins[0]).toBeInstanceOf(test_user_1.TestUser);
|
|
123
|
-
})
|
|
124
|
-
it('should find admins with age less than 56', () =>
|
|
125
|
-
|
|
113
|
+
});
|
|
114
|
+
it('should find admins with age less than 56', async () => {
|
|
115
|
+
var _a;
|
|
116
|
+
const admins = await model.find()
|
|
126
117
|
.where('admin', '==', true)
|
|
127
118
|
.where('age', '<', 50)
|
|
128
119
|
.get();
|
|
129
120
|
expect(admins.length).toBeGreaterThanOrEqual(1);
|
|
130
|
-
expect(admins[0].age).toBeLessThan(50);
|
|
131
|
-
})
|
|
132
|
-
it('should query by subproperties', () =>
|
|
133
|
-
|
|
121
|
+
expect((_a = admins[0]) === null || _a === void 0 ? void 0 : _a.age).toBeLessThan(50);
|
|
122
|
+
});
|
|
123
|
+
it('should query by subproperties', async () => {
|
|
124
|
+
var _a;
|
|
125
|
+
const users = await model.query({
|
|
134
126
|
operations: [
|
|
135
127
|
{
|
|
136
128
|
property: 'name',
|
|
@@ -140,48 +132,52 @@ describe('Firestore Model', () => {
|
|
|
140
132
|
{ property: 'age', operator: '!=', value: 134 }
|
|
141
133
|
]
|
|
142
134
|
});
|
|
143
|
-
expect(users[0].id).toBe('user3');
|
|
144
|
-
})
|
|
145
|
-
it('should find by subproperties', () =>
|
|
146
|
-
|
|
135
|
+
expect((_a = users[0]) === null || _a === void 0 ? void 0 : _a.id).toBe('user3');
|
|
136
|
+
});
|
|
137
|
+
it('should find by subproperties', async () => {
|
|
138
|
+
var _a;
|
|
139
|
+
const users = await model.find()
|
|
147
140
|
.where('name', '==', { firstName: 'userFirstName3' })
|
|
148
141
|
.get();
|
|
149
|
-
expect(users[0].id).toBe('user3');
|
|
150
|
-
})
|
|
151
|
-
it('should find by property path', () =>
|
|
152
|
-
|
|
142
|
+
expect((_a = users[0]) === null || _a === void 0 ? void 0 : _a.id).toBe('user3');
|
|
143
|
+
});
|
|
144
|
+
it('should find by property path', async () => {
|
|
145
|
+
var _a;
|
|
146
|
+
const users = await model.find()
|
|
153
147
|
.whereDeepProp('name.firstName', '==', 'userFirstName3')
|
|
154
148
|
.get();
|
|
155
|
-
expect(users[0].id).toBe('user3');
|
|
156
|
-
})
|
|
157
|
-
it('should find by superdeep property path', () =>
|
|
158
|
-
|
|
149
|
+
expect((_a = users[0]) === null || _a === void 0 ? void 0 : _a.id).toBe('user3');
|
|
150
|
+
});
|
|
151
|
+
it('should find by superdeep property path', async () => {
|
|
152
|
+
var _a;
|
|
153
|
+
const users = await model.find()
|
|
159
154
|
.whereDeepProp('name.ancestorName.father', '==', 'user3Father')
|
|
160
155
|
.get();
|
|
161
|
-
expect(users[0].id).toEqual('user3');
|
|
162
|
-
})
|
|
163
|
-
it('should find by swallow property path', () =>
|
|
164
|
-
|
|
156
|
+
expect((_a = users[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual('user3');
|
|
157
|
+
});
|
|
158
|
+
it('should find by swallow property path', async () => {
|
|
159
|
+
var _a;
|
|
160
|
+
const users = await model.find()
|
|
165
161
|
.whereDeepProp('age', '==', 21)
|
|
166
162
|
.get();
|
|
167
|
-
expect(users[0].id).toEqual('user2');
|
|
168
|
-
})
|
|
163
|
+
expect((_a = users[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual('user2');
|
|
164
|
+
});
|
|
169
165
|
});
|
|
170
166
|
describe('Derived classes should fit on parent collection', () => {
|
|
171
|
-
it('should save derived object in parent collection', () =>
|
|
167
|
+
it('should save derived object in parent collection', async () => {
|
|
172
168
|
const derived = new test_user_1.DerivedUser();
|
|
173
169
|
derived.name = { firstName: 'Fulanito', lastName: 'Derived' };
|
|
174
170
|
derived.salary = 3900;
|
|
175
|
-
|
|
176
|
-
const newUser =
|
|
171
|
+
await model.save(derived);
|
|
172
|
+
const newUser = await model.findById(derived.id);
|
|
177
173
|
expect(newUser).toBeInstanceOf(test_user_1.DerivedUser);
|
|
178
174
|
expect(newUser.salary).toBe(3900);
|
|
179
175
|
expect(newUser.className).toEqual('DerivedUser');
|
|
180
|
-
})
|
|
176
|
+
});
|
|
181
177
|
});
|
|
182
178
|
describe('References to documents', () => {
|
|
183
179
|
let ref1, ref2;
|
|
184
|
-
beforeEach(() =>
|
|
180
|
+
beforeEach(async () => {
|
|
185
181
|
testUser.documentRef = new test_user_1.SubClass();
|
|
186
182
|
testUser.documentRef.year = 2045;
|
|
187
183
|
ref1 = new test_user_1.SubClass();
|
|
@@ -195,141 +191,157 @@ describe('Firestore Model', () => {
|
|
|
195
191
|
testUser.manyDerived = [new test_user_1.DerivedUser(), new test_user_1.DerivedUser()];
|
|
196
192
|
testUser.manyDerived[0].salary = 990;
|
|
197
193
|
testUser.manyDerived[1].salary = 1990;
|
|
198
|
-
|
|
199
|
-
})
|
|
200
|
-
it('should save a document as a reference', () =>
|
|
194
|
+
await model.save(testUser);
|
|
195
|
+
});
|
|
196
|
+
it('should save a document as a reference', async () => {
|
|
201
197
|
const subClassModel = entropic_bond_1.Store.getModel('SubClass');
|
|
202
198
|
expect(subClassModel).toBeDefined();
|
|
203
|
-
const newDocument =
|
|
199
|
+
const newDocument = await subClassModel.findById(testUser.documentRef.id);
|
|
204
200
|
expect(newDocument).toBeInstanceOf(test_user_1.SubClass);
|
|
205
201
|
expect(newDocument.year).toBe(2045);
|
|
206
|
-
})
|
|
207
|
-
it('should read a swallow document reference', () =>
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
expect(loadedUser.documentRef
|
|
211
|
-
expect(loadedUser.documentRef.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
202
|
+
});
|
|
203
|
+
it('should read a swallow document reference', async () => {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
const loadedUser = await model.findById(testUser.id);
|
|
206
|
+
expect(loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.documentRef).toBeInstanceOf(test_user_1.SubClass);
|
|
207
|
+
expect((_a = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.documentRef) === null || _a === void 0 ? void 0 : _a.id).toBeDefined();
|
|
208
|
+
expect((_b = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.documentRef) === null || _b === void 0 ? void 0 : _b.year).toBeUndefined();
|
|
209
|
+
});
|
|
210
|
+
it('should fill data of swallow document reference', async () => {
|
|
211
|
+
var _a, _b;
|
|
212
|
+
const loadedUser = await model.findById(testUser.id);
|
|
213
|
+
await entropic_bond_1.Store.populate(loadedUser.documentRef);
|
|
214
|
+
expect((_a = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.documentRef) === null || _a === void 0 ? void 0 : _a.id).toBeDefined();
|
|
215
|
+
expect((_b = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.documentRef) === null || _b === void 0 ? void 0 : _b.year).toBe(2045);
|
|
216
|
+
});
|
|
217
|
+
it('should save and array of references', async () => {
|
|
220
218
|
const subClassModel = entropic_bond_1.Store.getModel('SubClass');
|
|
221
|
-
const newDocument =
|
|
219
|
+
const newDocument = await subClassModel.findById(testUser.documentRef.id);
|
|
222
220
|
expect(newDocument).toBeInstanceOf(test_user_1.SubClass);
|
|
223
221
|
expect(newDocument.year).toBe(2045);
|
|
224
|
-
})
|
|
225
|
-
it('should read an array of references', () =>
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
expect(loadedUser.manyRefs
|
|
229
|
-
expect(loadedUser.manyRefs[0]
|
|
230
|
-
expect(loadedUser.manyRefs[0].
|
|
231
|
-
expect(loadedUser.manyRefs[
|
|
232
|
-
expect(loadedUser.manyRefs[1]
|
|
233
|
-
expect(loadedUser.manyRefs[1].
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
expect(loadedUser.derived.
|
|
247
|
-
expect(loadedUser.derived.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
expect(loadedUser.
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
expect(loadedUser.manyDerived[0].id).
|
|
263
|
-
expect(loadedUser.manyDerived[
|
|
264
|
-
expect(loadedUser.manyDerived[1].
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
222
|
+
});
|
|
223
|
+
it('should read an array of references', async () => {
|
|
224
|
+
var _a, _b, _c, _d, _e, _f;
|
|
225
|
+
const loadedUser = await model.findById(testUser.id);
|
|
226
|
+
expect(loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs).toHaveLength(2);
|
|
227
|
+
expect(loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[0]).toBeInstanceOf(test_user_1.SubClass);
|
|
228
|
+
expect((_a = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual((_b = testUser.manyRefs[0]) === null || _b === void 0 ? void 0 : _b.id);
|
|
229
|
+
expect((_c = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[0]) === null || _c === void 0 ? void 0 : _c.year).toBeUndefined();
|
|
230
|
+
expect(loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[1]).toBeInstanceOf(test_user_1.SubClass);
|
|
231
|
+
expect((_d = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[1]) === null || _d === void 0 ? void 0 : _d.id).toEqual((_e = testUser.manyRefs[1]) === null || _e === void 0 ? void 0 : _e.id);
|
|
232
|
+
expect((_f = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[1]) === null || _f === void 0 ? void 0 : _f.year).toBeUndefined();
|
|
233
|
+
});
|
|
234
|
+
it('should fill array of refs', async () => {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
const loadedUser = await model.findById(testUser.id);
|
|
237
|
+
await entropic_bond_1.Store.populate(loadedUser.manyRefs);
|
|
238
|
+
expect((_a = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[0]) === null || _a === void 0 ? void 0 : _a.year).toBe(2081);
|
|
239
|
+
expect((_b = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyRefs[1]) === null || _b === void 0 ? void 0 : _b.year).toBe(2082);
|
|
240
|
+
});
|
|
241
|
+
it('should save a reference when declared @persistentAt', async () => {
|
|
242
|
+
var _a, _b, _c, _d, _e, _f;
|
|
243
|
+
const loadedUser = await model.findById(testUser.id);
|
|
244
|
+
expect((_a = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.derived) === null || _a === void 0 ? void 0 : _a.id).toEqual((_b = testUser.derived) === null || _b === void 0 ? void 0 : _b.id);
|
|
245
|
+
expect((_c = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.derived) === null || _c === void 0 ? void 0 : _c.salary).toBeUndefined();
|
|
246
|
+
await entropic_bond_1.Store.populate(loadedUser.derived);
|
|
247
|
+
expect((_d = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.derived) === null || _d === void 0 ? void 0 : _d.salary).toBe(1350);
|
|
248
|
+
expect((_e = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.derived) === null || _e === void 0 ? void 0 : _e.id).toBe((_f = testUser.derived) === null || _f === void 0 ? void 0 : _f.id);
|
|
249
|
+
});
|
|
250
|
+
it('should populate from special collection when declared with @persistentRefAt', async () => {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
const loadedUser = await model.findById('user6');
|
|
253
|
+
await entropic_bond_1.Store.populate(loadedUser.derived);
|
|
254
|
+
expect((_a = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.derived) === null || _a === void 0 ? void 0 : _a.salary).toBe(2800);
|
|
255
|
+
expect((_b = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.derived) === null || _b === void 0 ? void 0 : _b.id).toBe('user4');
|
|
256
|
+
});
|
|
257
|
+
it('should save a reference when declared @persistentAt as array', async () => {
|
|
258
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
259
|
+
const loadedUser = await model.findById(testUser.id);
|
|
260
|
+
expect((_b = (_a = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyDerived) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.id).toEqual((_d = (_c = testUser.manyDerived) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.id);
|
|
261
|
+
expect((_f = (_e = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyDerived) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.salary).toBeUndefined();
|
|
262
|
+
expect((_h = (_g = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyDerived) === null || _g === void 0 ? void 0 : _g[1]) === null || _h === void 0 ? void 0 : _h.salary).toBeUndefined();
|
|
263
|
+
await entropic_bond_1.Store.populate(loadedUser.manyDerived);
|
|
264
|
+
expect((_k = (_j = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyDerived) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.salary).toBe(990);
|
|
265
|
+
expect((_m = (_l = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyDerived) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.id).toBe((_p = (_o = testUser.manyDerived) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.id);
|
|
266
|
+
expect((_r = (_q = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyDerived) === null || _q === void 0 ? void 0 : _q[1]) === null || _r === void 0 ? void 0 : _r.salary).toBe(1990);
|
|
267
|
+
expect((_t = (_s = loadedUser === null || loadedUser === void 0 ? void 0 : loadedUser.manyDerived) === null || _s === void 0 ? void 0 : _s[1]) === null || _t === void 0 ? void 0 : _t.id).toBe((_v = (_u = testUser.manyDerived) === null || _u === void 0 ? void 0 : _u[1]) === null || _v === void 0 ? void 0 : _v.id);
|
|
268
|
+
});
|
|
269
|
+
it('should not overwrite not filled ref in collection', async () => {
|
|
270
|
+
const loadedUser = await model.findById('user6');
|
|
271
|
+
await model.save(loadedUser);
|
|
272
|
+
const refInCollection = await model.findById('user4');
|
|
273
|
+
expect(refInCollection === null || refInCollection === void 0 ? void 0 : refInCollection.salary).toBe(2800);
|
|
274
|
+
});
|
|
275
|
+
it('should save loaded ref with assigned new instance', async () => {
|
|
276
|
+
var _a;
|
|
277
|
+
const loadedUser = await model.findById('user6');
|
|
274
278
|
loadedUser.derived = new test_user_1.DerivedUser();
|
|
275
279
|
loadedUser.derived.salary = 345;
|
|
276
|
-
|
|
277
|
-
const refInCollection =
|
|
278
|
-
expect(refInCollection.salary).toBe(345);
|
|
279
|
-
})
|
|
280
|
-
it('should save loaded ref with modified ref data', () =>
|
|
281
|
-
const loadedUser =
|
|
282
|
-
|
|
280
|
+
await model.save(loadedUser);
|
|
281
|
+
const refInCollection = await model.findById((_a = loadedUser.derived) === null || _a === void 0 ? void 0 : _a.id);
|
|
282
|
+
expect(refInCollection === null || refInCollection === void 0 ? void 0 : refInCollection.salary).toBe(345);
|
|
283
|
+
});
|
|
284
|
+
it('should save loaded ref with modified ref data', async () => {
|
|
285
|
+
const loadedUser = await model.findById('user6');
|
|
286
|
+
await entropic_bond_1.Store.populate(loadedUser.derived);
|
|
283
287
|
loadedUser.derived.salary = 1623;
|
|
284
|
-
|
|
285
|
-
const refInCollection =
|
|
286
|
-
expect(refInCollection.salary).toBe(1623);
|
|
287
|
-
})
|
|
288
|
+
await model.save(loadedUser);
|
|
289
|
+
const refInCollection = await model.findById('user4');
|
|
290
|
+
expect(refInCollection === null || refInCollection === void 0 ? void 0 : refInCollection.salary).toBe(1623);
|
|
291
|
+
});
|
|
288
292
|
});
|
|
289
293
|
describe('Operations on queries', () => {
|
|
290
|
-
it('should limit the result set', () =>
|
|
291
|
-
const unlimited =
|
|
292
|
-
const limited =
|
|
294
|
+
it('should limit the result set', async () => {
|
|
295
|
+
const unlimited = await model.find().get();
|
|
296
|
+
const limited = await model.find().limit(2).get();
|
|
293
297
|
expect(unlimited.length).not.toBe(limited.length);
|
|
294
298
|
expect(limited).toHaveLength(2);
|
|
295
|
-
})
|
|
296
|
-
it('should sort ascending the result set', () =>
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
expect(docs[
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
299
|
+
});
|
|
300
|
+
it('should sort ascending the result set', async () => {
|
|
301
|
+
var _a, _b;
|
|
302
|
+
const docs = await model.find().orderBy('age').get();
|
|
303
|
+
expect((_a = docs[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual('user2');
|
|
304
|
+
expect((_b = docs[1]) === null || _b === void 0 ? void 0 : _b.id).toEqual('user1');
|
|
305
|
+
});
|
|
306
|
+
it('should sort descending the result set', async () => {
|
|
307
|
+
var _a, _b;
|
|
308
|
+
const docs = await model.find().orderBy('age', 'desc').get();
|
|
309
|
+
expect((_a = docs[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual('user3');
|
|
310
|
+
expect((_b = docs[1]) === null || _b === void 0 ? void 0 : _b.id).toEqual('user5');
|
|
311
|
+
});
|
|
312
|
+
it('should sort by deep property path', async () => {
|
|
313
|
+
var _a, _b;
|
|
314
|
+
const docs = await model.find().orderByDeepProp('name.firstName', 'desc').get();
|
|
315
|
+
expect((_a = docs[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual('user6');
|
|
316
|
+
expect((_b = docs[1]) === null || _b === void 0 ? void 0 : _b.id).toEqual('user5');
|
|
317
|
+
});
|
|
318
|
+
it('should sort by swallow property path', async () => {
|
|
319
|
+
var _a, _b;
|
|
320
|
+
const docs = await model.find().orderByDeepProp('age').get();
|
|
321
|
+
expect((_a = docs[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual('user2');
|
|
322
|
+
expect((_b = docs[1]) === null || _b === void 0 ? void 0 : _b.id).toEqual('user1');
|
|
323
|
+
});
|
|
324
|
+
it('should count documents in collection', async () => {
|
|
325
|
+
expect(await model.find().count()).toBe(6);
|
|
326
|
+
});
|
|
316
327
|
describe('Data Cursors', () => {
|
|
317
|
-
beforeEach(() =>
|
|
318
|
-
|
|
319
|
-
})
|
|
320
|
-
it('should get next result set', () =>
|
|
321
|
-
|
|
328
|
+
beforeEach(async () => {
|
|
329
|
+
await model.find().get(2);
|
|
330
|
+
});
|
|
331
|
+
it('should get next result set', async () => {
|
|
332
|
+
var _a, _b, _c;
|
|
333
|
+
const docs = await model.next();
|
|
322
334
|
const mockDataArr = Object.values(mock_data_json_1.default.TestUser);
|
|
323
335
|
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', () =>
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const docs =
|
|
336
|
+
expect((_a = docs[0]) === null || _a === void 0 ? void 0 : _a.id).toEqual((_b = mockDataArr[2]) === null || _b === void 0 ? void 0 : _b.id);
|
|
337
|
+
expect((_c = docs[0]) === null || _c === void 0 ? void 0 : _c.id).toEqual('user3');
|
|
338
|
+
});
|
|
339
|
+
it('should not go beyond the end of result set', async () => {
|
|
340
|
+
await model.next();
|
|
341
|
+
await model.next();
|
|
342
|
+
const docs = await model.next();
|
|
331
343
|
expect(docs).toHaveLength(0);
|
|
332
|
-
})
|
|
344
|
+
});
|
|
333
345
|
});
|
|
334
346
|
});
|
|
335
347
|
describe('SubCollections', () => {
|
|
@@ -337,13 +349,13 @@ describe('Firestore Model', () => {
|
|
|
337
349
|
beforeEach(() => {
|
|
338
350
|
model = entropic_bond_1.Store.getModelForSubCollection(testUser, 'SubClass');
|
|
339
351
|
});
|
|
340
|
-
it('should retrieve from subcollection', () =>
|
|
352
|
+
it('should retrieve from subcollection', async () => {
|
|
341
353
|
const subClass = new test_user_1.SubClass();
|
|
342
354
|
subClass.year = 3452;
|
|
343
|
-
|
|
344
|
-
const loaded =
|
|
345
|
-
expect(loaded.year).toBe(3452);
|
|
346
|
-
})
|
|
355
|
+
await model.save(subClass);
|
|
356
|
+
const loaded = await model.findById(subClass.id);
|
|
357
|
+
expect(loaded === null || loaded === void 0 ? void 0 : loaded.year).toBe(3452);
|
|
358
|
+
});
|
|
347
359
|
});
|
|
348
360
|
});
|
|
349
361
|
//# sourceMappingURL=firebase-datasource.spec.js.map
|