@dereekb/firebase 10.2.0 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +1005 -729
- package/index.esm.js +47 -162
- package/package.json +1 -1
- package/src/lib/client/firestore/driver.accessor.batch.d.ts +2 -2
- package/src/lib/client/firestore/driver.accessor.transaction.d.ts +1 -1
- package/src/lib/client/function/model.function.factory.d.ts +0 -10
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +5 -9
- package/src/lib/common/model/function.d.ts +15 -37
- package/src/lib/common/model/model/model.param.d.ts +5 -5
- package/test/CHANGELOG.md +18 -0
- package/test/package.json +1 -1
- package/test/src/lib/client/firebase.js +36 -21
- package/test/src/lib/client/firebase.js.map +1 -1
- package/test/src/lib/common/firebase.instance.js +2 -0
- package/test/src/lib/common/firebase.instance.js.map +1 -1
- package/test/src/lib/common/firestore/firestore.instance.js +1 -0
- package/test/src/lib/common/firestore/firestore.instance.js.map +1 -1
- package/test/src/lib/common/firestore/firestore.js +18 -10
- package/test/src/lib/common/firestore/firestore.js.map +1 -1
- package/test/src/lib/common/firestore/test.driver.accessor.js +273 -277
- package/test/src/lib/common/firestore/test.driver.accessor.js.map +1 -1
- package/test/src/lib/common/firestore/test.driver.query.js +315 -329
- package/test/src/lib/common/firestore/test.driver.query.js.map +1 -1
- package/test/src/lib/common/firestore/test.iterator.js +6 -7
- package/test/src/lib/common/firestore/test.iterator.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +2 -1
- package/test/src/lib/common/mock/mock.item.collection.fixture.js +4 -2
- package/test/src/lib/common/mock/mock.item.collection.fixture.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.service.js +6 -11
- package/test/src/lib/common/mock/mock.item.service.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.storage.fixture.js +2 -1
- package/test/src/lib/common/mock/mock.item.storage.fixture.js.map +1 -1
- package/test/src/lib/common/storage/storage.instance.js +1 -0
- package/test/src/lib/common/storage/storage.instance.js.map +1 -1
- package/test/src/lib/common/storage/storage.js +10 -3
- package/test/src/lib/common/storage/storage.js.map +1 -1
- package/test/src/lib/common/storage/test.driver.accessor.js +132 -133
- package/test/src/lib/common/storage/test.driver.accessor.js.map +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.describeFirestoreDocumentAccessorTests = exports.describeFirestoreAccessorDriverTests = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const test_1 = require("@dereekb/util/test");
|
|
6
5
|
const rxjs_1 = require("rxjs");
|
|
7
6
|
const rxjs_2 = require("@dereekb/rxjs");
|
|
@@ -17,9 +16,9 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
17
16
|
const testDocumentCount = 5;
|
|
18
17
|
let mockItemFirestoreDocumentAccessor;
|
|
19
18
|
let items;
|
|
20
|
-
beforeEach(() =>
|
|
19
|
+
beforeEach(async () => {
|
|
21
20
|
mockItemFirestoreDocumentAccessor = f.instance.firestoreCollection.documentAccessor();
|
|
22
|
-
items =
|
|
21
|
+
items = await (0, firebase_1.makeDocuments)(f.instance.firestoreCollection.documentAccessor(), {
|
|
23
22
|
count: testDocumentCount,
|
|
24
23
|
init: (i) => {
|
|
25
24
|
return {
|
|
@@ -29,7 +28,7 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
30
|
});
|
|
32
|
-
})
|
|
31
|
+
});
|
|
33
32
|
describe('MockItem', () => {
|
|
34
33
|
let itemDocument;
|
|
35
34
|
let accessor;
|
|
@@ -47,63 +46,63 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
47
46
|
loadDocumentForWriteBatch: (writeBatch, ref) => f.instance.firestoreCollection.documentAccessorForWriteBatch(writeBatch).loadDocument(ref)
|
|
48
47
|
}));
|
|
49
48
|
describe('increment()', () => {
|
|
50
|
-
it(`should increase the item's value`, () =>
|
|
51
|
-
let data =
|
|
52
|
-
expect(data
|
|
49
|
+
it(`should increase the item's value`, async () => {
|
|
50
|
+
let data = await itemDocument.snapshotData();
|
|
51
|
+
expect(data?.number).toBe(undefined);
|
|
53
52
|
const update = { number: 3 };
|
|
54
|
-
|
|
55
|
-
data =
|
|
56
|
-
expect(data
|
|
53
|
+
await itemDocument.increment(update);
|
|
54
|
+
data = await itemDocument.snapshotData();
|
|
55
|
+
expect(data?.number).toBe(update.number);
|
|
57
56
|
// increment again
|
|
58
|
-
|
|
59
|
-
data =
|
|
60
|
-
expect(data
|
|
61
|
-
})
|
|
62
|
-
it(`should decrease the item's value`, () =>
|
|
63
|
-
let data =
|
|
64
|
-
expect(data
|
|
57
|
+
await itemDocument.increment(update);
|
|
58
|
+
data = await itemDocument.snapshotData();
|
|
59
|
+
expect(data?.number).toBe(update.number * 2);
|
|
60
|
+
});
|
|
61
|
+
it(`should decrease the item's value`, async () => {
|
|
62
|
+
let data = await itemDocument.snapshotData();
|
|
63
|
+
expect(data?.number).toBe(undefined);
|
|
65
64
|
const update = { number: -3 };
|
|
66
|
-
|
|
67
|
-
data =
|
|
68
|
-
expect(data
|
|
65
|
+
await itemDocument.increment(update);
|
|
66
|
+
data = await itemDocument.snapshotData();
|
|
67
|
+
expect(data?.number).toBe(update.number);
|
|
69
68
|
// increment again
|
|
70
|
-
|
|
71
|
-
data =
|
|
72
|
-
expect(data
|
|
73
|
-
})
|
|
74
|
-
it(`should increase and decrease the item's value`, () =>
|
|
75
|
-
let data =
|
|
76
|
-
expect(data
|
|
69
|
+
await itemDocument.increment(update);
|
|
70
|
+
data = await itemDocument.snapshotData();
|
|
71
|
+
expect(data?.number).toBe(update.number * 2);
|
|
72
|
+
});
|
|
73
|
+
it(`should increase and decrease the item's value`, async () => {
|
|
74
|
+
let data = await itemDocument.snapshotData();
|
|
75
|
+
expect(data?.number).toBe(undefined);
|
|
77
76
|
const update = { number: 3 };
|
|
78
|
-
|
|
77
|
+
await itemDocument.increment(update);
|
|
79
78
|
const update2 = { number: -6 };
|
|
80
|
-
|
|
81
|
-
data =
|
|
82
|
-
expect(data
|
|
83
|
-
})
|
|
79
|
+
await itemDocument.increment(update2);
|
|
80
|
+
data = await itemDocument.snapshotData();
|
|
81
|
+
expect(data?.number).toBe(update.number + update2.number);
|
|
82
|
+
});
|
|
84
83
|
describe('in transaction', () => {
|
|
85
|
-
it(`should increase the item's value`, () =>
|
|
84
|
+
it(`should increase the item's value`, async () => {
|
|
86
85
|
const update = { number: 3 };
|
|
87
|
-
|
|
88
|
-
const itemDocumentInTransaction =
|
|
89
|
-
let data =
|
|
90
|
-
expect(data
|
|
91
|
-
|
|
92
|
-
})
|
|
93
|
-
const result =
|
|
94
|
-
expect(result
|
|
95
|
-
})
|
|
86
|
+
await f.parent.firestoreContext.runTransaction(async (transaction) => {
|
|
87
|
+
const itemDocumentInTransaction = await f.instance.firestoreCollection.documentAccessorForTransaction(transaction).loadDocumentForId(itemDocument.id);
|
|
88
|
+
let data = await itemDocumentInTransaction.snapshotData();
|
|
89
|
+
expect(data?.number).toBe(undefined);
|
|
90
|
+
await itemDocumentInTransaction.increment(update);
|
|
91
|
+
});
|
|
92
|
+
const result = await itemDocument.snapshotData();
|
|
93
|
+
expect(result?.number).toBe(update.number);
|
|
94
|
+
});
|
|
96
95
|
});
|
|
97
96
|
describe('in write batch', () => {
|
|
98
|
-
it(`should increase the item's value`, () =>
|
|
97
|
+
it(`should increase the item's value`, async () => {
|
|
99
98
|
const update = { number: 3 };
|
|
100
99
|
const writeBatch = f.parent.firestoreContext.batch();
|
|
101
|
-
const itemDocumentForWriteBatch =
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const result =
|
|
105
|
-
expect(result
|
|
106
|
-
})
|
|
100
|
+
const itemDocumentForWriteBatch = await f.instance.firestoreCollection.documentAccessorForWriteBatch(writeBatch).loadDocumentForId(itemDocument.id);
|
|
101
|
+
await itemDocumentForWriteBatch.increment(update);
|
|
102
|
+
await writeBatch.commit();
|
|
103
|
+
const result = await itemDocument.snapshotData();
|
|
104
|
+
expect(result?.number).toBe(update.number);
|
|
105
|
+
});
|
|
107
106
|
});
|
|
108
107
|
});
|
|
109
108
|
});
|
|
@@ -121,28 +120,26 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
121
120
|
});
|
|
122
121
|
describe('create()', () => {
|
|
123
122
|
describe('mockItemUserAccessorFactory usage', () => {
|
|
124
|
-
it('should copy the documents identifier to the uid field on create.', () =>
|
|
125
|
-
|
|
126
|
-
yield itemUserDataDocument.accessor.create({
|
|
123
|
+
it('should copy the documents identifier to the uid field on create.', async () => {
|
|
124
|
+
await itemUserDataDocument.accessor.create({
|
|
127
125
|
uid: '',
|
|
128
126
|
name: 'hello'
|
|
129
127
|
});
|
|
130
|
-
const snapshot =
|
|
131
|
-
expect(
|
|
132
|
-
})
|
|
128
|
+
const snapshot = await itemUserDataDocument.accessor.get();
|
|
129
|
+
expect(snapshot.data()?.uid).toBe(testUserId);
|
|
130
|
+
});
|
|
133
131
|
});
|
|
134
132
|
});
|
|
135
133
|
describe('set()', () => {
|
|
136
134
|
describe('mockItemUserAccessorFactory usage', () => {
|
|
137
|
-
it('should copy the documents identifier to the uid field on set.', () =>
|
|
138
|
-
|
|
139
|
-
yield itemUserDataDocument.accessor.set({
|
|
135
|
+
it('should copy the documents identifier to the uid field on set.', async () => {
|
|
136
|
+
await itemUserDataDocument.accessor.set({
|
|
140
137
|
uid: '',
|
|
141
138
|
name: 'hello'
|
|
142
139
|
});
|
|
143
|
-
const snapshot =
|
|
144
|
-
expect(
|
|
145
|
-
})
|
|
140
|
+
const snapshot = await itemUserDataDocument.accessor.get();
|
|
141
|
+
expect(snapshot.data()?.uid).toBe(testUserId);
|
|
142
|
+
});
|
|
146
143
|
});
|
|
147
144
|
});
|
|
148
145
|
});
|
|
@@ -170,45 +167,44 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
170
167
|
});
|
|
171
168
|
});
|
|
172
169
|
describe('get()', () => {
|
|
173
|
-
it('should read that data using the configured converter', () =>
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const dataWithoutConverter = (yield itemPrivateDataDocument.accessor.getWithConverter(null)).data();
|
|
170
|
+
it('should read that data using the configured converter', async () => {
|
|
171
|
+
await itemPrivateDataDocument.accessor.set({ values: null });
|
|
172
|
+
const dataWithoutConverter = (await itemPrivateDataDocument.accessor.getWithConverter(null)).data();
|
|
177
173
|
expect(dataWithoutConverter).toBeDefined();
|
|
178
174
|
expect(dataWithoutConverter.values).toBeNull();
|
|
179
175
|
// converter on client, _converter on server
|
|
180
|
-
expect(
|
|
181
|
-
const data =
|
|
182
|
-
expect(data
|
|
183
|
-
expect(data
|
|
184
|
-
})
|
|
176
|
+
expect(itemPrivateDataDocument.documentRef.converter ?? itemPrivateDataDocument.documentRef._converter).toBeDefined();
|
|
177
|
+
const data = await itemPrivateDataDocument.snapshotData();
|
|
178
|
+
expect(data?.values).toBeDefined();
|
|
179
|
+
expect(data?.values).not.toBeNull(); // should not be null due to the snapshot converter config
|
|
180
|
+
});
|
|
185
181
|
});
|
|
186
182
|
describe('getWithConverter()', () => {
|
|
187
|
-
it('should get the results with the input converter', () =>
|
|
188
|
-
|
|
189
|
-
const data =
|
|
190
|
-
expect(data
|
|
191
|
-
const dataWithoutConverter = (
|
|
183
|
+
it('should get the results with the input converter', async () => {
|
|
184
|
+
await itemPrivateDataDocument.accessor.set({ values: null });
|
|
185
|
+
const data = await itemPrivateDataDocument.snapshotData();
|
|
186
|
+
expect(data?.values).toBeDefined();
|
|
187
|
+
const dataWithoutConverter = (await itemPrivateDataDocument.accessor.getWithConverter(null)).data();
|
|
192
188
|
expect(dataWithoutConverter).toBeDefined();
|
|
193
189
|
expect(dataWithoutConverter.values).toBeNull();
|
|
194
|
-
})
|
|
195
|
-
it('should get the results with the input converter with a type', () =>
|
|
196
|
-
|
|
197
|
-
const data =
|
|
198
|
-
expect(data
|
|
190
|
+
});
|
|
191
|
+
it('should get the results with the input converter with a type', async () => {
|
|
192
|
+
await itemPrivateDataDocument.accessor.set({ values: null });
|
|
193
|
+
const data = await itemPrivateDataDocument.snapshotData();
|
|
194
|
+
expect(data?.values).toBeDefined();
|
|
199
195
|
const converter = mock_1.mockItemConverter;
|
|
200
|
-
const dataWithoutConverter =
|
|
196
|
+
const dataWithoutConverter = await itemPrivateDataDocument.accessor.getWithConverter(converter);
|
|
201
197
|
expect(dataWithoutConverter).toBeDefined();
|
|
202
|
-
})
|
|
198
|
+
});
|
|
203
199
|
});
|
|
204
200
|
describe('update()', () => {
|
|
205
|
-
(0, test_1.itShouldFail)('if the item does not exist', () =>
|
|
206
|
-
const exists =
|
|
201
|
+
(0, test_1.itShouldFail)('if the item does not exist', async () => {
|
|
202
|
+
const exists = await itemPrivateDataDocument.accessor.exists();
|
|
207
203
|
expect(exists).toBe(false);
|
|
208
|
-
|
|
209
|
-
})
|
|
210
|
-
it('should update the item if it exist', () =>
|
|
211
|
-
|
|
204
|
+
await (0, test_1.expectFail)(() => itemPrivateDataDocument.update({ createdAt: new Date() }));
|
|
205
|
+
});
|
|
206
|
+
it('should update the item if it exist', async () => {
|
|
207
|
+
await itemPrivateDataDocument.create({
|
|
212
208
|
createdAt: new Date(),
|
|
213
209
|
num: 0,
|
|
214
210
|
values: [],
|
|
@@ -220,23 +216,23 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
220
216
|
}
|
|
221
217
|
});
|
|
222
218
|
const newDate = new Date(0);
|
|
223
|
-
const exists =
|
|
219
|
+
const exists = await itemPrivateDataDocument.accessor.exists();
|
|
224
220
|
expect(exists).toBe(true);
|
|
225
|
-
|
|
226
|
-
const data =
|
|
227
|
-
expect(data
|
|
221
|
+
await itemPrivateDataDocument.update({ createdAt: newDate });
|
|
222
|
+
const data = await itemPrivateDataDocument.snapshotData();
|
|
223
|
+
expect(data?.createdAt.getTime()).toBe(newDate.getTime());
|
|
228
224
|
// check was not modified
|
|
229
|
-
expect(data
|
|
230
|
-
expect(data
|
|
231
|
-
expect(data
|
|
232
|
-
expect(data
|
|
233
|
-
})
|
|
225
|
+
expect(data?.settings['test'].north).toBe(true);
|
|
226
|
+
expect(data?.settings['test'].south).toBe(true);
|
|
227
|
+
expect(data?.settings['test'].east).toBeUndefined();
|
|
228
|
+
expect(data?.settings['test'].west).toBeUndefined();
|
|
229
|
+
});
|
|
234
230
|
});
|
|
235
231
|
describe('set()', () => {
|
|
236
|
-
it('should create the item', () =>
|
|
237
|
-
let exists =
|
|
232
|
+
it('should create the item', async () => {
|
|
233
|
+
let exists = await privateDataAccessor.exists();
|
|
238
234
|
expect(exists).toBe(false);
|
|
239
|
-
|
|
235
|
+
await privateDataAccessor.set({
|
|
240
236
|
values: [],
|
|
241
237
|
num: 0,
|
|
242
238
|
createdAt: new Date(),
|
|
@@ -246,23 +242,23 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
246
242
|
}
|
|
247
243
|
}
|
|
248
244
|
});
|
|
249
|
-
exists =
|
|
245
|
+
exists = await privateDataAccessor.exists();
|
|
250
246
|
expect(exists).toBe(true);
|
|
251
|
-
})
|
|
247
|
+
});
|
|
252
248
|
});
|
|
253
249
|
describe('with item', () => {
|
|
254
|
-
beforeEach(() =>
|
|
255
|
-
|
|
256
|
-
})
|
|
250
|
+
beforeEach(async () => {
|
|
251
|
+
await privateDataAccessor.set({ num: 0, values: [], createdAt: new Date(), settings: {} });
|
|
252
|
+
});
|
|
257
253
|
describe('increment()', () => {
|
|
258
|
-
it(`should increase the item's value`, () =>
|
|
259
|
-
let data =
|
|
260
|
-
expect(data
|
|
254
|
+
it(`should increase the item's value`, async () => {
|
|
255
|
+
let data = await itemPrivateDataDocument.snapshotData();
|
|
256
|
+
expect(data?.num).toBe(0);
|
|
261
257
|
const update = { num: 3 };
|
|
262
|
-
|
|
263
|
-
data =
|
|
264
|
-
expect(data
|
|
265
|
-
})
|
|
258
|
+
await itemPrivateDataDocument.increment(update);
|
|
259
|
+
data = await itemPrivateDataDocument.snapshotData();
|
|
260
|
+
expect(data?.num).toBe(update.num);
|
|
261
|
+
});
|
|
266
262
|
});
|
|
267
263
|
describe('accessors', () => {
|
|
268
264
|
const TEST_COMMENTS = 'test';
|
|
@@ -279,10 +275,10 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
279
275
|
});
|
|
280
276
|
describe('MockItemSubItem', () => {
|
|
281
277
|
let subItemDocument;
|
|
282
|
-
beforeEach(() =>
|
|
278
|
+
beforeEach(async () => {
|
|
283
279
|
subItemDocument = f.instance.collections.mockItemSubItemCollectionFactory(itemDocument).documentAccessor().newDocument();
|
|
284
|
-
|
|
285
|
-
})
|
|
280
|
+
await subItemDocument.accessor.set({ value: 0 });
|
|
281
|
+
});
|
|
286
282
|
describe('firestoreCollectionWithParent (MockItemSubItem)', () => {
|
|
287
283
|
let mockItemSubItemFirestoreCollection;
|
|
288
284
|
beforeEach(() => {
|
|
@@ -326,11 +322,11 @@ function describeFirestoreAccessorDriverTests(f) {
|
|
|
326
322
|
});
|
|
327
323
|
describe('documentAccessor()', () => {
|
|
328
324
|
describe('loadDocumentForKey()', () => {
|
|
329
|
-
it('should load an existing document from the path.', () =>
|
|
325
|
+
it('should load an existing document from the path.', async () => {
|
|
330
326
|
const document = mockItemFirestoreDocumentAccessor.loadDocumentForKey(items[0].key);
|
|
331
|
-
const exists =
|
|
327
|
+
const exists = await document.accessor.exists();
|
|
332
328
|
expect(exists).toBe(true);
|
|
333
|
-
})
|
|
329
|
+
});
|
|
334
330
|
(0, test_1.itShouldFail)('if the path is invalid (points to collection)', () => {
|
|
335
331
|
(0, test_1.expectFail)(() => {
|
|
336
332
|
mockItemFirestoreDocumentAccessor.loadDocumentForKey('path');
|
|
@@ -393,166 +389,166 @@ function describeFirestoreDocumentAccessorTests(init) {
|
|
|
393
389
|
});
|
|
394
390
|
describe('utilities', () => {
|
|
395
391
|
describe('getDocumentSnapshotPairs()', () => {
|
|
396
|
-
it('should return the document and snapshot pairs for the input.', () =>
|
|
397
|
-
const pairs =
|
|
392
|
+
it('should return the document and snapshot pairs for the input.', async () => {
|
|
393
|
+
const pairs = await (0, firebase_1.getDocumentSnapshotPairs)([firestoreDocument]);
|
|
398
394
|
expect(pairs.length).toBe(1);
|
|
399
395
|
expect(pairs[0]).toBeDefined();
|
|
400
396
|
expect(pairs[0].document).toBe(firestoreDocument);
|
|
401
397
|
expect(pairs[0].snapshot).toBeDefined();
|
|
402
398
|
expect(pairs[0].snapshot.data()).toBeDefined();
|
|
403
|
-
})
|
|
399
|
+
});
|
|
404
400
|
});
|
|
405
401
|
describe('useDocumentSnapshot()', () => {
|
|
406
|
-
it(`should use the input document value if it exists`, () =>
|
|
407
|
-
const exists =
|
|
402
|
+
it(`should use the input document value if it exists`, async () => {
|
|
403
|
+
const exists = await firestoreDocument.exists();
|
|
408
404
|
expect(exists).toBe(true);
|
|
409
405
|
let snapshotUsed = false;
|
|
410
|
-
|
|
406
|
+
await (0, firebase_1.useDocumentSnapshot)(firestoreDocument, (snapshot) => {
|
|
411
407
|
expect(snapshot).toBeDefined();
|
|
412
408
|
snapshotUsed = true;
|
|
413
409
|
});
|
|
414
410
|
expect(snapshotUsed).toBe(true);
|
|
415
|
-
})
|
|
416
|
-
it(`should not use the input undefined value`, () =>
|
|
411
|
+
});
|
|
412
|
+
it(`should not use the input undefined value`, async () => {
|
|
417
413
|
let snapshotUsed = false;
|
|
418
|
-
|
|
414
|
+
await (0, firebase_1.useDocumentSnapshot)(undefined, (snapshot) => {
|
|
419
415
|
expect(snapshot).toBeDefined();
|
|
420
416
|
snapshotUsed = true;
|
|
421
417
|
});
|
|
422
418
|
expect(snapshotUsed).toBe(false);
|
|
423
|
-
})
|
|
419
|
+
});
|
|
424
420
|
});
|
|
425
421
|
describe('useDocumentSnapshotData()', () => {
|
|
426
|
-
it(`should use the input document's snapshot data if it exists`, () =>
|
|
427
|
-
const exists =
|
|
422
|
+
it(`should use the input document's snapshot data if it exists`, async () => {
|
|
423
|
+
const exists = await firestoreDocument.exists();
|
|
428
424
|
expect(exists).toBe(true);
|
|
429
425
|
let snapshotUsed = false;
|
|
430
|
-
|
|
426
|
+
await (0, firebase_1.useDocumentSnapshotData)(firestoreDocument, (data) => {
|
|
431
427
|
expect(data).toBeDefined();
|
|
432
428
|
snapshotUsed = true;
|
|
433
429
|
});
|
|
434
430
|
expect(snapshotUsed).toBe(true);
|
|
435
|
-
})
|
|
431
|
+
});
|
|
436
432
|
});
|
|
437
433
|
});
|
|
438
434
|
describe('AbstractFirestoreDocument', () => {
|
|
439
435
|
describe('snapshot()', () => {
|
|
440
|
-
it('should return the snapshot.', () =>
|
|
441
|
-
const snapshot =
|
|
436
|
+
it('should return the snapshot.', async () => {
|
|
437
|
+
const snapshot = await firestoreDocument.snapshot();
|
|
442
438
|
expect(snapshot).toBeDefined();
|
|
443
|
-
})
|
|
439
|
+
});
|
|
444
440
|
});
|
|
445
441
|
describe('snapshotData()', () => {
|
|
446
|
-
it('should return the snapshot data if the model exists.', () =>
|
|
447
|
-
const exists =
|
|
442
|
+
it('should return the snapshot data if the model exists.', async () => {
|
|
443
|
+
const exists = await firestoreDocument.exists();
|
|
448
444
|
expect(exists).toBe(true);
|
|
449
|
-
const data =
|
|
445
|
+
const data = await firestoreDocument.snapshotData();
|
|
450
446
|
expect(data).toBeDefined();
|
|
451
|
-
})
|
|
452
|
-
it('should return the undefined if the model does not exist.', () =>
|
|
453
|
-
|
|
454
|
-
const exists =
|
|
447
|
+
});
|
|
448
|
+
it('should return the undefined if the model does not exist.', async () => {
|
|
449
|
+
await accessor.delete();
|
|
450
|
+
const exists = await firestoreDocument.exists();
|
|
455
451
|
expect(exists).toBe(false);
|
|
456
|
-
const data =
|
|
452
|
+
const data = await firestoreDocument.snapshotData();
|
|
457
453
|
expect(data).toBeUndefined();
|
|
458
|
-
})
|
|
454
|
+
});
|
|
459
455
|
});
|
|
460
456
|
describe('create()', () => {
|
|
461
|
-
it('should create the document if it does not exist.', () =>
|
|
462
|
-
const snapshot =
|
|
463
|
-
|
|
464
|
-
let exists =
|
|
457
|
+
it('should create the document if it does not exist.', async () => {
|
|
458
|
+
const snapshot = await firestoreDocument.snapshot();
|
|
459
|
+
await accessor.delete();
|
|
460
|
+
let exists = await firestoreDocument.exists();
|
|
465
461
|
expect(exists).toBe(false);
|
|
466
|
-
|
|
467
|
-
exists =
|
|
462
|
+
await firestoreDocument.create(snapshot.data());
|
|
463
|
+
exists = await firestoreDocument.exists();
|
|
468
464
|
expect(exists).toBe(true);
|
|
469
|
-
})
|
|
470
|
-
(0, test_1.itShouldFail)('if the document exists.', () =>
|
|
471
|
-
const snapshot =
|
|
472
|
-
const exists =
|
|
465
|
+
});
|
|
466
|
+
(0, test_1.itShouldFail)('if the document exists.', async () => {
|
|
467
|
+
const snapshot = await firestoreDocument.snapshot();
|
|
468
|
+
const exists = await firestoreDocument.exists();
|
|
473
469
|
expect(exists).toBe(true);
|
|
474
|
-
|
|
475
|
-
})
|
|
470
|
+
await (0, test_1.expectFail)(() => firestoreDocument.create(snapshot.data()));
|
|
471
|
+
});
|
|
476
472
|
});
|
|
477
473
|
describe('update()', () => {
|
|
478
|
-
it('should update the data if the document exists.', () =>
|
|
474
|
+
it('should update the data if the document exists.', async () => {
|
|
479
475
|
const data = c.dataForUpdate();
|
|
480
|
-
|
|
481
|
-
const snapshot =
|
|
476
|
+
await firestoreDocument.update(data);
|
|
477
|
+
const snapshot = await firestoreDocument.snapshot();
|
|
482
478
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
483
|
-
})
|
|
484
|
-
(0, test_1.itShouldFail)('if the document does not exist.', () =>
|
|
485
|
-
|
|
486
|
-
const snapshot =
|
|
479
|
+
});
|
|
480
|
+
(0, test_1.itShouldFail)('if the document does not exist.', async () => {
|
|
481
|
+
await accessor.delete();
|
|
482
|
+
const snapshot = await firestoreDocument.snapshot();
|
|
487
483
|
expect(snapshot.data()).toBe(undefined);
|
|
488
|
-
const exists =
|
|
484
|
+
const exists = await firestoreDocument.exists();
|
|
489
485
|
expect(exists).toBe(false);
|
|
490
|
-
|
|
491
|
-
})
|
|
492
|
-
it('should not throw an error if the input update data is empty.', () =>
|
|
493
|
-
|
|
494
|
-
})
|
|
486
|
+
await (0, test_1.expectFail)(() => firestoreDocument.update(c.dataForUpdate()));
|
|
487
|
+
});
|
|
488
|
+
it('should not throw an error if the input update data is empty.', async () => {
|
|
489
|
+
await firestoreDocument.update({});
|
|
490
|
+
});
|
|
495
491
|
});
|
|
496
492
|
describe('transaction', () => {
|
|
497
493
|
describe('stream$', () => {
|
|
498
|
-
it('should not cause the transaction to fail if the document is loaded after changes have begun.', () =>
|
|
499
|
-
|
|
500
|
-
const transactionDocument =
|
|
501
|
-
const currentData =
|
|
494
|
+
it('should not cause the transaction to fail if the document is loaded after changes have begun.', async () => {
|
|
495
|
+
await c.context.runTransaction(async (transaction) => {
|
|
496
|
+
const transactionDocument = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
|
|
497
|
+
const currentData = await transactionDocument.snapshotData();
|
|
502
498
|
expect(currentData).toBeDefined();
|
|
503
499
|
const data = c.dataForUpdate();
|
|
504
|
-
|
|
500
|
+
await transactionDocument.update(data);
|
|
505
501
|
// stream$ and data$ do not call stream() until called directly.
|
|
506
|
-
const secondLoading =
|
|
502
|
+
const secondLoading = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
|
|
507
503
|
expect(secondLoading).toBeDefined();
|
|
508
|
-
})
|
|
509
|
-
})
|
|
510
|
-
(0, test_1.itShouldFail)('if stream$ is called after an update has occured in the transaction', () =>
|
|
511
|
-
|
|
512
|
-
const transactionDocument =
|
|
513
|
-
const currentData =
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
(0, test_1.itShouldFail)('if stream$ is called after an update has occured in the transaction', async () => {
|
|
507
|
+
await (0, test_1.expectFail)(() => c.context.runTransaction(async (transaction) => {
|
|
508
|
+
const transactionDocument = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
|
|
509
|
+
const currentData = await transactionDocument.snapshotData();
|
|
514
510
|
expect(currentData).toBeDefined();
|
|
515
511
|
const data = c.dataForUpdate();
|
|
516
|
-
|
|
512
|
+
await transactionDocument.update(data);
|
|
517
513
|
// read the stream using a promise so the error is captured
|
|
518
|
-
|
|
519
|
-
}))
|
|
520
|
-
})
|
|
514
|
+
await (0, rxjs_1.firstValueFrom)(c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef).stream$);
|
|
515
|
+
}));
|
|
516
|
+
});
|
|
521
517
|
});
|
|
522
518
|
describe('update()', () => {
|
|
523
|
-
it('should update the data if the document exists.', () =>
|
|
524
|
-
|
|
525
|
-
const transactionDocument =
|
|
526
|
-
const currentData =
|
|
519
|
+
it('should update the data if the document exists.', async () => {
|
|
520
|
+
await c.context.runTransaction(async (transaction) => {
|
|
521
|
+
const transactionDocument = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
|
|
522
|
+
const currentData = await transactionDocument.snapshotData();
|
|
527
523
|
expect(currentData).toBeDefined();
|
|
528
524
|
const data = c.dataForUpdate();
|
|
529
|
-
|
|
530
|
-
})
|
|
531
|
-
const snapshot =
|
|
525
|
+
await transactionDocument.update(data);
|
|
526
|
+
});
|
|
527
|
+
const snapshot = await firestoreDocument.snapshot();
|
|
532
528
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
533
|
-
})
|
|
529
|
+
});
|
|
534
530
|
});
|
|
535
531
|
});
|
|
536
532
|
describe('write batch', () => {
|
|
537
533
|
describe('update()', () => {
|
|
538
|
-
it('should update the data if the document exists.', () =>
|
|
534
|
+
it('should update the data if the document exists.', async () => {
|
|
539
535
|
const batch = c.context.batch();
|
|
540
|
-
const batchDocument =
|
|
536
|
+
const batchDocument = await c.loadDocumentForWriteBatch(batch, firestoreDocument.documentRef);
|
|
541
537
|
const data = c.dataForUpdate();
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const snapshot =
|
|
538
|
+
await batchDocument.update(data);
|
|
539
|
+
await batch.commit();
|
|
540
|
+
const snapshot = await firestoreDocument.snapshot();
|
|
545
541
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
546
|
-
})
|
|
542
|
+
});
|
|
547
543
|
});
|
|
548
544
|
});
|
|
549
545
|
});
|
|
550
546
|
describe('accessor', () => {
|
|
551
547
|
describe('stream()', () => {
|
|
552
|
-
it('should return a snapshot stream', () =>
|
|
553
|
-
const result =
|
|
548
|
+
it('should return a snapshot stream', async () => {
|
|
549
|
+
const result = await accessor.stream();
|
|
554
550
|
expect(result).toBeDefined();
|
|
555
|
-
})
|
|
551
|
+
});
|
|
556
552
|
it('should emit values on updates from the observable.', (done) => {
|
|
557
553
|
let count = 0;
|
|
558
554
|
sub.subscription = accessor.stream().subscribe((item) => {
|
|
@@ -574,133 +570,133 @@ function describeFirestoreDocumentAccessorTests(init) {
|
|
|
574
570
|
beforeEach(() => {
|
|
575
571
|
runTransaction = c.context.runTransaction;
|
|
576
572
|
});
|
|
577
|
-
it('should return the first emitted value (observable completes immediately)', () =>
|
|
578
|
-
|
|
573
|
+
it('should return the first emitted value (observable completes immediately)', async () => {
|
|
574
|
+
await runTransaction(async (transaction) => {
|
|
579
575
|
const transactionItemDocument = c.loadDocumentForTransaction(transaction, accessor.documentRef);
|
|
580
576
|
// load the value
|
|
581
|
-
const value =
|
|
577
|
+
const value = await (0, rxjs_1.firstValueFrom)(transactionItemDocument.accessor.stream());
|
|
582
578
|
expect(value).toBeDefined();
|
|
583
579
|
// set to make the transaction valid
|
|
584
|
-
|
|
580
|
+
await transactionItemDocument.accessor.set({ value: 0 }, { merge: true });
|
|
585
581
|
return value;
|
|
586
|
-
})
|
|
587
|
-
})
|
|
582
|
+
});
|
|
583
|
+
});
|
|
588
584
|
});
|
|
589
585
|
describe('in batch context', () => {
|
|
590
|
-
it('should return the first emitted value (observable completes immediately)', () =>
|
|
586
|
+
it('should return the first emitted value (observable completes immediately)', async () => {
|
|
591
587
|
const writeBatch = c.context.batch();
|
|
592
588
|
const batchItemDocument = c.loadDocumentForWriteBatch(writeBatch, accessor.documentRef);
|
|
593
589
|
// load the value
|
|
594
|
-
const value =
|
|
590
|
+
const value = await (0, rxjs_1.firstValueFrom)(batchItemDocument.accessor.stream());
|
|
595
591
|
expect(value).toBeDefined();
|
|
596
592
|
// set to make the batch changes valid
|
|
597
|
-
|
|
593
|
+
await batchItemDocument.accessor.set({ value: 0 }, { merge: true });
|
|
598
594
|
// commit the changes
|
|
599
|
-
|
|
600
|
-
})
|
|
595
|
+
await writeBatch.commit();
|
|
596
|
+
});
|
|
601
597
|
});
|
|
602
598
|
});
|
|
603
599
|
describe('create()', () => {
|
|
604
|
-
it('should create the document if it does not exist.', () =>
|
|
605
|
-
const snapshot =
|
|
606
|
-
|
|
607
|
-
let exists =
|
|
600
|
+
it('should create the document if it does not exist.', async () => {
|
|
601
|
+
const snapshot = await accessor.get();
|
|
602
|
+
await accessor.delete();
|
|
603
|
+
let exists = await accessor.exists();
|
|
608
604
|
expect(exists).toBe(false);
|
|
609
|
-
|
|
610
|
-
exists =
|
|
605
|
+
await accessor.create(snapshot.data());
|
|
606
|
+
exists = await accessor.exists();
|
|
611
607
|
expect(exists).toBe(true);
|
|
612
|
-
})
|
|
613
|
-
(0, test_1.itShouldFail)('if the document exists.', () =>
|
|
614
|
-
const snapshot =
|
|
615
|
-
const exists =
|
|
608
|
+
});
|
|
609
|
+
(0, test_1.itShouldFail)('if the document exists.', async () => {
|
|
610
|
+
const snapshot = await accessor.get();
|
|
611
|
+
const exists = await accessor.exists();
|
|
616
612
|
expect(exists).toBe(true);
|
|
617
|
-
|
|
618
|
-
})
|
|
613
|
+
await (0, test_1.expectFail)(() => accessor.create(snapshot.data()));
|
|
614
|
+
});
|
|
619
615
|
});
|
|
620
616
|
describe('get()', () => {
|
|
621
|
-
it('should return a snapshot', () =>
|
|
622
|
-
const result =
|
|
617
|
+
it('should return a snapshot', async () => {
|
|
618
|
+
const result = await accessor.get();
|
|
623
619
|
expect(result).toBeDefined();
|
|
624
620
|
expect(result.id).toBeDefined();
|
|
625
|
-
})
|
|
621
|
+
});
|
|
626
622
|
});
|
|
627
623
|
describe('exists()', () => {
|
|
628
|
-
it('should return true if the document exists', () =>
|
|
629
|
-
const exists =
|
|
624
|
+
it('should return true if the document exists', async () => {
|
|
625
|
+
const exists = await accessor.exists();
|
|
630
626
|
expect(exists).toBe(true);
|
|
631
|
-
})
|
|
632
|
-
it('should return false if the document does not exist', () =>
|
|
633
|
-
|
|
634
|
-
const exists =
|
|
627
|
+
});
|
|
628
|
+
it('should return false if the document does not exist', async () => {
|
|
629
|
+
await accessor.delete();
|
|
630
|
+
const exists = await accessor.exists();
|
|
635
631
|
expect(exists).toBe(false);
|
|
636
|
-
})
|
|
632
|
+
});
|
|
637
633
|
});
|
|
638
634
|
describe('update()', () => {
|
|
639
|
-
it('should update the data if the document exists.', () =>
|
|
635
|
+
it('should update the data if the document exists.', async () => {
|
|
640
636
|
const data = c.dataForUpdate();
|
|
641
|
-
|
|
642
|
-
const snapshot =
|
|
637
|
+
await accessor.update(data);
|
|
638
|
+
const snapshot = await accessor.get();
|
|
643
639
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
644
|
-
})
|
|
645
|
-
(0, test_1.itShouldFail)('if the document does not exist.', () =>
|
|
646
|
-
|
|
647
|
-
const snapshot =
|
|
640
|
+
});
|
|
641
|
+
(0, test_1.itShouldFail)('if the document does not exist.', async () => {
|
|
642
|
+
await accessor.delete();
|
|
643
|
+
const snapshot = await accessor.get();
|
|
648
644
|
expect(snapshot.data()).toBe(undefined);
|
|
649
|
-
const exists =
|
|
645
|
+
const exists = await accessor.exists();
|
|
650
646
|
expect(exists).toBe(false);
|
|
651
|
-
|
|
652
|
-
})
|
|
653
|
-
(0, test_1.itShouldFail)('if the input is an empty object.', () =>
|
|
654
|
-
|
|
655
|
-
})
|
|
656
|
-
//
|
|
647
|
+
await (0, test_1.expectFail)(() => accessor.update(c.dataForUpdate()));
|
|
648
|
+
});
|
|
649
|
+
(0, test_1.itShouldFail)('if the input is an empty object.', async () => {
|
|
650
|
+
await (0, test_1.expectFail)(() => accessor.update({}));
|
|
651
|
+
});
|
|
652
|
+
// TODO(TEST): test that update does not call the converter when setting values.
|
|
657
653
|
});
|
|
658
654
|
describe('set()', () => {
|
|
659
|
-
it('should create the object if it does not exist.', () =>
|
|
660
|
-
|
|
661
|
-
let exists =
|
|
655
|
+
it('should create the object if it does not exist.', async () => {
|
|
656
|
+
await accessor.delete();
|
|
657
|
+
let exists = await accessor.exists();
|
|
662
658
|
expect(exists).toBe(false);
|
|
663
659
|
const data = c.dataForUpdate();
|
|
664
|
-
|
|
665
|
-
exists =
|
|
660
|
+
await accessor.set(data);
|
|
661
|
+
exists = await accessor.exists();
|
|
666
662
|
expect(exists).toBe(true);
|
|
667
|
-
const snapshot =
|
|
663
|
+
const snapshot = await accessor.get();
|
|
668
664
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
669
|
-
})
|
|
670
|
-
it('should update the data on the document for fields that are not undefined.', () =>
|
|
665
|
+
});
|
|
666
|
+
it('should update the data on the document for fields that are not undefined.', async () => {
|
|
671
667
|
const data = c.dataForUpdate();
|
|
672
|
-
|
|
673
|
-
const snapshot =
|
|
668
|
+
await accessor.set(data);
|
|
669
|
+
const snapshot = await accessor.get();
|
|
674
670
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
675
|
-
})
|
|
671
|
+
});
|
|
676
672
|
describe('merge=true', () => {
|
|
677
|
-
it('should update the data if the document exists.', () =>
|
|
673
|
+
it('should update the data if the document exists.', async () => {
|
|
678
674
|
const data = c.dataForUpdate();
|
|
679
|
-
|
|
680
|
-
const snapshot =
|
|
675
|
+
await accessor.set(data, { merge: true });
|
|
676
|
+
const snapshot = await accessor.get();
|
|
681
677
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
682
|
-
})
|
|
683
|
-
it('should succeed if the document does not exist.', () =>
|
|
684
|
-
|
|
685
|
-
let snapshot =
|
|
678
|
+
});
|
|
679
|
+
it('should succeed if the document does not exist.', async () => {
|
|
680
|
+
await accessor.delete();
|
|
681
|
+
let snapshot = await accessor.get();
|
|
686
682
|
expect(snapshot.data()).toBe(undefined);
|
|
687
|
-
const exists =
|
|
683
|
+
const exists = await accessor.exists();
|
|
688
684
|
expect(exists).toBe(false);
|
|
689
|
-
|
|
690
|
-
snapshot =
|
|
685
|
+
await accessor.set(c.dataForUpdate(), { merge: true });
|
|
686
|
+
snapshot = await accessor.get();
|
|
691
687
|
expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
|
|
692
|
-
})
|
|
688
|
+
});
|
|
693
689
|
});
|
|
694
|
-
//
|
|
690
|
+
// TODO(TEST): test that set calls the converter when setting values.
|
|
695
691
|
});
|
|
696
692
|
describe('delete()', () => {
|
|
697
|
-
it('should delete the document.', () =>
|
|
698
|
-
|
|
699
|
-
const snapshot =
|
|
693
|
+
it('should delete the document.', async () => {
|
|
694
|
+
await accessor.delete();
|
|
695
|
+
const snapshot = await accessor.get();
|
|
700
696
|
expect(snapshot.data()).toBe(undefined);
|
|
701
|
-
const exists =
|
|
697
|
+
const exists = await accessor.exists();
|
|
702
698
|
expect(exists).toBe(false);
|
|
703
|
-
})
|
|
699
|
+
});
|
|
704
700
|
});
|
|
705
701
|
});
|
|
706
702
|
}
|