diff --git a/dev/system-test/firestore.ts b/dev/system-test/firestore.ts index f57c2767c..75effe098 100644 --- a/dev/system-test/firestore.ts +++ b/dev/system-test/firestore.ts @@ -4019,6 +4019,47 @@ describe('Query class', () => { unsubscribe(); }); + it('snapshot listener sorts cross type numbers same way as server', async () => { + const batch = firestore.batch(); + batch.set(randomCol.doc('longMin'), { + value: BigInt('-9223372036854775808'), + }); // this gets converted to number and looses precision + batch.set(randomCol.doc('longMax'), { + value: BigInt('9223372036854775807'), + }); + batch.set(randomCol.doc('NaN'), {value: NaN}); + batch.set(randomCol.doc('maxSafeInteger'), { + value: Number.MAX_SAFE_INTEGER, + }); + batch.set(randomCol.doc('minSafeInteger'), { + value: Number.MIN_SAFE_INTEGER, + }); + batch.set(randomCol.doc('maxValue'), {value: Number.MAX_VALUE}); + batch.set(randomCol.doc('negativeMaxValue'), {value: -Number.MAX_VALUE}); + batch.set(randomCol.doc('minValue'), {value: Number.MIN_VALUE}); + batch.set(randomCol.doc('negativeMinValue'), {value: -Number.MIN_VALUE}); + batch.set(randomCol.doc('negativeInfinity'), {value: -Infinity}); + batch.set(randomCol.doc('positiveInfinity'), {value: Infinity}); + await batch.commit(); + + const query = randomCol.orderBy('value'); + + const getSnapshot = await query.get(); + + const unsubscribe = query.onSnapshot(snapshot => + currentDeferred.resolve(snapshot) + ); + + const watchSnapshot = await waitForSnapshot(); + + // Compare the snapshot (including sort order) of a snapshot + snapshotsEqual(watchSnapshot, { + docs: getSnapshot.docs, + docChanges: getSnapshot.docChanges(), + }); + unsubscribe(); + }); + it('SDK orders vector field same way as backend', async () => { // We validate that the SDK orders the vector field the same way as the backend // by comparing the sort order of vector fields from a Query.get() and