Skip to content

Commit 2a3a7df

Browse files
committed
Add integration test.
1 parent 6251a28 commit 2a3a7df

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ import {
3737
endAt,
3838
endBefore,
3939
GeoPoint,
40+
getDocFromCache,
4041
getDocs,
4142
limit,
4243
limitToLast,
44+
loadBundle,
4345
onSnapshot,
4446
or,
4547
orderBy,
@@ -74,6 +76,44 @@ import { captureExistenceFilterMismatches } from '../util/testing_hooks_util';
7476
apiDescribe('Queries', persistence => {
7577
addEqualityMatcher();
7678

79+
it('QuerySnapshot.toJSON bundle getDocFromCache', async () => {
80+
let path: string | null = null;
81+
let jsonBundle: object | null = null;
82+
const testDocs = {
83+
a: { k: 'a' },
84+
b: { k: 'b' },
85+
c: { k: 'c' }
86+
};
87+
// Write an initial document in an isolated Firestore instance so it's not stored in the cache.
88+
await withTestCollection(persistence, testDocs, async collection => {
89+
await getDocs(query(collection)).then(querySnapshot => {
90+
expect(querySnapshot.docs.length).to.equal(3);
91+
// Find the path to a known doc.
92+
querySnapshot.docs.forEach(docSnapshot => {
93+
if (docSnapshot.ref.path.endsWith('a')) {
94+
path = docSnapshot.ref.path;
95+
}
96+
});
97+
expect(path).to.not.be.null;
98+
jsonBundle = querySnapshot.toJSON();
99+
});
100+
});
101+
expect(jsonBundle).to.not.be.null;
102+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
103+
const json = (jsonBundle as any).bundle;
104+
expect(json).to.exist;
105+
expect(json.length).to.be.greaterThan(0);
106+
// Use a new instance to load the bundle to ensure that the cache is primed by the bundle and
107+
// not the previous getDocs call.
108+
await withTestDb(persistence, async db => {
109+
await loadBundle(db, json);
110+
const docRef = doc(db, path!);
111+
const docSnap = await getDocFromCache(docRef);
112+
expect(docSnap.exists);
113+
expect(docSnap.data()).to.deep.equal(testDocs.a);
114+
});
115+
});
116+
77117
it('can issue limit queries', () => {
78118
const testDocs = {
79119
a: { k: 'a' },

0 commit comments

Comments
 (0)