@dereekb/firebase 10.2.0 → 11.0.0
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 +14 -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.describeFirestoreQueryDriverTests = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const date_fns_1 = require("date-fns");
|
|
6
5
|
const test_1 = require("@dereekb/util/test");
|
|
7
6
|
const rxjs_1 = require("@dereekb/rxjs");
|
|
@@ -22,8 +21,8 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
22
21
|
const startDate = (0, date_fns_1.addDays)((0, date_fns_1.startOfDay)(new Date()), 1);
|
|
23
22
|
const EVEN_TAG = 'even';
|
|
24
23
|
const ODD_TAG = 'odd';
|
|
25
|
-
beforeEach(() =>
|
|
26
|
-
items =
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
items = await (0, firebase_1.makeDocuments)(f.instance.firestoreCollection.documentAccessor(), {
|
|
27
26
|
count: testDocumentCount,
|
|
28
27
|
init: (i) => {
|
|
29
28
|
return {
|
|
@@ -35,20 +34,20 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
36
|
});
|
|
38
|
-
})
|
|
37
|
+
});
|
|
39
38
|
describe('firestoreIdBatchVerifierFactory()', () => {
|
|
40
39
|
const mockItemIdBatchVerifier = (0, firebase_1.firestoreIdBatchVerifierFactory)({
|
|
41
40
|
readKeys: (x) => [x.id],
|
|
42
41
|
fieldToQuery: '_id'
|
|
43
42
|
});
|
|
44
|
-
it('should query on the id field.', () =>
|
|
43
|
+
it('should query on the id field.', async () => {
|
|
45
44
|
const takenIds = items.map((x) => x.id);
|
|
46
|
-
const result =
|
|
45
|
+
const result = await f.instance.mockItemCollection.queryDocument((0, firebase_1.whereDocumentId)('in', takenIds)).getDocs();
|
|
47
46
|
expect(result).toBeDefined();
|
|
48
47
|
expect(result.length).toBe(takenIds.length);
|
|
49
48
|
expect(result.map((x) => x.id)).toContain(takenIds[0]);
|
|
50
|
-
})
|
|
51
|
-
it('should return ids that are not taken.', () =>
|
|
49
|
+
});
|
|
50
|
+
it('should return ids that are not taken.', async () => {
|
|
52
51
|
const takenIds = items.map((x) => x.id);
|
|
53
52
|
const idFactory = (0, util_1.arrayFactory)((0, util_1.mapGetter)((0, util_1.randomNumberFactory)(10000000), (x) => `test-id-${x}`));
|
|
54
53
|
const random = (0, util_1.randomFromArrayFactory)(takenIds);
|
|
@@ -60,18 +59,18 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
60
59
|
}
|
|
61
60
|
});
|
|
62
61
|
const idsToMake = 30;
|
|
63
|
-
const result =
|
|
62
|
+
const result = await factory(idsToMake);
|
|
64
63
|
expect(result).toBeDefined();
|
|
65
64
|
expect((0, util_1.unique)(result).length).toBe(idsToMake);
|
|
66
65
|
expect((0, util_1.unique)(result, takenIds).length).toBe(idsToMake);
|
|
67
|
-
})
|
|
66
|
+
});
|
|
68
67
|
});
|
|
69
68
|
describe('mockItemUser', () => {
|
|
70
69
|
let testUserId;
|
|
71
70
|
let allMockUserItems;
|
|
72
|
-
beforeEach(() =>
|
|
71
|
+
beforeEach(async () => {
|
|
73
72
|
testUserId = 'userid' + Math.ceil(Math.random() * 100000);
|
|
74
|
-
const results =
|
|
73
|
+
const results = await Promise.all(items.map((parent) => (0, firebase_1.makeDocuments)(f.instance.mockItemUserCollection(parent).documentAccessor(), {
|
|
75
74
|
count: 1,
|
|
76
75
|
newDocument: (x) => x.loadDocumentForId(testUserId),
|
|
77
76
|
init: (i) => {
|
|
@@ -82,22 +81,22 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
82
81
|
}
|
|
83
82
|
})));
|
|
84
83
|
allMockUserItems = results.flat();
|
|
85
|
-
})
|
|
84
|
+
});
|
|
86
85
|
describe('utils', () => {
|
|
87
86
|
describe('iterate load firestore utilities', () => {
|
|
88
87
|
describe('loadAllFirestoreDocumentSnapshotPairs()', () => {
|
|
89
|
-
it('should iterate batches of snapshot pairs.', () =>
|
|
88
|
+
it('should iterate batches of snapshot pairs.', async () => {
|
|
90
89
|
const documentAccessor = f.instance.mockItemUserCollectionGroup.documentAccessor();
|
|
91
90
|
const mockUserItemsVisited = new Set();
|
|
92
|
-
const result =
|
|
91
|
+
const result = await (0, firebase_1.loadAllFirestoreDocumentSnapshotPairs)({
|
|
93
92
|
documentAccessor,
|
|
94
|
-
iterateSnapshotPairsBatch: (x) =>
|
|
93
|
+
iterateSnapshotPairsBatch: async (x) => {
|
|
95
94
|
x.forEach((y) => mockUserItemsVisited.add(y.document.key));
|
|
96
95
|
const pair = x[0];
|
|
97
96
|
expect(pair.data).toBeDefined();
|
|
98
97
|
expect(pair.snapshot).toBeDefined();
|
|
99
98
|
expect(pair.document).toBeDefined();
|
|
100
|
-
}
|
|
99
|
+
},
|
|
101
100
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
102
101
|
constraintsFactory: [] // no constraints
|
|
103
102
|
});
|
|
@@ -107,18 +106,18 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
107
106
|
expect(result.snapshotPairs[0].data).toBeDefined();
|
|
108
107
|
expect(result.snapshotPairs[0].document).toBeDefined();
|
|
109
108
|
expect(result.snapshotPairs[0].snapshot).toBeDefined();
|
|
110
|
-
})
|
|
109
|
+
});
|
|
111
110
|
});
|
|
112
111
|
describe('loadAllFirestoreDocumentSnapshot()', () => {
|
|
113
|
-
it('should iterate batches of snapshot pairs.', () =>
|
|
112
|
+
it('should iterate batches of snapshot pairs.', async () => {
|
|
114
113
|
const mockUserItemsVisited = new Set();
|
|
115
|
-
const result =
|
|
116
|
-
iterateSnapshotsForCheckpoint: (x) =>
|
|
114
|
+
const result = await (0, firebase_1.loadAllFirestoreDocumentSnapshot)({
|
|
115
|
+
iterateSnapshotsForCheckpoint: async (x) => {
|
|
117
116
|
x.forEach((y) => mockUserItemsVisited.add(y.ref.path));
|
|
118
117
|
const snapshot = x[0];
|
|
119
118
|
expect(snapshot.ref).toBeDefined();
|
|
120
119
|
expect(snapshot.data()).toBeDefined();
|
|
121
|
-
}
|
|
120
|
+
},
|
|
122
121
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
123
122
|
constraintsFactory: [] // no constraints
|
|
124
123
|
});
|
|
@@ -127,22 +126,22 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
127
126
|
expect(result.snapshots.length).toBe(allMockUserItems.length);
|
|
128
127
|
expect(result.snapshots[0].ref).toBeDefined();
|
|
129
128
|
expect(result.snapshots[0].data()).toBeDefined();
|
|
130
|
-
})
|
|
129
|
+
});
|
|
131
130
|
});
|
|
132
131
|
});
|
|
133
132
|
describe('iterate firestore utilities', () => {
|
|
134
133
|
describe('iterateFirestoreDocumentSnapshotPairs()', () => {
|
|
135
|
-
it('should iterate across all mock users by each snapshot pair.', () =>
|
|
134
|
+
it('should iterate across all mock users by each snapshot pair.', async () => {
|
|
136
135
|
const documentAccessor = f.instance.mockItemUserCollectionGroup.documentAccessor();
|
|
137
136
|
const mockUserItemsVisited = new Set();
|
|
138
137
|
const batchSize = 2;
|
|
139
|
-
const result =
|
|
138
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotPairs)({
|
|
140
139
|
batchSize,
|
|
141
140
|
handleRepeatCursor: false,
|
|
142
|
-
filterCheckpointSnapshots: (x) =>
|
|
141
|
+
filterCheckpointSnapshots: async (x) => {
|
|
143
142
|
return x;
|
|
144
|
-
}
|
|
145
|
-
iterateSnapshotPair: (x) =>
|
|
143
|
+
},
|
|
144
|
+
iterateSnapshotPair: async (x) => {
|
|
146
145
|
expect(x.data).toBeDefined();
|
|
147
146
|
expect(x.snapshot).toBeDefined();
|
|
148
147
|
expect(x.document).toBeDefined();
|
|
@@ -153,32 +152,32 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
153
152
|
else {
|
|
154
153
|
mockUserItemsVisited.add(key);
|
|
155
154
|
}
|
|
156
|
-
}
|
|
157
|
-
useCheckpointResult: (x) =>
|
|
155
|
+
},
|
|
156
|
+
useCheckpointResult: async (x) => {
|
|
158
157
|
if (x.docSnapshots.length > 0) {
|
|
159
158
|
expect(x.results[0].snapshots.length).toBeLessThanOrEqual(batchSize);
|
|
160
159
|
}
|
|
161
|
-
}
|
|
160
|
+
},
|
|
162
161
|
documentAccessor,
|
|
163
162
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
164
163
|
constraintsFactory: [] // no constraints
|
|
165
164
|
});
|
|
166
165
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
167
166
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
168
|
-
})
|
|
167
|
+
});
|
|
169
168
|
describe('1 item exists', () => {
|
|
170
169
|
let onlyItem;
|
|
171
|
-
beforeEach(() =>
|
|
170
|
+
beforeEach(async () => {
|
|
172
171
|
onlyItem = allMockUserItems.pop();
|
|
173
|
-
|
|
172
|
+
await Promise.all(allMockUserItems.map((x) => x.accessor.delete()));
|
|
174
173
|
allMockUserItems = [onlyItem];
|
|
175
|
-
})
|
|
176
|
-
it('should iterate the single item', () =>
|
|
174
|
+
});
|
|
175
|
+
it('should iterate the single item', async () => {
|
|
177
176
|
const documentAccessor = f.instance.mockItemUserCollectionGroup.documentAccessor();
|
|
178
177
|
const mockUserItemsVisited = new Set();
|
|
179
178
|
expect(allMockUserItems).toHaveLength(1);
|
|
180
|
-
const result =
|
|
181
|
-
iterateSnapshotPair: (x) =>
|
|
179
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotPairs)({
|
|
180
|
+
iterateSnapshotPair: async (x) => {
|
|
182
181
|
expect(x.data).toBeDefined();
|
|
183
182
|
expect(x.snapshot).toBeDefined();
|
|
184
183
|
expect(x.document).toBeDefined();
|
|
@@ -189,7 +188,7 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
189
188
|
else {
|
|
190
189
|
mockUserItemsVisited.add(key);
|
|
191
190
|
}
|
|
192
|
-
}
|
|
191
|
+
},
|
|
193
192
|
documentAccessor,
|
|
194
193
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
195
194
|
batchSize: null,
|
|
@@ -202,8 +201,8 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
202
201
|
});
|
|
203
202
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
204
203
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
205
|
-
})
|
|
206
|
-
// TODO: Case where a document was visited twice via iteration after it was updated. Assumed
|
|
204
|
+
});
|
|
205
|
+
// TODO(TEST): Case where a document was visited twice via iteration after it was updated. Assumed
|
|
207
206
|
// to occur when the updated item matches an "or" case or other value when using "in". Cannot
|
|
208
207
|
// reproduce at the moment.
|
|
209
208
|
/*
|
|
@@ -252,14 +251,14 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
252
251
|
*/
|
|
253
252
|
});
|
|
254
253
|
describe('0 items exists', () => {
|
|
255
|
-
beforeEach(() =>
|
|
256
|
-
|
|
257
|
-
})
|
|
258
|
-
it('should iterate no items', () =>
|
|
254
|
+
beforeEach(async () => {
|
|
255
|
+
await Promise.all(allMockUserItems.map((x) => x.accessor.delete()));
|
|
256
|
+
});
|
|
257
|
+
it('should iterate no items', async () => {
|
|
259
258
|
const documentAccessor = f.instance.mockItemUserCollectionGroup.documentAccessor();
|
|
260
259
|
const mockUserItemsVisited = new Set();
|
|
261
|
-
const result =
|
|
262
|
-
iterateSnapshotPair: (x) =>
|
|
260
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotPairs)({
|
|
261
|
+
iterateSnapshotPair: async (x) => {
|
|
263
262
|
expect(x.data).toBeDefined();
|
|
264
263
|
expect(x.snapshot).toBeDefined();
|
|
265
264
|
expect(x.document).toBeDefined();
|
|
@@ -270,24 +269,24 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
270
269
|
else {
|
|
271
270
|
mockUserItemsVisited.add(key);
|
|
272
271
|
}
|
|
273
|
-
}
|
|
272
|
+
},
|
|
274
273
|
documentAccessor,
|
|
275
274
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
276
275
|
constraintsFactory: [] // no constraints
|
|
277
276
|
});
|
|
278
277
|
expect(result.totalSnapshotsVisited).toBe(0);
|
|
279
278
|
expect(mockUserItemsVisited.size).toBe(0);
|
|
280
|
-
})
|
|
279
|
+
});
|
|
281
280
|
});
|
|
282
281
|
});
|
|
283
282
|
describe('iterateFirestoreDocumentSnapshots()', () => {
|
|
284
|
-
it('should iterate across all mock users by each snapshot.', () =>
|
|
283
|
+
it('should iterate across all mock users by each snapshot.', async () => {
|
|
285
284
|
const documentAccessor = f.instance.mockItemUserCollectionGroup.documentAccessor();
|
|
286
285
|
const mockUserItemsVisited = new Set();
|
|
287
286
|
const batchSize = 2;
|
|
288
|
-
const result =
|
|
287
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshots)({
|
|
289
288
|
batchSize,
|
|
290
|
-
iterateSnapshot: (x) =>
|
|
289
|
+
iterateSnapshot: async (x) => {
|
|
291
290
|
const key = x.ref.path;
|
|
292
291
|
if (mockUserItemsVisited.has(key)) {
|
|
293
292
|
throw new Error('encountered repeat key');
|
|
@@ -295,145 +294,145 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
295
294
|
else {
|
|
296
295
|
mockUserItemsVisited.add(key);
|
|
297
296
|
}
|
|
298
|
-
}
|
|
299
|
-
useCheckpointResult: (x) =>
|
|
297
|
+
},
|
|
298
|
+
useCheckpointResult: async (x) => {
|
|
300
299
|
if (x.docSnapshots.length > 0) {
|
|
301
300
|
expect(x.results[0].snapshots.length).toBeLessThanOrEqual(batchSize);
|
|
302
301
|
}
|
|
303
|
-
}
|
|
302
|
+
},
|
|
304
303
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
305
304
|
constraintsFactory: [] // no constraints
|
|
306
305
|
});
|
|
307
306
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
308
307
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
309
|
-
})
|
|
308
|
+
});
|
|
310
309
|
});
|
|
311
310
|
describe('iterateFirestoreDocumentSnapshotPairBatches()', () => {
|
|
312
|
-
it('should iterate batches of snapshot pairs.', () =>
|
|
311
|
+
it('should iterate batches of snapshot pairs.', async () => {
|
|
313
312
|
const documentAccessor = f.instance.mockItemUserCollectionGroup.documentAccessor();
|
|
314
313
|
const mockUserItemsVisited = new Set();
|
|
315
314
|
const batchSize = 2;
|
|
316
|
-
const result =
|
|
315
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotPairBatches)({
|
|
317
316
|
documentAccessor,
|
|
318
317
|
batchSize,
|
|
319
|
-
iterateSnapshotPairsBatch: (x) =>
|
|
318
|
+
iterateSnapshotPairsBatch: async (x) => {
|
|
320
319
|
expect(x.length).toBeLessThanOrEqual(batchSize);
|
|
321
320
|
const pair = x[0];
|
|
322
321
|
expect(pair.data).toBeDefined();
|
|
323
322
|
expect(pair.snapshot).toBeDefined();
|
|
324
323
|
expect(pair.document).toBeDefined();
|
|
325
|
-
}
|
|
326
|
-
useCheckpointResult: (x) =>
|
|
324
|
+
},
|
|
325
|
+
useCheckpointResult: async (x) => {
|
|
327
326
|
x.docSnapshots.forEach((y) => mockUserItemsVisited.add(y.ref.path));
|
|
328
|
-
}
|
|
327
|
+
},
|
|
329
328
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
330
329
|
constraintsFactory: [] // no constraints
|
|
331
330
|
});
|
|
332
331
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
333
332
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
334
|
-
})
|
|
333
|
+
});
|
|
335
334
|
});
|
|
336
335
|
describe('iterateFirestoreDocumentSnapshotBatches()', () => {
|
|
337
|
-
it('should iterate batches of snapshots.', () =>
|
|
336
|
+
it('should iterate batches of snapshots.', async () => {
|
|
338
337
|
const mockUserItemsVisited = new Set();
|
|
339
338
|
const batchSize = 2;
|
|
340
|
-
const result =
|
|
339
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotBatches)({
|
|
341
340
|
batchSize,
|
|
342
|
-
iterateSnapshotBatch: (x) =>
|
|
341
|
+
iterateSnapshotBatch: async (x) => {
|
|
343
342
|
expect(x.length).toBeLessThanOrEqual(batchSize);
|
|
344
|
-
}
|
|
345
|
-
useCheckpointResult: (x) =>
|
|
343
|
+
},
|
|
344
|
+
useCheckpointResult: async (x) => {
|
|
346
345
|
x.docSnapshots.forEach((y) => mockUserItemsVisited.add(y.ref.path));
|
|
347
|
-
}
|
|
346
|
+
},
|
|
348
347
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
349
348
|
constraintsFactory: [] // no constraints
|
|
350
349
|
});
|
|
351
350
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
352
351
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
353
|
-
})
|
|
352
|
+
});
|
|
354
353
|
describe('limitPerCheckpoint', () => {
|
|
355
354
|
describe('limitPerCheckpoint = 0', () => {
|
|
356
|
-
it('should not iterate any batches', () =>
|
|
357
|
-
const result =
|
|
355
|
+
it('should not iterate any batches', async () => {
|
|
356
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotBatches)({
|
|
358
357
|
limitPerCheckpoint: 0,
|
|
359
|
-
iterateSnapshotBatch: (x) =>
|
|
358
|
+
iterateSnapshotBatch: async (x) => {
|
|
360
359
|
expect(x.length).toBe(0);
|
|
361
|
-
}
|
|
362
|
-
useCheckpointResult: (x) =>
|
|
360
|
+
},
|
|
361
|
+
useCheckpointResult: async (x) => {
|
|
363
362
|
expect(x.docSnapshots.length).toBe(0);
|
|
364
|
-
}
|
|
363
|
+
},
|
|
365
364
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
366
365
|
constraintsFactory: [] // no constraints
|
|
367
366
|
});
|
|
368
367
|
expect(result.totalSnapshotsVisited).toBe(0);
|
|
369
368
|
expect(result.totalSnapshotsLimitReached).toBe(true);
|
|
370
|
-
})
|
|
369
|
+
});
|
|
371
370
|
});
|
|
372
371
|
});
|
|
373
372
|
describe('maxParallelCheckpoints>1', () => {
|
|
374
|
-
it('should process the checkpoints in parallel.', () =>
|
|
373
|
+
it('should process the checkpoints in parallel.', async () => {
|
|
375
374
|
const mockUserItemsVisited = new Set();
|
|
376
375
|
const batchSize = 1;
|
|
377
376
|
const maxParallelCheckpoints = 4;
|
|
378
377
|
let currentRunningTasks = 0;
|
|
379
378
|
let maxRunningTasks = 0;
|
|
380
|
-
const result =
|
|
379
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotBatches)({
|
|
381
380
|
batchSize,
|
|
382
381
|
limitPerCheckpoint: 1,
|
|
383
382
|
maxParallelCheckpoints,
|
|
384
|
-
iterateSnapshotBatch: (x, batchIndex) =>
|
|
383
|
+
iterateSnapshotBatch: async (x, batchIndex) => {
|
|
385
384
|
currentRunningTasks += 1;
|
|
386
|
-
|
|
385
|
+
await (0, util_1.waitForMs)(1000);
|
|
387
386
|
maxRunningTasks = Math.max(maxRunningTasks, currentRunningTasks);
|
|
388
387
|
currentRunningTasks -= 1;
|
|
389
|
-
}
|
|
390
|
-
useCheckpointResult: (x) =>
|
|
388
|
+
},
|
|
389
|
+
useCheckpointResult: async (x) => {
|
|
391
390
|
x.docSnapshots.forEach((y) => mockUserItemsVisited.add(y.ref.path));
|
|
392
|
-
}
|
|
391
|
+
},
|
|
393
392
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
394
393
|
constraintsFactory: [] // no constraints
|
|
395
394
|
});
|
|
396
395
|
expect(maxRunningTasks).toBe(maxParallelCheckpoints);
|
|
397
396
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
398
397
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
399
|
-
})
|
|
398
|
+
});
|
|
400
399
|
});
|
|
401
400
|
describe('batchSize=null', () => {
|
|
402
|
-
it('should iterate with a single batch', () =>
|
|
401
|
+
it('should iterate with a single batch', async () => {
|
|
403
402
|
const mockUserItemsVisited = new Set();
|
|
404
403
|
const batchSize = null;
|
|
405
|
-
const result =
|
|
404
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotBatches)({
|
|
406
405
|
batchSize,
|
|
407
|
-
iterateSnapshotBatch: (x) =>
|
|
406
|
+
iterateSnapshotBatch: async (x) => {
|
|
408
407
|
expect(x.length).toBe(allMockUserItems.length);
|
|
409
|
-
}
|
|
410
|
-
useCheckpointResult: (x) =>
|
|
408
|
+
},
|
|
409
|
+
useCheckpointResult: async (x) => {
|
|
411
410
|
x.docSnapshots.forEach((y) => mockUserItemsVisited.add(y.ref.path));
|
|
412
|
-
}
|
|
411
|
+
},
|
|
413
412
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
414
413
|
constraintsFactory: [] // no constraints
|
|
415
414
|
});
|
|
416
415
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
417
416
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
418
|
-
})
|
|
417
|
+
});
|
|
419
418
|
});
|
|
420
419
|
describe('batchSizeForSnapshots: () => null', () => {
|
|
421
|
-
it('should iterate with a single batch', () =>
|
|
420
|
+
it('should iterate with a single batch', async () => {
|
|
422
421
|
const mockUserItemsVisited = new Set();
|
|
423
|
-
const result =
|
|
422
|
+
const result = await (0, firebase_1.iterateFirestoreDocumentSnapshotBatches)({
|
|
424
423
|
batchSizeForSnapshots: () => null,
|
|
425
|
-
iterateSnapshotBatch: (x) =>
|
|
424
|
+
iterateSnapshotBatch: async (x) => {
|
|
426
425
|
expect(x.length).toBe(allMockUserItems.length);
|
|
427
|
-
}
|
|
428
|
-
useCheckpointResult: (x) =>
|
|
426
|
+
},
|
|
427
|
+
useCheckpointResult: async (x) => {
|
|
429
428
|
x.docSnapshots.forEach((y) => mockUserItemsVisited.add(y.ref.path));
|
|
430
|
-
}
|
|
429
|
+
},
|
|
431
430
|
queryFactory: f.instance.mockItemUserCollectionGroup,
|
|
432
431
|
constraintsFactory: [] // no constraints
|
|
433
432
|
});
|
|
434
433
|
expect(result.totalSnapshotsVisited).toBe(allMockUserItems.length);
|
|
435
434
|
expect(mockUserItemsVisited.size).toBe(allMockUserItems.length);
|
|
436
|
-
})
|
|
435
|
+
});
|
|
437
436
|
});
|
|
438
437
|
});
|
|
439
438
|
});
|
|
@@ -442,13 +441,13 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
442
441
|
describe('query', () => {
|
|
443
442
|
describe('constraints', () => {
|
|
444
443
|
describe('where', () => {
|
|
445
|
-
it('should return the documents matching the input uid', () =>
|
|
446
|
-
const result =
|
|
444
|
+
it('should return the documents matching the input uid', async () => {
|
|
445
|
+
const result = await f.instance.mockItemUserCollectionGroup.query((0, firebase_1.where)('uid', '==', testUserId)).getDocs();
|
|
447
446
|
expect(result.docs.length).toBe(testDocumentCount);
|
|
448
447
|
result.docs.forEach((x) => {
|
|
449
448
|
expect(x.data().uid).toBe(testUserId);
|
|
450
449
|
});
|
|
451
|
-
})
|
|
450
|
+
});
|
|
452
451
|
});
|
|
453
452
|
});
|
|
454
453
|
});
|
|
@@ -460,10 +459,10 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
460
459
|
let parentA;
|
|
461
460
|
let querySubItems;
|
|
462
461
|
let allSubItems;
|
|
463
|
-
beforeEach(() =>
|
|
462
|
+
beforeEach(async () => {
|
|
464
463
|
querySubItems = f.instance.mockItemSubItemCollectionGroup.query;
|
|
465
464
|
parentA = items[0];
|
|
466
|
-
const results =
|
|
465
|
+
const results = await Promise.all(items.map((parent) => (0, firebase_1.makeDocuments)(f.instance.mockItemSubItemCollection(parent).documentAccessor(), {
|
|
467
466
|
count: subItemCountPerItem,
|
|
468
467
|
init: (i) => {
|
|
469
468
|
return {
|
|
@@ -472,7 +471,7 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
472
471
|
}
|
|
473
472
|
})));
|
|
474
473
|
allSubItems = results.flat();
|
|
475
|
-
})
|
|
474
|
+
});
|
|
476
475
|
describe('sub sub item', () => {
|
|
477
476
|
const deepSubItemCountPerItem = 1;
|
|
478
477
|
const totalDeepSubItemsCount = deepSubItemCountPerItem * totalSubItemsCount;
|
|
@@ -480,10 +479,10 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
480
479
|
let deepSubItemParentA;
|
|
481
480
|
let queryDeepSubItems;
|
|
482
481
|
let allDeepSubItems;
|
|
483
|
-
beforeEach(() =>
|
|
482
|
+
beforeEach(async () => {
|
|
484
483
|
queryDeepSubItems = f.instance.mockItemSubItemDeepCollectionGroup.query;
|
|
485
484
|
deepSubItemParentA = allSubItems[0];
|
|
486
|
-
const results =
|
|
485
|
+
const results = await Promise.all(allSubItems.map((parent) => (0, firebase_1.makeDocuments)(f.instance.mockItemSubItemDeepCollection(parent).documentAccessor(), {
|
|
487
486
|
count: deepSubItemCountPerItem,
|
|
488
487
|
init: (i) => {
|
|
489
488
|
return {
|
|
@@ -492,36 +491,36 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
492
491
|
}
|
|
493
492
|
})));
|
|
494
493
|
allDeepSubItems = results.flat();
|
|
495
|
-
})
|
|
494
|
+
});
|
|
496
495
|
// tests querying for all nested items under a parent
|
|
497
|
-
it('querying for only items belonging to mock item parentA', () =>
|
|
498
|
-
const result =
|
|
496
|
+
it('querying for only items belonging to mock item parentA', async () => {
|
|
497
|
+
const result = await queryDeepSubItems((0, mock_1.allChildMockItemSubItemDeepsWithinMockItem)(parentA.documentRef)).getDocs();
|
|
499
498
|
expect(result.docs.length).toBe(totalDeepSubItemsPerMockItem);
|
|
500
|
-
result.docs.forEach((x) =>
|
|
501
|
-
})
|
|
502
|
-
// TODO: Add tests for allChildDocumentsUnderRelativePath
|
|
499
|
+
result.docs.forEach((x) => expect(x.ref.parent?.parent?.parent?.parent?.path).toBe(parentA.documentRef.path));
|
|
500
|
+
});
|
|
501
|
+
// TODO(TEST): Add tests for allChildDocumentsUnderRelativePath
|
|
503
502
|
});
|
|
504
503
|
describe('sub item', () => {
|
|
505
504
|
describe('collection group', () => {
|
|
506
505
|
describe('query', () => {
|
|
507
|
-
it('should return sub items', () =>
|
|
508
|
-
const result =
|
|
506
|
+
it('should return sub items', async () => {
|
|
507
|
+
const result = await querySubItems().getDocs();
|
|
509
508
|
expect(result.docs.length).toBe(totalSubItemsCount);
|
|
510
|
-
})
|
|
509
|
+
});
|
|
511
510
|
describe('constraints', () => {
|
|
512
511
|
describe('where', () => {
|
|
513
|
-
it('should return the documents matching the query.', () =>
|
|
512
|
+
it('should return the documents matching the query.', async () => {
|
|
514
513
|
const value = 0;
|
|
515
|
-
const result =
|
|
514
|
+
const result = await querySubItems((0, firebase_1.where)('value', '==', value)).getDocs();
|
|
516
515
|
expect(result.docs.length).toBe(testDocumentCount);
|
|
517
516
|
expect(result.docs[0].data().value).toBe(value);
|
|
518
517
|
const ref = result.docs[0].ref;
|
|
519
518
|
expect(ref).toBeDefined();
|
|
520
519
|
expect(ref.parent).toBeDefined();
|
|
521
|
-
})
|
|
520
|
+
});
|
|
522
521
|
});
|
|
523
522
|
describe('whereDocumentId', () => {
|
|
524
|
-
(0, test_1.itShouldFail)('to query on collection groups.', () =>
|
|
523
|
+
(0, test_1.itShouldFail)('to query on collection groups.', async () => {
|
|
525
524
|
// https://stackoverflow.com/questions/56149601/firestore-collection-group-query-on-documentid
|
|
526
525
|
const targetId = 'targetid';
|
|
527
526
|
/*
|
|
@@ -539,8 +538,8 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
539
538
|
)
|
|
540
539
|
);
|
|
541
540
|
*/
|
|
542
|
-
|
|
543
|
-
})
|
|
541
|
+
await (0, test_1.expectFail)(() => querySubItems((0, firebase_1.whereDocumentId)('==', targetId)).getDocs());
|
|
542
|
+
});
|
|
544
543
|
});
|
|
545
544
|
});
|
|
546
545
|
describe('streamDocs()', () => {
|
|
@@ -614,17 +613,16 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
614
613
|
});
|
|
615
614
|
describe('queryDocument', () => {
|
|
616
615
|
let queryDocument;
|
|
617
|
-
beforeEach(() =>
|
|
616
|
+
beforeEach(async () => {
|
|
618
617
|
queryDocument = f.instance.firestoreCollection.queryDocument;
|
|
619
|
-
})
|
|
618
|
+
});
|
|
620
619
|
describe('filter()', () => {
|
|
621
|
-
it('should apply the filter to the query', () =>
|
|
622
|
-
const results = (
|
|
620
|
+
it('should apply the filter to the query', async () => {
|
|
621
|
+
const results = (await queryDocument().filter((0, firebase_1.where)('tags', 'array-contains', EVEN_TAG)).getDocSnapshotDataPairs());
|
|
623
622
|
expect(results).toBeDefined();
|
|
624
623
|
results.forEach((result) => {
|
|
625
|
-
var _a;
|
|
626
624
|
expect(result.data).toBeDefined();
|
|
627
|
-
expect(
|
|
625
|
+
expect(result.data?.tags).toContain(EVEN_TAG);
|
|
628
626
|
expect(result.document).toBeDefined();
|
|
629
627
|
expect(result.document instanceof mock_1.MockItemDocument).toBe(true);
|
|
630
628
|
expect(result.snapshot).toBeDefined();
|
|
@@ -632,16 +630,15 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
632
630
|
expect(result.snapshot.ref).toBeDefined();
|
|
633
631
|
expect(result.snapshot.id).toBe(result.document.id);
|
|
634
632
|
});
|
|
635
|
-
})
|
|
636
|
-
it('should add more filters to the existing query', () =>
|
|
637
|
-
const results = (
|
|
633
|
+
});
|
|
634
|
+
it('should add more filters to the existing query', async () => {
|
|
635
|
+
const results = (await queryDocument().filter((0, firebase_1.where)('tags', 'array-contains', EVEN_TAG)).filter((0, firebase_1.where)('number', '>=', 4)).getDocSnapshotDataPairs());
|
|
638
636
|
expect(results).toBeDefined();
|
|
639
637
|
expect(results.length).toBe(1);
|
|
640
638
|
results.forEach((result) => {
|
|
641
|
-
var _a, _b;
|
|
642
639
|
expect(result.data).toBeDefined();
|
|
643
|
-
expect(
|
|
644
|
-
expect(
|
|
640
|
+
expect(result.data?.tags).toContain(EVEN_TAG);
|
|
641
|
+
expect(result.data?.number).toBeGreaterThanOrEqual(4);
|
|
645
642
|
expect(result.document).toBeDefined();
|
|
646
643
|
expect(result.document instanceof mock_1.MockItemDocument).toBe(true);
|
|
647
644
|
expect(result.snapshot).toBeDefined();
|
|
@@ -649,15 +646,15 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
649
646
|
expect(result.snapshot.ref).toBeDefined();
|
|
650
647
|
expect(result.snapshot.id).toBe(result.document.id);
|
|
651
648
|
});
|
|
652
|
-
})
|
|
649
|
+
});
|
|
653
650
|
});
|
|
654
651
|
describe('getFirstDocSnapshotDataPair()', () => {
|
|
655
|
-
it('should return undefined if the query contains nothing', () =>
|
|
656
|
-
const result = (
|
|
652
|
+
it('should return undefined if the query contains nothing', async () => {
|
|
653
|
+
const result = (await queryDocument((0, firebase_1.where)('value', '==', '_DOES_NOT_EXIST_')).getFirstDocSnapshotDataPair());
|
|
657
654
|
expect(result).not.toBeDefined();
|
|
658
|
-
})
|
|
659
|
-
it('should return the first doc that matches if it exists', () =>
|
|
660
|
-
const result = (
|
|
655
|
+
});
|
|
656
|
+
it('should return the first doc that matches if it exists', async () => {
|
|
657
|
+
const result = (await queryDocument().getFirstDocSnapshotDataPair());
|
|
661
658
|
expect(result).toBeDefined();
|
|
662
659
|
expect(result.data).toBeDefined();
|
|
663
660
|
expect(result.document).toBeDefined();
|
|
@@ -666,16 +663,16 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
666
663
|
expect(result.snapshot.data()).toBeDefined();
|
|
667
664
|
expect(result.snapshot.ref).toBeDefined();
|
|
668
665
|
expect(result.snapshot.id).toBe(result.document.id);
|
|
669
|
-
})
|
|
666
|
+
});
|
|
670
667
|
});
|
|
671
668
|
describe('getDocSnapshotDataPairs()', () => {
|
|
672
|
-
it('should return an empty array if the query returns nothing', () =>
|
|
673
|
-
const result =
|
|
669
|
+
it('should return an empty array if the query returns nothing', async () => {
|
|
670
|
+
const result = await queryDocument((0, firebase_1.where)('value', '==', '_DOES_NOT_EXIST_')).getDocSnapshotDataPairs();
|
|
674
671
|
expect(result).toBeDefined();
|
|
675
672
|
expect(result.length).toBe(0);
|
|
676
|
-
})
|
|
677
|
-
it('should return the matching results', () =>
|
|
678
|
-
const results =
|
|
673
|
+
});
|
|
674
|
+
it('should return the matching results', async () => {
|
|
675
|
+
const results = await queryDocument().getDocSnapshotDataPairs();
|
|
679
676
|
expect(results).toBeDefined();
|
|
680
677
|
expect(results.length).toBeGreaterThan(0);
|
|
681
678
|
results.forEach((result) => {
|
|
@@ -688,7 +685,7 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
688
685
|
expect(result.snapshot.ref).toBeDefined();
|
|
689
686
|
expect(result.snapshot.id).toBe(result.document.id);
|
|
690
687
|
});
|
|
691
|
-
})
|
|
688
|
+
});
|
|
692
689
|
});
|
|
693
690
|
describe('streamDocs()', () => {
|
|
694
691
|
let sub;
|
|
@@ -835,9 +832,9 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
835
832
|
});
|
|
836
833
|
describe('query', () => {
|
|
837
834
|
let query;
|
|
838
|
-
beforeEach(() =>
|
|
835
|
+
beforeEach(async () => {
|
|
839
836
|
query = f.instance.firestoreCollection.query;
|
|
840
|
-
})
|
|
837
|
+
});
|
|
841
838
|
describe('streamDocs()', () => {
|
|
842
839
|
let sub;
|
|
843
840
|
beforeEach(() => {
|
|
@@ -906,13 +903,13 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
906
903
|
});
|
|
907
904
|
describe('constraint', () => {
|
|
908
905
|
describe('limit', () => {
|
|
909
|
-
it('should limit the number of items returned.', () =>
|
|
906
|
+
it('should limit the number of items returned.', async () => {
|
|
910
907
|
const limitCount = 2;
|
|
911
|
-
const unlimited =
|
|
908
|
+
const unlimited = await query().getDocs();
|
|
912
909
|
expect(unlimited.docs.length).toBe(testDocumentCount);
|
|
913
|
-
const result =
|
|
910
|
+
const result = await query((0, firebase_1.limit)(limitCount)).getDocs();
|
|
914
911
|
expect(result.docs.length).toBe(limitCount);
|
|
915
|
-
})
|
|
912
|
+
});
|
|
916
913
|
it('should limit the streamed results.', (done) => {
|
|
917
914
|
const limitCount = 2;
|
|
918
915
|
const resultObs = query((0, firebase_1.limit)(limitCount)).streamDocs();
|
|
@@ -923,35 +920,35 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
923
920
|
done();
|
|
924
921
|
});
|
|
925
922
|
});
|
|
926
|
-
it('should limit the number of items counted.', () =>
|
|
923
|
+
it('should limit the number of items counted.', async () => {
|
|
927
924
|
const limitCount = 2;
|
|
928
|
-
const unlimited =
|
|
925
|
+
const unlimited = await query().countDocs();
|
|
929
926
|
expect(unlimited).toBe(testDocumentCount);
|
|
930
|
-
const result =
|
|
927
|
+
const result = await query((0, firebase_1.limit)(limitCount)).countDocs();
|
|
931
928
|
expect(result).toBe(limitCount);
|
|
932
|
-
})
|
|
929
|
+
});
|
|
933
930
|
});
|
|
934
931
|
describe('limitToLast', () => {
|
|
935
|
-
it('should limit the number of items returned.', () =>
|
|
932
|
+
it('should limit the number of items returned.', async () => {
|
|
936
933
|
const limitCount = 2;
|
|
937
|
-
const unlimited =
|
|
934
|
+
const unlimited = await query().getDocs();
|
|
938
935
|
expect(unlimited.docs.length).toBe(testDocumentCount);
|
|
939
|
-
const result =
|
|
936
|
+
const result = await query((0, firebase_1.orderBy)('value'), (0, firebase_1.limitToLast)(limitCount)).getDocs();
|
|
940
937
|
expect(result.docs.length).toBe(limitCount);
|
|
941
|
-
})
|
|
942
|
-
it('the results should be returned from the end of the list. The results are still in the same order as requested.', () =>
|
|
938
|
+
});
|
|
939
|
+
it('the results should be returned from the end of the list. The results are still in the same order as requested.', async () => {
|
|
943
940
|
const limitCount = 2;
|
|
944
|
-
const result =
|
|
941
|
+
const result = await query((0, firebase_1.orderBy)('value', 'asc'), (0, firebase_1.limitToLast)(limitCount)).getDocs();
|
|
945
942
|
expect(result.docs.length).toBe(limitCount);
|
|
946
943
|
expect(result.docs[0].data().value).toBe('3');
|
|
947
944
|
expect(result.docs[1].data().value).toBe('4');
|
|
948
|
-
})
|
|
949
|
-
(0, test_1.itShouldFail)('if orderby is not provided.', () =>
|
|
945
|
+
});
|
|
946
|
+
(0, test_1.itShouldFail)('if orderby is not provided.', async () => {
|
|
950
947
|
const limitCount = 2;
|
|
951
|
-
const unlimited =
|
|
948
|
+
const unlimited = await query().getDocs();
|
|
952
949
|
expect(unlimited.docs.length).toBe(testDocumentCount);
|
|
953
|
-
|
|
954
|
-
})
|
|
950
|
+
await (0, test_1.expectFail)(() => query((0, firebase_1.limitToLast)(limitCount)).getDocs());
|
|
951
|
+
});
|
|
955
952
|
it('should stream results.', (done) => {
|
|
956
953
|
const limitCount = 2;
|
|
957
954
|
const resultObs = query((0, firebase_1.orderBy)('value'), (0, firebase_1.limitToLast)(limitCount)).streamDocs();
|
|
@@ -962,58 +959,58 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
962
959
|
done();
|
|
963
960
|
});
|
|
964
961
|
});
|
|
965
|
-
it('should limit the number of items counted.', () =>
|
|
962
|
+
it('should limit the number of items counted.', async () => {
|
|
966
963
|
const limitCount = 2;
|
|
967
|
-
const unlimited =
|
|
964
|
+
const unlimited = await query().countDocs();
|
|
968
965
|
expect(unlimited).toBe(testDocumentCount);
|
|
969
|
-
const result =
|
|
966
|
+
const result = await query((0, firebase_1.orderBy)('value'), (0, firebase_1.limitToLast)(limitCount)).countDocs();
|
|
970
967
|
expect(result).toBe(limitCount);
|
|
971
|
-
})
|
|
968
|
+
});
|
|
972
969
|
});
|
|
973
970
|
describe('orderBy', () => {
|
|
974
|
-
it('should return values sorted in ascending order.', () =>
|
|
975
|
-
const results =
|
|
971
|
+
it('should return values sorted in ascending order.', async () => {
|
|
972
|
+
const results = await query((0, firebase_1.orderBy)('value', 'asc')).getDocs();
|
|
976
973
|
expect(results.docs[0].data().value).toBe('0');
|
|
977
|
-
})
|
|
978
|
-
it('should return values sorted in descending order.', () =>
|
|
979
|
-
const results =
|
|
974
|
+
});
|
|
975
|
+
it('should return values sorted in descending order.', async () => {
|
|
976
|
+
const results = await query((0, firebase_1.orderBy)('value', 'desc')).getDocs();
|
|
980
977
|
expect(results.docs[0].data().value).toBe(`${items.length - 1}`);
|
|
981
|
-
})
|
|
978
|
+
});
|
|
982
979
|
});
|
|
983
980
|
describe('where', () => {
|
|
984
981
|
describe('==', () => {
|
|
985
|
-
it('should return the documents matching the query.', () =>
|
|
982
|
+
it('should return the documents matching the query.', async () => {
|
|
986
983
|
const value = '0';
|
|
987
|
-
const result =
|
|
984
|
+
const result = await query((0, firebase_1.where)('value', '==', value)).getDocs();
|
|
988
985
|
expect(result.docs.length).toBe(1);
|
|
989
986
|
expect(result.docs[0].data().value).toBe(value);
|
|
990
|
-
})
|
|
991
|
-
it('should return the count of the documents matching the query.', () =>
|
|
987
|
+
});
|
|
988
|
+
it('should return the count of the documents matching the query.', async () => {
|
|
992
989
|
const value = '0';
|
|
993
|
-
const result =
|
|
990
|
+
const result = await query((0, firebase_1.where)('value', '==', value)).countDocs();
|
|
994
991
|
expect(result).toBe(1);
|
|
995
|
-
})
|
|
992
|
+
});
|
|
996
993
|
});
|
|
997
994
|
describe('in', () => {
|
|
998
|
-
it('should return the documents with any of the input values.', () =>
|
|
995
|
+
it('should return the documents with any of the input values.', async () => {
|
|
999
996
|
const targetValue = ['0', '1', '2'];
|
|
1000
|
-
const result =
|
|
997
|
+
const result = await query((0, firebase_1.where)('value', 'in', targetValue)).getDocs();
|
|
1001
998
|
expect(result.docs.length).toBe(3);
|
|
1002
999
|
const values = result.docs.map((x) => x.data().value);
|
|
1003
1000
|
expect(values).toContain('0');
|
|
1004
1001
|
expect(values).toContain('1');
|
|
1005
1002
|
expect(values).toContain('2');
|
|
1006
|
-
})
|
|
1007
|
-
it('should return the count of documents with any of the input values.', () =>
|
|
1003
|
+
});
|
|
1004
|
+
it('should return the count of documents with any of the input values.', async () => {
|
|
1008
1005
|
const targetValue = ['0', '1', '2'];
|
|
1009
|
-
const result =
|
|
1006
|
+
const result = await query((0, firebase_1.where)('value', 'in', targetValue)).countDocs();
|
|
1010
1007
|
expect(result).toBe(3);
|
|
1011
|
-
})
|
|
1008
|
+
});
|
|
1012
1009
|
});
|
|
1013
1010
|
describe('not-in', () => {
|
|
1014
|
-
it('should return the documents that do not contain any of the input values.', () =>
|
|
1011
|
+
it('should return the documents that do not contain any of the input values.', async () => {
|
|
1015
1012
|
const targetValue = ['0', '1', '2'];
|
|
1016
|
-
const result =
|
|
1013
|
+
const result = await query((0, firebase_1.where)('value', 'not-in', targetValue)).getDocs();
|
|
1017
1014
|
expect(result.docs.length).toBe(2);
|
|
1018
1015
|
const values = result.docs.map((x) => x.data().value);
|
|
1019
1016
|
expect(values).not.toContain('0');
|
|
@@ -1021,63 +1018,63 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
1021
1018
|
expect(values).not.toContain('2');
|
|
1022
1019
|
expect(values).toContain('3');
|
|
1023
1020
|
expect(values).toContain('4');
|
|
1024
|
-
})
|
|
1025
|
-
it('should return the count of documents that do not contain any of the input values.', () =>
|
|
1021
|
+
});
|
|
1022
|
+
it('should return the count of documents that do not contain any of the input values.', async () => {
|
|
1026
1023
|
const targetValue = ['0', '1', '2'];
|
|
1027
|
-
const result =
|
|
1024
|
+
const result = await query((0, firebase_1.where)('value', 'not-in', targetValue)).countDocs();
|
|
1028
1025
|
expect(result).toBe(2);
|
|
1029
|
-
})
|
|
1026
|
+
});
|
|
1030
1027
|
});
|
|
1031
1028
|
describe('searching array values', () => {
|
|
1032
1029
|
describe('in', () => {
|
|
1033
|
-
it('should return the documents with arrays that only have the given values.', () =>
|
|
1030
|
+
it('should return the documents with arrays that only have the given values.', async () => {
|
|
1034
1031
|
// NOTE: we pass an array to match exactly
|
|
1035
1032
|
const targetValue = [['0', 'even']];
|
|
1036
|
-
const result =
|
|
1033
|
+
const result = await query((0, firebase_1.where)('tags', 'in', targetValue)).getDocs();
|
|
1037
1034
|
expect(result.docs.length).toBe(1);
|
|
1038
1035
|
expect(result.docs[0].data().value).toBe('0');
|
|
1039
|
-
})
|
|
1040
|
-
it('should not return the document with arrays that have more than the requested values.', () =>
|
|
1036
|
+
});
|
|
1037
|
+
it('should not return the document with arrays that have more than the requested values.', async () => {
|
|
1041
1038
|
const targetValue = [['0']];
|
|
1042
|
-
const result =
|
|
1039
|
+
const result = await query((0, firebase_1.where)('tags', 'in', targetValue)).getDocs();
|
|
1043
1040
|
expect(result.docs.length).toBe(0);
|
|
1044
|
-
})
|
|
1045
|
-
it('should return the count of documents with arrays that only have the given values.', () =>
|
|
1041
|
+
});
|
|
1042
|
+
it('should return the count of documents with arrays that only have the given values.', async () => {
|
|
1046
1043
|
// NOTE: we pass an array to match exactly
|
|
1047
1044
|
const targetValue = [['0', 'even']];
|
|
1048
|
-
const result =
|
|
1045
|
+
const result = await query((0, firebase_1.where)('tags', 'in', targetValue)).countDocs();
|
|
1049
1046
|
expect(result).toBe(1);
|
|
1050
|
-
})
|
|
1047
|
+
});
|
|
1051
1048
|
});
|
|
1052
1049
|
describe('array-contains', () => {
|
|
1053
|
-
it('should return the documents that contain the given value.', () =>
|
|
1050
|
+
it('should return the documents that contain the given value.', async () => {
|
|
1054
1051
|
const targetValue = '0';
|
|
1055
|
-
const result =
|
|
1052
|
+
const result = await query((0, firebase_1.where)('tags', 'array-contains', targetValue)).getDocs();
|
|
1056
1053
|
expect(result.docs.length).toBe(1);
|
|
1057
1054
|
expect(result.docs[0].data().value).toBe('0');
|
|
1058
|
-
})
|
|
1059
|
-
(0, test_1.itShouldFail)('if an array is passed to where with array-contains', () =>
|
|
1055
|
+
});
|
|
1056
|
+
(0, test_1.itShouldFail)('if an array is passed to where with array-contains', async () => {
|
|
1060
1057
|
const targetValues = ['0', 'even'];
|
|
1061
|
-
|
|
1062
|
-
})
|
|
1058
|
+
await (0, test_1.expectFail)(() => query((0, firebase_1.where)('tags', 'array-contains', targetValues)).getDocs());
|
|
1059
|
+
});
|
|
1063
1060
|
});
|
|
1064
1061
|
describe('array-contains-any', () => {
|
|
1065
|
-
it('should return the documents that contain the given value, even if it is not passed as an array.', () =>
|
|
1062
|
+
it('should return the documents that contain the given value, even if it is not passed as an array.', async () => {
|
|
1066
1063
|
const targetValues = 'even';
|
|
1067
|
-
const result =
|
|
1064
|
+
const result = await query((0, firebase_1.where)('tags', 'array-contains-any', targetValues)).getDocs();
|
|
1068
1065
|
expect(result.docs.length).toBe(Math.floor(testDocumentCount / 2) + 1);
|
|
1069
1066
|
result.docs.forEach((x) => {
|
|
1070
1067
|
expect((0, util_1.isEvenNumber)(Number(x.data().value)));
|
|
1071
1068
|
});
|
|
1072
|
-
})
|
|
1073
|
-
it('should return the documents that contain any of the given values.', () =>
|
|
1069
|
+
});
|
|
1070
|
+
it('should return the documents that contain any of the given values.', async () => {
|
|
1074
1071
|
const targetValues = ['0', 'even'];
|
|
1075
|
-
const result =
|
|
1072
|
+
const result = await query((0, firebase_1.where)('tags', 'array-contains-any', targetValues)).getDocs();
|
|
1076
1073
|
expect(result.docs.length).toBe(Math.floor(testDocumentCount / 2) + 1);
|
|
1077
1074
|
result.docs.forEach((x) => {
|
|
1078
1075
|
expect((0, util_1.isEvenNumber)(Number(x.data().value)));
|
|
1079
1076
|
});
|
|
1080
|
-
})
|
|
1077
|
+
});
|
|
1081
1078
|
});
|
|
1082
1079
|
});
|
|
1083
1080
|
describe('Compound Queries', () => {
|
|
@@ -1088,8 +1085,8 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
1088
1085
|
const evenPrefix = mock_1.mockItemIdentity.collectionType + '/';
|
|
1089
1086
|
const oddPrefix = mock_1.mockItemIdentity.collectionType + 'd' + '/'; // similar, but not quite the same
|
|
1090
1087
|
const expectedNumberOfEvenValues = Math.ceil(testDocumentCount / 2);
|
|
1091
|
-
beforeEach(() =>
|
|
1092
|
-
items =
|
|
1088
|
+
beforeEach(async () => {
|
|
1089
|
+
items = await (0, firebase_1.makeDocuments)(f.instance.firestoreCollection.documentAccessor(), {
|
|
1093
1090
|
count: testDocumentCount,
|
|
1094
1091
|
init: (i) => {
|
|
1095
1092
|
const isEven = (0, util_1.isEvenNumber)(i);
|
|
@@ -1102,30 +1099,30 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
1102
1099
|
};
|
|
1103
1100
|
}
|
|
1104
1101
|
});
|
|
1105
|
-
})
|
|
1102
|
+
});
|
|
1106
1103
|
describe('whereStringHasRootIdentityModelKey()', () => {
|
|
1107
|
-
it('should return only models with searched prefix', () =>
|
|
1108
|
-
const result =
|
|
1104
|
+
it('should return only models with searched prefix', async () => {
|
|
1105
|
+
const result = await query((0, firebase_1.whereStringHasRootIdentityModelKey)('value', mock_1.mockItemIdentity)).getDocs();
|
|
1109
1106
|
const values = result.docs.map((x) => x.data().value);
|
|
1110
1107
|
values.forEach((x) => {
|
|
1111
1108
|
expect(x.startsWith(evenPrefix));
|
|
1112
1109
|
});
|
|
1113
1110
|
expect(result.docs.length).toBe(expectedNumberOfEvenValues);
|
|
1114
|
-
})
|
|
1115
|
-
it('should return the count of only models with searched prefix', () =>
|
|
1116
|
-
const result =
|
|
1111
|
+
});
|
|
1112
|
+
it('should return the count of only models with searched prefix', async () => {
|
|
1113
|
+
const result = await query((0, firebase_1.whereStringHasRootIdentityModelKey)('value', mock_1.mockItemIdentity)).countDocs();
|
|
1117
1114
|
expect(result).toBe(expectedNumberOfEvenValues);
|
|
1118
|
-
})
|
|
1115
|
+
});
|
|
1119
1116
|
});
|
|
1120
1117
|
describe('whereStringValueHasPrefix()', () => {
|
|
1121
|
-
it('should return only models with searched prefix', () =>
|
|
1122
|
-
const result =
|
|
1118
|
+
it('should return only models with searched prefix', async () => {
|
|
1119
|
+
const result = await query((0, firebase_1.whereStringValueHasPrefix)('value', evenPrefix)).getDocs();
|
|
1123
1120
|
const values = result.docs.map((x) => x.data().value);
|
|
1124
1121
|
values.forEach((x) => {
|
|
1125
1122
|
expect(x.startsWith(evenPrefix));
|
|
1126
1123
|
});
|
|
1127
1124
|
expect(result.docs.length).toBe(expectedNumberOfEvenValues);
|
|
1128
|
-
})
|
|
1125
|
+
});
|
|
1129
1126
|
});
|
|
1130
1127
|
});
|
|
1131
1128
|
/**
|
|
@@ -1133,130 +1130,119 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
1133
1130
|
*/
|
|
1134
1131
|
describe('Searching Date Strings', () => {
|
|
1135
1132
|
describe('whereDateIsAfterWithSort()', () => {
|
|
1136
|
-
it('should return models with dates after the input.', () =>
|
|
1137
|
-
var _a, _b;
|
|
1133
|
+
it('should return models with dates after the input.', async () => {
|
|
1138
1134
|
const startHoursLater = 2;
|
|
1139
1135
|
const start = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1140
|
-
const result =
|
|
1136
|
+
const result = await query((0, firebase_1.whereDateIsAfterWithSort)('date', start)).getDocs();
|
|
1141
1137
|
expect(result.docs.length).toBe(startHoursLater);
|
|
1142
1138
|
// ascending order by default
|
|
1143
|
-
expect(
|
|
1144
|
-
expect(
|
|
1145
|
-
})
|
|
1146
|
-
it('should return models with dates after the input in descending order.', () =>
|
|
1147
|
-
var _c, _d;
|
|
1139
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 1).toISOString());
|
|
1140
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 2).toISOString());
|
|
1141
|
+
});
|
|
1142
|
+
it('should return models with dates after the input in descending order.', async () => {
|
|
1148
1143
|
const startHoursLater = 2;
|
|
1149
1144
|
const start = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1150
|
-
const result =
|
|
1145
|
+
const result = await query((0, firebase_1.whereDateIsAfterWithSort)('date', start, 'desc')).getDocs();
|
|
1151
1146
|
expect(result.docs.length).toBe(startHoursLater);
|
|
1152
1147
|
// check descending order
|
|
1153
|
-
expect(
|
|
1154
|
-
expect(
|
|
1155
|
-
})
|
|
1148
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 2).toISOString());
|
|
1149
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 1).toISOString());
|
|
1150
|
+
});
|
|
1156
1151
|
});
|
|
1157
1152
|
describe('whereDateIsBeforeWithSort()', () => {
|
|
1158
|
-
it('should return models with dates before the input.', () =>
|
|
1159
|
-
var _a, _b;
|
|
1153
|
+
it('should return models with dates before the input.', async () => {
|
|
1160
1154
|
const startHoursLater = 2;
|
|
1161
1155
|
const endDate = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1162
|
-
const result =
|
|
1156
|
+
const result = await query((0, firebase_1.whereDateIsBeforeWithSort)('date', endDate)).getDocs();
|
|
1163
1157
|
expect(result.docs.length).toBe(startHoursLater);
|
|
1164
1158
|
// descending order by default
|
|
1165
|
-
expect(
|
|
1166
|
-
expect(
|
|
1167
|
-
})
|
|
1168
|
-
it('should return models with dates before the input in ascending order.', () =>
|
|
1169
|
-
var _c, _d;
|
|
1159
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -1).toISOString());
|
|
1160
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -2).toISOString());
|
|
1161
|
+
});
|
|
1162
|
+
it('should return models with dates before the input in ascending order.', async () => {
|
|
1170
1163
|
const startHoursLater = 2;
|
|
1171
1164
|
const endDate = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1172
|
-
const result =
|
|
1165
|
+
const result = await query((0, firebase_1.whereDateIsBeforeWithSort)('date', endDate, 'asc')).getDocs();
|
|
1173
1166
|
expect(result.docs.length).toBe(startHoursLater);
|
|
1174
1167
|
// check ascending order
|
|
1175
|
-
expect(
|
|
1176
|
-
expect(
|
|
1177
|
-
})
|
|
1168
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -2).toISOString());
|
|
1169
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -1).toISOString());
|
|
1170
|
+
});
|
|
1178
1171
|
});
|
|
1179
1172
|
describe('whereDateIsOnOrAfterWithSort()', () => {
|
|
1180
|
-
it('should return models with dates after the input.', () =>
|
|
1181
|
-
var _a, _b, _c;
|
|
1173
|
+
it('should return models with dates after the input.', async () => {
|
|
1182
1174
|
const startHoursLater = 2;
|
|
1183
1175
|
const start = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1184
|
-
const result =
|
|
1176
|
+
const result = await query((0, firebase_1.whereDateIsOnOrAfterWithSort)('date', start)).getDocs();
|
|
1185
1177
|
expect(result.docs.length).toBe(3);
|
|
1186
1178
|
// ascending order by default
|
|
1187
|
-
expect(
|
|
1188
|
-
expect(
|
|
1189
|
-
expect(
|
|
1190
|
-
})
|
|
1191
|
-
it('should return models with dates after the input in descending order.', () =>
|
|
1192
|
-
var _d, _e, _f;
|
|
1179
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 0).toISOString());
|
|
1180
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 1).toISOString());
|
|
1181
|
+
expect(result.docs[2].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 2).toISOString());
|
|
1182
|
+
});
|
|
1183
|
+
it('should return models with dates after the input in descending order.', async () => {
|
|
1193
1184
|
const startHoursLater = 2;
|
|
1194
1185
|
const start = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1195
|
-
const result =
|
|
1186
|
+
const result = await query((0, firebase_1.whereDateIsOnOrAfterWithSort)('date', start, 'desc')).getDocs();
|
|
1196
1187
|
expect(result.docs.length).toBe(3);
|
|
1197
1188
|
// check descending order
|
|
1198
|
-
expect(
|
|
1199
|
-
expect(
|
|
1200
|
-
expect(
|
|
1201
|
-
})
|
|
1189
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 2).toISOString());
|
|
1190
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 1).toISOString());
|
|
1191
|
+
expect(result.docs[2].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 0).toISOString());
|
|
1192
|
+
});
|
|
1202
1193
|
});
|
|
1203
1194
|
describe('whereDateIsOnOrBeforeWithSort()', () => {
|
|
1204
|
-
it('should return models with dates before the input.', () =>
|
|
1205
|
-
var _a, _b, _c;
|
|
1195
|
+
it('should return models with dates before the input.', async () => {
|
|
1206
1196
|
const startHoursLater = 2;
|
|
1207
1197
|
const endDate = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1208
|
-
const result =
|
|
1198
|
+
const result = await query((0, firebase_1.whereDateIsOnOrBeforeWithSort)('date', endDate)).getDocs();
|
|
1209
1199
|
expect(result.docs.length).toBe(3);
|
|
1210
1200
|
// descending order by default
|
|
1211
|
-
expect(
|
|
1212
|
-
expect(
|
|
1213
|
-
expect(
|
|
1214
|
-
})
|
|
1215
|
-
it('should return models with dates before the input in ascending order.', () =>
|
|
1216
|
-
var _d, _e, _f;
|
|
1201
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, 0).toISOString());
|
|
1202
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -1).toISOString());
|
|
1203
|
+
expect(result.docs[2].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -2).toISOString());
|
|
1204
|
+
});
|
|
1205
|
+
it('should return models with dates before the input in ascending order.', async () => {
|
|
1217
1206
|
const startHoursLater = 2;
|
|
1218
1207
|
const endDate = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1219
|
-
const result =
|
|
1208
|
+
const result = await query((0, firebase_1.whereDateIsOnOrBeforeWithSort)('date', endDate, 'asc')).getDocs();
|
|
1220
1209
|
expect(result.docs.length).toBe(3);
|
|
1221
1210
|
// check ascending order
|
|
1222
|
-
expect(
|
|
1223
|
-
expect(
|
|
1224
|
-
expect(
|
|
1225
|
-
})
|
|
1211
|
+
expect(result.docs[0].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -2).toISOString());
|
|
1212
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, -1).toISOString());
|
|
1213
|
+
expect(result.docs[2].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(endDate, 0).toISOString());
|
|
1214
|
+
});
|
|
1226
1215
|
});
|
|
1227
1216
|
describe('whereDateIsInRange()', () => {
|
|
1228
|
-
it('should return the date values within the given range.', () =>
|
|
1229
|
-
var _a, _b;
|
|
1217
|
+
it('should return the date values within the given range.', async () => {
|
|
1230
1218
|
const startHoursLater = 1;
|
|
1231
1219
|
const totalHoursInRange = 2;
|
|
1232
1220
|
const start = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1233
|
-
const result =
|
|
1221
|
+
const result = await query((0, firebase_1.whereDateIsInRange)('date', { date: start, distance: totalHoursInRange - 1, type: date_1.DateRangeType.HOURS_RANGE })).getDocs();
|
|
1234
1222
|
expect(result.docs.length).toBe(totalHoursInRange);
|
|
1235
|
-
expect(
|
|
1236
|
-
expect(
|
|
1237
|
-
})
|
|
1223
|
+
expect(result.docs[0].data().date?.toISOString()).toBe(start.toISOString());
|
|
1224
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 1).toISOString());
|
|
1225
|
+
});
|
|
1238
1226
|
});
|
|
1239
1227
|
describe('whereDateIsBetween()', () => {
|
|
1240
|
-
it('should return the date values within the given range.', () =>
|
|
1241
|
-
var _a, _b;
|
|
1228
|
+
it('should return the date values within the given range.', async () => {
|
|
1242
1229
|
const startHoursLater = 1;
|
|
1243
1230
|
const hoursRange = 2;
|
|
1244
1231
|
const start = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1245
1232
|
const end = (0, date_fns_1.addHours)(start, hoursRange);
|
|
1246
|
-
const result =
|
|
1233
|
+
const result = await query((0, firebase_1.whereDateIsBetween)('date', { start, end })).getDocs();
|
|
1247
1234
|
expect(result.docs.length).toBe(hoursRange);
|
|
1248
|
-
expect(
|
|
1249
|
-
expect(
|
|
1250
|
-
})
|
|
1235
|
+
expect(result.docs[0].data().date?.toISOString()).toBe(start.toISOString());
|
|
1236
|
+
expect(result.docs[1].data().date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 1).toISOString());
|
|
1237
|
+
});
|
|
1251
1238
|
describe('with searching array value', () => {
|
|
1252
|
-
it('should search the date range and values that are tagged even.', () =>
|
|
1253
|
-
var _a;
|
|
1239
|
+
it('should search the date range and values that are tagged even.', async () => {
|
|
1254
1240
|
const targetTag = 'even';
|
|
1255
1241
|
const startHoursLater = 1;
|
|
1256
1242
|
const hoursRange = 2;
|
|
1257
1243
|
const start = (0, date_fns_1.addHours)(startDate, startHoursLater);
|
|
1258
1244
|
const end = (0, date_fns_1.addHours)(start, hoursRange);
|
|
1259
|
-
const result =
|
|
1245
|
+
const result = await query([
|
|
1260
1246
|
// filter by dates first
|
|
1261
1247
|
...(0, firebase_1.whereDateIsBetween)('date', { start, end }),
|
|
1262
1248
|
// only allow even items
|
|
@@ -1264,104 +1250,104 @@ function describeFirestoreQueryDriverTests(f) {
|
|
|
1264
1250
|
]).getDocs();
|
|
1265
1251
|
expect(result.docs.length).toBe(1);
|
|
1266
1252
|
const onlyResultData = result.docs[0].data();
|
|
1267
|
-
expect(
|
|
1253
|
+
expect(onlyResultData.date?.toISOString()).toBe((0, date_fns_1.addHours)(start, 1).toISOString());
|
|
1268
1254
|
expect(onlyResultData.tags).toContain(targetTag);
|
|
1269
|
-
})
|
|
1255
|
+
});
|
|
1270
1256
|
});
|
|
1271
1257
|
});
|
|
1272
1258
|
});
|
|
1273
1259
|
});
|
|
1274
1260
|
});
|
|
1275
1261
|
describe('whereDocumentId', () => {
|
|
1276
|
-
it('should return the documents matching the query.', () =>
|
|
1262
|
+
it('should return the documents matching the query.', async () => {
|
|
1277
1263
|
const targetId = items[0].id;
|
|
1278
|
-
const result =
|
|
1264
|
+
const result = await query((0, firebase_1.whereDocumentId)('==', targetId)).getDocs();
|
|
1279
1265
|
expect(result.docs.length).toBe(1);
|
|
1280
1266
|
expect(result.docs[0].id).toBe(targetId);
|
|
1281
|
-
})
|
|
1267
|
+
});
|
|
1282
1268
|
});
|
|
1283
1269
|
describe('startAt', () => {
|
|
1284
|
-
it('should return values starting from the specified startAt document.', () =>
|
|
1270
|
+
it('should return values starting from the specified startAt document.', async () => {
|
|
1285
1271
|
const limitCount = 2;
|
|
1286
1272
|
const firstQuery = query((0, firebase_1.limit)(limitCount));
|
|
1287
|
-
const first =
|
|
1273
|
+
const first = await firstQuery.getDocs();
|
|
1288
1274
|
expect(first.docs.length).toBe(limitCount);
|
|
1289
|
-
const second =
|
|
1275
|
+
const second = await firstQuery.filter((0, firebase_1.startAt)(first.docs[1])).getDocs();
|
|
1290
1276
|
expect(second.docs.length).toBe(limitCount);
|
|
1291
1277
|
expect(second.docs[0].id).toBe(first.docs[1].id);
|
|
1292
|
-
})
|
|
1293
|
-
it('should return the count of values starting from the specified startAt document.', () =>
|
|
1278
|
+
});
|
|
1279
|
+
it('should return the count of values starting from the specified startAt document.', async () => {
|
|
1294
1280
|
const limitCount = 2;
|
|
1295
1281
|
const firstQuery = query((0, firebase_1.limit)(limitCount));
|
|
1296
|
-
const first =
|
|
1282
|
+
const first = await firstQuery.getDocs();
|
|
1297
1283
|
expect(first.docs.length).toBe(limitCount);
|
|
1298
1284
|
// NOTE: startAt with count requires an orderBy to be set.
|
|
1299
|
-
const secondCount =
|
|
1285
|
+
const secondCount = await firstQuery.filter((0, firebase_1.orderByDocumentId)(), (0, firebase_1.startAt)(first.docs[1])).countDocs();
|
|
1300
1286
|
expect(secondCount).toBe(limitCount);
|
|
1301
|
-
})
|
|
1287
|
+
});
|
|
1302
1288
|
});
|
|
1303
1289
|
describe('startAtValue', () => {
|
|
1304
|
-
it('should return values starting from the specified startAt path.', () =>
|
|
1290
|
+
it('should return values starting from the specified startAt path.', async () => {
|
|
1305
1291
|
const limitCount = testDocumentCount;
|
|
1306
1292
|
const firstQuery = query((0, firebase_1.orderBy)('value'), (0, firebase_1.limit)(limitCount));
|
|
1307
|
-
const first =
|
|
1293
|
+
const first = await firstQuery.getDocs();
|
|
1308
1294
|
expect(first.docs.length).toBe(limitCount);
|
|
1309
1295
|
const indexToStartAt = 3;
|
|
1310
1296
|
const docToStartAt = first.docs[indexToStartAt];
|
|
1311
1297
|
const docToStartAtValue = docToStartAt.data().value;
|
|
1312
|
-
const second =
|
|
1298
|
+
const second = await firstQuery.filter((0, firebase_1.startAtValue)(docToStartAtValue)).getDocs();
|
|
1313
1299
|
expect(second.docs.length).toBe(limitCount - indexToStartAt);
|
|
1314
1300
|
expect(second.docs[0].id).toBe(docToStartAt.id);
|
|
1315
|
-
})
|
|
1301
|
+
});
|
|
1316
1302
|
});
|
|
1317
1303
|
describe('startAfter', () => {
|
|
1318
|
-
it('should return values starting after the specified startAt point.', () =>
|
|
1304
|
+
it('should return values starting after the specified startAt point.', async () => {
|
|
1319
1305
|
const limitCount = 3;
|
|
1320
1306
|
const firstQuery = query((0, firebase_1.limit)(limitCount));
|
|
1321
|
-
const first =
|
|
1307
|
+
const first = await firstQuery.getDocs();
|
|
1322
1308
|
expect(first.docs.length).toBe(limitCount);
|
|
1323
1309
|
const startAfterDoc = first.docs[1];
|
|
1324
1310
|
const expectedFirstDoc = first.docs[2];
|
|
1325
|
-
const second =
|
|
1311
|
+
const second = await firstQuery.filter((0, firebase_1.startAfter)(startAfterDoc)).getDocs();
|
|
1326
1312
|
expect(second.docs.length).toBe(limitCount);
|
|
1327
1313
|
expect(second.docs[0].id).toBe(expectedFirstDoc.id);
|
|
1328
|
-
})
|
|
1314
|
+
});
|
|
1329
1315
|
});
|
|
1330
1316
|
describe('endAt', () => {
|
|
1331
|
-
it('should return values ending with the specified endAt point (inclusive).', () =>
|
|
1317
|
+
it('should return values ending with the specified endAt point (inclusive).', async () => {
|
|
1332
1318
|
const limitCount = 2;
|
|
1333
1319
|
const firstQuery = query((0, firebase_1.limit)(limitCount));
|
|
1334
|
-
const first =
|
|
1320
|
+
const first = await firstQuery.getDocs();
|
|
1335
1321
|
expect(first.docs.length).toBe(limitCount);
|
|
1336
|
-
const second =
|
|
1322
|
+
const second = await firstQuery.filter((0, firebase_1.endAt)(first.docs[0])).getDocs();
|
|
1337
1323
|
expect(second.docs.length).toBe(limitCount - 1);
|
|
1338
1324
|
expect(second.docs[0].id).toBe(first.docs[0].id);
|
|
1339
|
-
})
|
|
1325
|
+
});
|
|
1340
1326
|
});
|
|
1341
1327
|
describe('endAtValue', () => {
|
|
1342
|
-
it('should return values starting from the specified startAt path.', () =>
|
|
1328
|
+
it('should return values starting from the specified startAt path.', async () => {
|
|
1343
1329
|
const limitCount = testDocumentCount;
|
|
1344
1330
|
const firstQuery = query((0, firebase_1.orderBy)('value'), (0, firebase_1.limit)(limitCount));
|
|
1345
|
-
const first =
|
|
1331
|
+
const first = await firstQuery.getDocs();
|
|
1346
1332
|
expect(first.docs.length).toBe(limitCount);
|
|
1347
1333
|
const indexToEndAt = 2;
|
|
1348
1334
|
const docToEndAt = first.docs[indexToEndAt];
|
|
1349
1335
|
const docToEndAtValue = docToEndAt.data().value;
|
|
1350
|
-
const second =
|
|
1336
|
+
const second = await firstQuery.filter((0, firebase_1.endAtValue)(docToEndAtValue)).getDocs();
|
|
1351
1337
|
expect(second.docs.length).toBe(indexToEndAt + 1);
|
|
1352
1338
|
expect(second.docs[second.docs.length - 1].id).toBe(docToEndAt.id);
|
|
1353
|
-
})
|
|
1339
|
+
});
|
|
1354
1340
|
});
|
|
1355
1341
|
describe('endBefore', () => {
|
|
1356
|
-
it('should return values ending with the specified endBefore point (exclusive).', () =>
|
|
1342
|
+
it('should return values ending with the specified endBefore point (exclusive).', async () => {
|
|
1357
1343
|
const limitCount = 2;
|
|
1358
1344
|
const firstQuery = query((0, firebase_1.limit)(limitCount));
|
|
1359
|
-
const first =
|
|
1345
|
+
const first = await firstQuery.getDocs();
|
|
1360
1346
|
expect(first.docs.length).toBe(limitCount);
|
|
1361
|
-
const second =
|
|
1347
|
+
const second = await firstQuery.filter((0, firebase_1.endBefore)(first.docs[1])).getDocs();
|
|
1362
1348
|
expect(second.docs.length).toBe(limitCount - 1);
|
|
1363
1349
|
expect(second.docs[0].id).toBe(first.docs[0].id);
|
|
1364
|
-
})
|
|
1350
|
+
});
|
|
1365
1351
|
});
|
|
1366
1352
|
});
|
|
1367
1353
|
});
|