Skip to content

Commit cbba951

Browse files
committed
resolve TODOs
1 parent 4600a34 commit cbba951

File tree

4 files changed

+60
-63
lines changed

4 files changed

+60
-63
lines changed

packages/firestore/src/model/values.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ function compareRegex(left: Value, right: Value): number {
644644
]?.stringValue ?? '';
645645

646646
// First order by patterns, and then options.
647-
const patternDiff = primitiveComparator(leftPattern, rightPattern);
647+
const patternDiff = compareUtf8Strings(leftPattern, rightPattern);
648648
return patternDiff !== 0
649649
? patternDiff
650650
: primitiveComparator(leftOptions, rightOptions);
@@ -656,8 +656,7 @@ function compareBsonObjectIds(left: Value, right: Value): number {
656656
const rightOid =
657657
right.mapValue!.fields?.[RESERVED_BSON_OBJECT_ID_KEY]?.stringValue ?? '';
658658

659-
// TODO(Mila/BSON): use compareUtf8Strings once the bug fix is merged.
660-
return primitiveComparator(leftOid, rightOid);
659+
return compareUtf8Strings(leftOid, rightOid);
661660
}
662661

663662
/**

packages/firestore/test/integration/api/database.test.ts

+49-54
Original file line numberDiff line numberDiff line change
@@ -2818,9 +2818,6 @@ apiDescribe('Database', persistence => {
28182818
settings,
28192819
testDocs,
28202820
async coll => {
2821-
// Populate the cache with all docs first
2822-
await getDocs(coll);
2823-
28242821
let orderedQuery = query(
28252822
coll,
28262823
where('key', '>', new BsonObjectId('507f191e810c19729de860ea')),
@@ -2833,6 +2830,7 @@ apiDescribe('Database', persistence => {
28332830
testDocs['b']
28342831
]);
28352832
await assertSDKQueryResultsConsistentWithBackend(
2833+
coll,
28362834
orderedQuery,
28372835
testDocs,
28382836
toIds(snapshot)
@@ -2853,6 +2851,7 @@ apiDescribe('Database', persistence => {
28532851
testDocs['a']
28542852
]);
28552853
await assertSDKQueryResultsConsistentWithBackend(
2854+
coll,
28562855
orderedQuery,
28572856
testDocs,
28582857
toIds(snapshot)
@@ -2873,9 +2872,6 @@ apiDescribe('Database', persistence => {
28732872
settings,
28742873
testDocs,
28752874
async coll => {
2876-
// Populate the cache with all docs first
2877-
await getDocs(coll);
2878-
28792875
let orderedQuery = query(
28802876
coll,
28812877
where('key', '>=', new Int32Value(1)),
@@ -2888,6 +2884,7 @@ apiDescribe('Database', persistence => {
28882884
testDocs['b']
28892885
]);
28902886
await assertSDKQueryResultsConsistentWithBackend(
2887+
coll,
28912888
orderedQuery,
28922889
testDocs,
28932890
toIds(snapshot)
@@ -2905,6 +2902,7 @@ apiDescribe('Database', persistence => {
29052902
testDocs['a']
29062903
]);
29072904
await assertSDKQueryResultsConsistentWithBackend(
2905+
coll,
29082906
orderedQuery,
29092907
testDocs,
29102908
toIds(snapshot)
@@ -2925,9 +2923,6 @@ apiDescribe('Database', persistence => {
29252923
settings,
29262924
testDocs,
29272925
async coll => {
2928-
// Populate the cache with all docs first
2929-
await getDocs(coll);
2930-
29312926
let orderedQuery = query(
29322927
coll,
29332928
where('key', '>', new BsonTimestamp(1, 1)),
@@ -2940,6 +2935,7 @@ apiDescribe('Database', persistence => {
29402935
testDocs['b']
29412936
]);
29422937
await assertSDKQueryResultsConsistentWithBackend(
2938+
coll,
29432939
orderedQuery,
29442940
testDocs,
29452941
toIds(snapshot)
@@ -2957,6 +2953,7 @@ apiDescribe('Database', persistence => {
29572953
testDocs['b']
29582954
]);
29592955
await assertSDKQueryResultsConsistentWithBackend(
2956+
coll,
29602957
orderedQuery,
29612958
testDocs,
29622959
toIds(snapshot)
@@ -2977,9 +2974,6 @@ apiDescribe('Database', persistence => {
29772974
settings,
29782975
testDocs,
29792976
async coll => {
2980-
// Populate the cache with all docs first
2981-
await getDocs(coll);
2982-
29832977
let orderedQuery = query(
29842978
coll,
29852979
where('key', '>', new BsonBinaryData(1, new Uint8Array([1, 2, 3]))),
@@ -2992,6 +2986,7 @@ apiDescribe('Database', persistence => {
29922986
testDocs['b']
29932987
]);
29942988
await assertSDKQueryResultsConsistentWithBackend(
2989+
coll,
29952990
orderedQuery,
29962991
testDocs,
29972992
toIds(snapshot)
@@ -3014,6 +3009,7 @@ apiDescribe('Database', persistence => {
30143009
testDocs['a']
30153010
]);
30163011
await assertSDKQueryResultsConsistentWithBackend(
3012+
coll,
30173013
orderedQuery,
30183014
testDocs,
30193015
toIds(snapshot)
@@ -3034,9 +3030,6 @@ apiDescribe('Database', persistence => {
30343030
settings,
30353031
testDocs,
30363032
async coll => {
3037-
// Populate the cache with all docs first
3038-
await getDocs(coll);
3039-
30403033
const orderedQuery = query(
30413034
coll,
30423035
or(
@@ -3052,6 +3045,7 @@ apiDescribe('Database', persistence => {
30523045
testDocs['a']
30533046
]);
30543047
await assertSDKQueryResultsConsistentWithBackend(
3048+
coll,
30553049
orderedQuery,
30563050
testDocs,
30573051
toIds(snapshot)
@@ -3074,9 +3068,6 @@ apiDescribe('Database', persistence => {
30743068
settings,
30753069
testDocs,
30763070
async coll => {
3077-
// Populate the cache with all docs first
3078-
await getDocs(coll);
3079-
30803071
let filteredQuery = query(
30813072
coll,
30823073
where('key', '==', MinKey.instance())
@@ -3087,23 +3078,24 @@ apiDescribe('Database', persistence => {
30873078
testDocs['b']
30883079
]);
30893080
await assertSDKQueryResultsConsistentWithBackend(
3081+
coll,
30903082
filteredQuery,
30913083
testDocs,
30923084
toIds(snapshot)
30933085
);
30943086

3095-
// TODO(Mila/BSON): uncomment after the null inclusion bug
3096-
// filteredQuery = query(coll, where('key', '!=', MinKey.instance()));
3097-
// snapshot = await getDocs(filteredQuery);
3098-
// expect(toDataArray(snapshot)).to.deep.equal([
3099-
// testDocs['d'],
3100-
// testDocs['e']
3101-
// ]);
3102-
// await assertSDKQueryResultsConsistentWithBackend(
3103-
// filteredQuery,
3104-
// testDocs,
3105-
// toIds(snapshot)
3106-
// );
3087+
filteredQuery = query(coll, where('key', '!=', MinKey.instance()));
3088+
snapshot = await getDocs(filteredQuery);
3089+
expect(toDataArray(snapshot)).to.deep.equal([
3090+
testDocs['d'],
3091+
testDocs['e']
3092+
]);
3093+
await assertSDKQueryResultsConsistentWithBackend(
3094+
coll,
3095+
filteredQuery,
3096+
testDocs,
3097+
toIds(snapshot)
3098+
);
31073099

31083100
filteredQuery = query(coll, where('key', '>=', MinKey.instance()));
31093101
snapshot = await getDocs(filteredQuery);
@@ -3112,6 +3104,7 @@ apiDescribe('Database', persistence => {
31123104
testDocs['b']
31133105
]);
31143106
await assertSDKQueryResultsConsistentWithBackend(
3107+
coll,
31153108
filteredQuery,
31163109
testDocs,
31173110
toIds(snapshot)
@@ -3124,6 +3117,7 @@ apiDescribe('Database', persistence => {
31243117
testDocs['b']
31253118
]);
31263119
await assertSDKQueryResultsConsistentWithBackend(
3120+
coll,
31273121
filteredQuery,
31283122
testDocs,
31293123
toIds(snapshot)
@@ -3133,6 +3127,7 @@ apiDescribe('Database', persistence => {
31333127
snapshot = await getDocs(filteredQuery);
31343128
expect(toDataArray(snapshot)).to.deep.equal([]);
31353129
await assertSDKQueryResultsConsistentWithBackend(
3130+
coll,
31363131
filteredQuery,
31373132
testDocs,
31383133
toIds(snapshot)
@@ -3142,6 +3137,7 @@ apiDescribe('Database', persistence => {
31423137
snapshot = await getDocs(filteredQuery);
31433138
expect(toDataArray(snapshot)).to.deep.equal([]);
31443139
await assertSDKQueryResultsConsistentWithBackend(
3140+
coll,
31453141
filteredQuery,
31463142
testDocs,
31473143
toIds(snapshot)
@@ -3151,6 +3147,7 @@ apiDescribe('Database', persistence => {
31513147
snapshot = await getDocs(filteredQuery);
31523148
expect(toDataArray(snapshot)).to.deep.equal([]);
31533149
await assertSDKQueryResultsConsistentWithBackend(
3150+
coll,
31543151
filteredQuery,
31553152
testDocs,
31563153
toIds(snapshot)
@@ -3173,9 +3170,6 @@ apiDescribe('Database', persistence => {
31733170
settings,
31743171
testDocs,
31753172
async coll => {
3176-
// Populate the cache with all docs first
3177-
await getDocs(coll);
3178-
31793173
let filteredQuery = query(
31803174
coll,
31813175
where('key', '==', MaxKey.instance())
@@ -3186,23 +3180,24 @@ apiDescribe('Database', persistence => {
31863180
testDocs['d']
31873181
]);
31883182
await assertSDKQueryResultsConsistentWithBackend(
3183+
coll,
31893184
filteredQuery,
31903185
testDocs,
31913186
toIds(snapshot)
31923187
);
31933188

3194-
// TODO(Mila/BSON): uncomment after the null inclusion bug
3195-
// filteredQuery = query(coll, where('key', '!=', MaxKey.instance()));
3196-
// snapshot = await getDocs(filteredQuery);
3197-
// expect(toDataArray(snapshot)).to.deep.equal([
3198-
// testDocs['a'],
3199-
// testDocs['b']
3200-
// ]);
3201-
// await assertSDKQueryResultsConsistentWithBackend(
3202-
// filteredQuery,
3203-
// testDocs,
3204-
// toIds(snapshot)
3205-
// );
3189+
filteredQuery = query(coll, where('key', '!=', MaxKey.instance()));
3190+
snapshot = await getDocs(filteredQuery);
3191+
expect(toDataArray(snapshot)).to.deep.equal([
3192+
testDocs['a'],
3193+
testDocs['b']
3194+
]);
3195+
await assertSDKQueryResultsConsistentWithBackend(
3196+
coll,
3197+
filteredQuery,
3198+
testDocs,
3199+
toIds(snapshot)
3200+
);
32063201

32073202
filteredQuery = query(coll, where('key', '>=', MaxKey.instance()));
32083203
snapshot = await getDocs(filteredQuery);
@@ -3211,6 +3206,7 @@ apiDescribe('Database', persistence => {
32113206
testDocs['d']
32123207
]);
32133208
await assertSDKQueryResultsConsistentWithBackend(
3209+
coll,
32143210
filteredQuery,
32153211
testDocs,
32163212
toIds(snapshot)
@@ -3223,6 +3219,7 @@ apiDescribe('Database', persistence => {
32233219
testDocs['d']
32243220
]);
32253221
await assertSDKQueryResultsConsistentWithBackend(
3222+
coll,
32263223
filteredQuery,
32273224
testDocs,
32283225
toIds(snapshot)
@@ -3232,6 +3229,7 @@ apiDescribe('Database', persistence => {
32323229
snapshot = await getDocs(filteredQuery);
32333230
expect(toDataArray(snapshot)).to.deep.equal([]);
32343231
await assertSDKQueryResultsConsistentWithBackend(
3232+
coll,
32353233
filteredQuery,
32363234
testDocs,
32373235
toIds(snapshot)
@@ -3241,6 +3239,7 @@ apiDescribe('Database', persistence => {
32413239
snapshot = await getDocs(filteredQuery);
32423240
expect(toDataArray(snapshot)).to.deep.equal([]);
32433241
await assertSDKQueryResultsConsistentWithBackend(
3242+
coll,
32443243
filteredQuery,
32453244
testDocs,
32463245
toIds(snapshot)
@@ -3250,6 +3249,7 @@ apiDescribe('Database', persistence => {
32503249
snapshot = await getDocs(filteredQuery);
32513250
expect(toDataArray(snapshot)).to.deep.equal([]);
32523251
await assertSDKQueryResultsConsistentWithBackend(
3252+
coll,
32533253
filteredQuery,
32543254
testDocs,
32553255
toIds(snapshot)
@@ -3273,16 +3273,14 @@ apiDescribe('Database', persistence => {
32733273
settings,
32743274
testDocs,
32753275
async coll => {
3276-
// Populate the cache with all docs first
3277-
await getDocs(coll);
3278-
32793276
let filteredQuery = query(coll, where('key', '==', null));
32803277
let snapshot = await getDocs(filteredQuery);
32813278
expect(toDataArray(snapshot)).to.deep.equal([
32823279
testDocs['b'],
32833280
testDocs['c']
32843281
]);
32853282
await assertSDKQueryResultsConsistentWithBackend(
3283+
coll,
32863284
filteredQuery,
32873285
testDocs,
32883286
toIds(snapshot)
@@ -3296,6 +3294,7 @@ apiDescribe('Database', persistence => {
32963294
testDocs['e']
32973295
]);
32983296
await assertSDKQueryResultsConsistentWithBackend(
3297+
coll,
32993298
filteredQuery,
33003299
testDocs,
33013300
toIds(snapshot)
@@ -3424,11 +3423,9 @@ apiDescribe('Database', persistence => {
34243423
await setDoc(doc(coll, 'm'), { key: docRef });
34253424
testDocs['m'] = { key: docRef };
34263425

3427-
// Populate the cache with all docs first
3428-
await getDocs(coll);
3429-
34303426
const orderedQuery = query(coll, orderBy('key', 'desc'));
34313427
await assertSDKQueryResultsConsistentWithBackend(
3428+
coll,
34323429
orderedQuery,
34333430
testDocs,
34343431
[
@@ -3487,11 +3484,9 @@ apiDescribe('Database', persistence => {
34873484
settings,
34883485
testDocs,
34893486
async coll => {
3490-
// Populate the cache with all docs first
3491-
await getDocs(coll);
3492-
34933487
const orderedQuery = query(coll, orderBy('key'));
34943488
await assertSDKQueryResultsConsistentWithBackend(
3489+
coll,
34953490
orderedQuery,
34963491
testDocs,
34973492
[

packages/firestore/test/integration/util/helpers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,15 @@ export async function checkOnlineAndOfflineResultsMatch(
633633
* @returns {Promise<void>} A Promise that resolves when the assertions are complete.
634634
*/
635635
export async function assertSDKQueryResultsConsistentWithBackend(
636+
collection: CollectionReference,
636637
query: Query,
637638
allData: { [key: string]: DocumentData },
638639
expectedDocIds: string[]
639640
): Promise<void> {
640641
// Check the cache round trip first to make sure cache is properly populated, otherwise the
641642
// snapshot listener below will return partial results from previous
642643
// "assertSDKQueryResultsConsistentWithBackend" calls if it is called multiple times in one test
643-
await checkOnlineAndOfflineResultsMatch(query, ...expectedDocIds);
644+
await checkOnlineAndOfflineResultsMatch(collection, query, ...expectedDocIds);
644645

645646
const eventAccumulator = new EventsAccumulator<QuerySnapshot>();
646647
const unsubscribe = onSnapshot(

0 commit comments

Comments
 (0)