@@ -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,47 @@ import { captureExistenceFilterMismatches } from '../util/testing_hooks_util';
7476apiDescribe ( '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+ console . log ( "DEDB checking if json exists" ) ;
105+ expect ( json ) . to . exist ;
106+ expect ( json . length ) . to . be . greaterThan ( 0 ) ;
107+
108+ if ( path !== null ) {
109+ await withTestDb ( persistence , async db => {
110+ const docRef = doc ( db , path ! ) ;
111+ await loadBundle ( db , json ) ;
112+ const docSnap = await getDocFromCache ( docRef ) ;
113+ console . log ( "DEDB checking if docSnap exists" ) ;
114+ expect ( docSnap . exists ) ;
115+ expect ( docSnap . data ( ) ) . to . deep . equal ( testDocs . a ) ;
116+ } ) ;
117+ }
118+ } ) ;
119+
77120 it ( 'can issue limit queries' , ( ) => {
78121 const testDocs = {
79122 a : { k : 'a' } ,
0 commit comments