@@ -86,8 +86,6 @@ import { DEFAULT_SETTINGS, DEFAULT_PROJECT_ID } from '../util/settings';
86
86
87
87
use ( chaiAsPromised ) ;
88
88
89
- const SNAPSHOT_TEST_TIMEOUT = 5000 ;
90
-
91
89
apiDescribe ( 'Database' , persistence => {
92
90
it ( 'can set a document' , ( ) => {
93
91
return withTestDoc ( persistence , docRef => {
@@ -1198,7 +1196,7 @@ apiDescribe('Database', persistence => {
1198
1196
onSnapshot ( docA , ( ) => deferred2 . resolve ( ) ) ;
1199
1197
} ) ;
1200
1198
} ) ;
1201
- return Promise . all ( [ deferred1 . promise , deferred2 . promise ] ) . then ( ( ) => { } ) ;
1199
+ return Promise . all ( [ deferred1 . promise , deferred2 . promise ] ) . then ( ( ) => { } ) ;
1202
1200
} ) ;
1203
1201
} ) ;
1204
1202
@@ -1264,36 +1262,187 @@ apiDescribe('Database', persistence => {
1264
1262
) ;
1265
1263
} ) ;
1266
1264
1265
+ it ( 'DocumentSnapshot observer events for snapshot created by a bundle' , async ( ) => {
1266
+ const initialData = { a : 0 } ;
1267
+ const finalData = { a : 1 } ;
1268
+ await withTestDocAndInitialData (
1269
+ persistence ,
1270
+ initialData ,
1271
+ async ( docRef , db ) => {
1272
+ const doc = await getDoc ( docRef ) ;
1273
+ const accumulator = new EventsAccumulator < DocumentSnapshot > ( ) ;
1274
+ const unsubscribe = onSnapshot ( db , doc . toJSON ( ) , {
1275
+ next : accumulator . storeEvent
1276
+ } ) ;
1277
+ await accumulator
1278
+ . awaitEvent ( )
1279
+ . then ( snap => {
1280
+ expect ( snap . exists ( ) ) . to . be . true ;
1281
+ expect ( snap . data ( ) ) . to . deep . equal ( initialData ) ;
1282
+ } )
1283
+ . then ( ( ) => setDoc ( docRef , finalData ) )
1284
+ . then ( ( ) => accumulator . awaitEvent ( ) )
1285
+ . then ( snap => {
1286
+ expect ( snap . exists ( ) ) . to . be . true ;
1287
+ expect ( snap . data ( ) ) . to . deep . equal ( finalData ) ;
1288
+ } ) ;
1289
+ unsubscribe ( ) ;
1290
+ }
1291
+ ) ;
1292
+ } ) ;
1293
+
1294
+ it ( 'DocumentSnapshot error events for snapshot created by a bundle' , async ( ) => {
1295
+ const initialData = { a : 0 } ;
1296
+ await withTestDocAndInitialData (
1297
+ persistence ,
1298
+ initialData ,
1299
+ async ( docRef , db ) => {
1300
+ const doc = await getDoc ( docRef ) ;
1301
+ const json = doc . toJSON ( ) ;
1302
+ json . bundle = 'BadData' ;
1303
+ const deferred = new Deferred ( ) ;
1304
+ const unsubscribe = onSnapshot (
1305
+ db ,
1306
+ json ,
1307
+ ds => {
1308
+ expect ( ds ) . to . not . exist ;
1309
+ deferred . resolve ( ) ;
1310
+ } ,
1311
+ err => {
1312
+ expect ( err . name ) . to . exist ;
1313
+ expect ( err . message ) . to . exist ;
1314
+ deferred . resolve ( ) ;
1315
+ }
1316
+ ) ;
1317
+ await deferred . promise ;
1318
+ unsubscribe ( ) ;
1319
+ }
1320
+ ) ;
1321
+ } ) ;
1322
+
1323
+ it ( 'DocumentSnapshot observer error events for snapshot created by a bundle' , async ( ) => {
1324
+ const initialData = { a : 0 } ;
1325
+ await withTestDocAndInitialData (
1326
+ persistence ,
1327
+ initialData ,
1328
+ async ( docRef , db ) => {
1329
+ const doc = await getDoc ( docRef ) ;
1330
+ const json = doc . toJSON ( ) ;
1331
+ json . bundle = 'BadData' ;
1332
+ const deferred = new Deferred ( ) ;
1333
+ const unsubscribe = onSnapshot ( db , json , {
1334
+ next : ds => {
1335
+ expect ( ds ) . to . not . exist ;
1336
+ deferred . resolve ( ) ;
1337
+ } ,
1338
+ error : err => {
1339
+ expect ( err . name ) . to . exist ;
1340
+ expect ( err . message ) . to . exist ;
1341
+ deferred . resolve ( ) ;
1342
+ }
1343
+ } ) ;
1344
+ await deferred . promise ;
1345
+ unsubscribe ( ) ;
1346
+ }
1347
+ ) ;
1348
+ } ) ;
1349
+
1267
1350
it ( 'Querysnapshot events for snapshot created by a bundle' , async ( ) => {
1268
1351
const testDocs = {
1269
1352
a : { foo : 1 } ,
1270
1353
b : { bar : 2 }
1271
1354
} ;
1272
1355
await withTestCollection ( persistence , testDocs , async ( coll , db ) => {
1273
- const q = query ( coll , orderBy ( documentId ( ) ) ) ;
1274
- const querySnap = await getDocs ( q ) ;
1275
- const json = querySnap . toJSON ( ) ;
1356
+ const querySnap = await getDocs ( query ( coll , orderBy ( documentId ( ) ) ) ) ;
1276
1357
const accumulator = new EventsAccumulator < QuerySnapshot > ( ) ;
1277
1358
const unsubscribe = onSnapshot (
1278
1359
db ,
1279
- json ,
1360
+ querySnap . toJSON ( ) ,
1280
1361
accumulator . storeEvent
1281
1362
) ;
1282
- await accumulator
1283
- . awaitEvent ( )
1284
- . then ( snap => {
1285
- const docs = snap . docs ;
1286
- expect ( docs ) . not . to . be . null ;
1287
- console . error ( "DEDB lenght: " , docs . length ) ;
1288
- console . error ( "Doc0 data: " , docs [ 0 ] . data ( ) ) ;
1289
- console . error ( "Doc1 data: " , docs [ 1 ] . data ( ) ) ;
1290
- expect ( docs . length ) . to . equal ( 2 ) ;
1291
- expect ( docs [ 0 ] . data ( ) ) . to . deep . equal ( testDocs . a ) ;
1292
- expect ( docs [ 1 ] . data ( ) ) . to . deep . equal ( testDocs . b ) ;
1293
- } )
1363
+ await accumulator . awaitEvent ( ) . then ( snap => {
1364
+ expect ( snap . docs ) . not . to . be . null ;
1365
+ expect ( snap . docs . length ) . to . equal ( 2 ) ;
1366
+ expect ( snap . docs [ 0 ] . data ( ) ) . to . deep . equal ( testDocs . a ) ;
1367
+ expect ( snap . docs [ 1 ] . data ( ) ) . to . deep . equal ( testDocs . b ) ;
1368
+ } ) ;
1294
1369
unsubscribe ( ) ;
1295
- }
1296
- ) ;
1370
+ } ) ;
1371
+ } ) ;
1372
+
1373
+ it ( 'Querysnapshot observer events for snapshot created by a bundle' , async ( ) => {
1374
+ const testDocs = {
1375
+ a : { foo : 1 } ,
1376
+ b : { bar : 2 }
1377
+ } ;
1378
+ await withTestCollection ( persistence , testDocs , async ( coll , db ) => {
1379
+ const querySnap = await getDocs ( query ( coll , orderBy ( documentId ( ) ) ) ) ;
1380
+ const accumulator = new EventsAccumulator < QuerySnapshot > ( ) ;
1381
+ const unsubscribe = onSnapshot ( db , querySnap . toJSON ( ) , {
1382
+ next : accumulator . storeEvent
1383
+ } ) ;
1384
+ await accumulator . awaitEvent ( ) . then ( snap => {
1385
+ expect ( snap . docs ) . not . to . be . null ;
1386
+ expect ( snap . docs . length ) . to . equal ( 2 ) ;
1387
+ expect ( snap . docs [ 0 ] . data ( ) ) . to . deep . equal ( testDocs . a ) ;
1388
+ expect ( snap . docs [ 1 ] . data ( ) ) . to . deep . equal ( testDocs . b ) ;
1389
+ } ) ;
1390
+ unsubscribe ( ) ;
1391
+ } ) ;
1392
+ } ) ;
1393
+
1394
+ it ( 'QuerySnapshot error events for snapshot created by a bundle' , async ( ) => {
1395
+ const testDocs = {
1396
+ a : { foo : 1 } ,
1397
+ b : { bar : 2 }
1398
+ } ;
1399
+ await withTestCollection ( persistence , testDocs , async ( coll , db ) => {
1400
+ const querySnap = await getDocs ( query ( coll , orderBy ( documentId ( ) ) ) ) ;
1401
+ const deferred = new Deferred ( ) ;
1402
+ const json = querySnap . toJSON ( ) ;
1403
+ json . bundle = 'BadData' ;
1404
+ const unsubscribe = onSnapshot (
1405
+ db ,
1406
+ json ,
1407
+ qs => {
1408
+ expect ( qs ) . to . not . exist ;
1409
+ deferred . resolve ( ) ;
1410
+ } ,
1411
+ err => {
1412
+ expect ( err . name ) . to . exist ;
1413
+ expect ( err . message ) . to . exist ;
1414
+ deferred . resolve ( ) ;
1415
+ }
1416
+ ) ;
1417
+ await deferred . promise ;
1418
+ unsubscribe ( ) ;
1419
+ } ) ;
1420
+ } ) ;
1421
+
1422
+ it ( 'QuerySnapshot observer error events for snapshot created by a bundle' , async ( ) => {
1423
+ const testDocs = {
1424
+ a : { foo : 1 } ,
1425
+ b : { bar : 2 }
1426
+ } ;
1427
+ await withTestCollection ( persistence , testDocs , async ( coll , db ) => {
1428
+ const querySnap = await getDocs ( query ( coll , orderBy ( documentId ( ) ) ) ) ;
1429
+ const deferred = new Deferred ( ) ;
1430
+ const json = querySnap . toJSON ( ) ;
1431
+ json . bundle = 'BadData' ;
1432
+ const unsubscribe = onSnapshot ( db , json , {
1433
+ next : qs => {
1434
+ expect ( qs ) . to . not . exist ;
1435
+ deferred . resolve ( ) ;
1436
+ } ,
1437
+ error : err => {
1438
+ expect ( err . name ) . to . exist ;
1439
+ expect ( err . message ) . to . exist ;
1440
+ deferred . resolve ( ) ;
1441
+ }
1442
+ } ) ;
1443
+ await deferred . promise ;
1444
+ unsubscribe ( ) ;
1445
+ } ) ;
1297
1446
} ) ;
1298
1447
1299
1448
it ( 'QuerySnapshot updated doc events in snapshot created by a bundle' , async ( ) => {
@@ -1302,39 +1451,32 @@ apiDescribe('Database', persistence => {
1302
1451
b : { bar : 2 }
1303
1452
} ;
1304
1453
await withTestCollection ( persistence , testDocs , async ( coll , db ) => {
1305
- const q = query ( coll , orderBy ( documentId ( ) ) ) ;
1306
- const querySnap = await getDocs ( q ) ;
1454
+ const querySnap = await getDocs ( query ( coll , orderBy ( documentId ( ) ) ) ) ;
1307
1455
const refForDocA = querySnap . docs [ 0 ] . ref ;
1308
- const json = querySnap . toJSON ( ) ;
1309
1456
const accumulator = new EventsAccumulator < QuerySnapshot > ( ) ;
1310
1457
const unsubscribe = onSnapshot (
1311
1458
db ,
1312
- json ,
1459
+ querySnap . toJSON ( ) ,
1313
1460
accumulator . storeEvent
1314
1461
) ;
1315
1462
await accumulator
1316
1463
. awaitEvent ( )
1317
1464
. then ( snap => {
1318
- const docs = snap . docs ;
1319
- console . error ( "DEDB: docs: " , docs ) ;
1320
- expect ( docs ) . not . to . be . null ;
1321
- expect ( docs . length ) . to . equal ( 2 ) ;
1322
- expect ( docs [ 0 ] . data ( ) ) . to . deep . equal ( testDocs . a ) ;
1323
- expect ( docs [ 1 ] . data ( ) ) . to . deep . equal ( testDocs . b ) ;
1465
+ expect ( snap . docs ) . not . to . be . null ;
1466
+ expect ( snap . docs . length ) . to . equal ( 2 ) ;
1467
+ expect ( snap . docs [ 0 ] . data ( ) ) . to . deep . equal ( testDocs . a ) ;
1468
+ expect ( snap . docs [ 1 ] . data ( ) ) . to . deep . equal ( testDocs . b ) ;
1324
1469
} )
1325
- . then ( ( ) => setDoc ( refForDocA , { foo : 0 } ) )
1470
+ . then ( ( ) => setDoc ( refForDocA , { foo : 0 } ) )
1326
1471
. then ( ( ) => accumulator . awaitEvent ( ) )
1327
1472
. then ( snap => {
1328
- const docs = snap . docs ;
1329
- console . error ( "DEDB: docs: " , docs ) ;
1330
- expect ( docs ) . not . to . be . null ;
1331
- expect ( docs . length ) . to . equal ( 2 ) ;
1332
- expect ( docs [ 0 ] . data ( ) ) . to . deep . equal ( { foo : 0 } ) ;
1333
- expect ( docs [ 1 ] . data ( ) ) . to . deep . equal ( testDocs . b ) ;
1473
+ expect ( snap . docs ) . not . to . be . null ;
1474
+ expect ( snap . docs . length ) . to . equal ( 2 ) ;
1475
+ expect ( snap . docs [ 0 ] . data ( ) ) . to . deep . equal ( { foo : 0 } ) ;
1476
+ expect ( snap . docs [ 1 ] . data ( ) ) . to . deep . equal ( testDocs . b ) ;
1334
1477
} ) ;
1335
1478
unsubscribe ( ) ;
1336
- }
1337
- ) ;
1479
+ } ) ;
1338
1480
} ) ;
1339
1481
1340
1482
it ( 'Metadata only changes are not fired when no options provided' , ( ) => {
@@ -1374,7 +1516,7 @@ apiDescribe('Database', persistence => {
1374
1516
const queryForRejection = collection ( db , 'a/__badpath__/b' ) ;
1375
1517
onSnapshot (
1376
1518
queryForRejection ,
1377
- ( ) => { } ,
1519
+ ( ) => { } ,
1378
1520
( err : Error ) => {
1379
1521
expect ( err . name ) . to . exist ;
1380
1522
expect ( err . message ) . to . exist ;
@@ -1391,13 +1533,13 @@ apiDescribe('Database', persistence => {
1391
1533
const queryForRejection = collection ( db , 'a/__badpath__/b' ) ;
1392
1534
onSnapshot (
1393
1535
queryForRejection ,
1394
- ( ) => { } ,
1536
+ ( ) => { } ,
1395
1537
( err : Error ) => {
1396
1538
expect ( err . name ) . to . exist ;
1397
1539
expect ( err . message ) . to . exist ;
1398
1540
onSnapshot (
1399
1541
queryForRejection ,
1400
- ( ) => { } ,
1542
+ ( ) => { } ,
1401
1543
( err2 : Error ) => {
1402
1544
expect ( err2 . name ) . to . exist ;
1403
1545
expect ( err2 . message ) . to . exist ;
@@ -1812,7 +1954,7 @@ apiDescribe('Database', persistence => {
1812
1954
it ( 'can query after firestore restart' , async ( ) => {
1813
1955
return withTestDoc ( persistence , async ( docRef , firestore ) => {
1814
1956
const deferred : Deferred < FirestoreError > = new Deferred ( ) ;
1815
- const unsubscribe = onSnapshot ( docRef , snapshot => { } , deferred . resolve ) ;
1957
+ const unsubscribe = onSnapshot ( docRef , snapshot => { } , deferred . resolve ) ;
1816
1958
1817
1959
await firestore . _restart ( ) ;
1818
1960
@@ -1832,7 +1974,7 @@ apiDescribe('Database', persistence => {
1832
1974
it ( 'query listener throws error on termination' , async ( ) => {
1833
1975
return withTestDoc ( persistence , async ( docRef , firestore ) => {
1834
1976
const deferred : Deferred < FirestoreError > = new Deferred ( ) ;
1835
- const unsubscribe = onSnapshot ( docRef , snapshot => { } , deferred . resolve ) ;
1977
+ const unsubscribe = onSnapshot ( docRef , snapshot => { } , deferred . resolve ) ;
1836
1978
1837
1979
await terminate ( firestore ) ;
1838
1980
@@ -1879,7 +2021,7 @@ apiDescribe('Database', persistence => {
1879
2021
readonly title : string ,
1880
2022
readonly author : string ,
1881
2023
readonly ref : DocumentReference | null = null
1882
- ) { }
2024
+ ) { }
1883
2025
byline ( ) : string {
1884
2026
return this . title + ', by ' + this . author ;
1885
2027
}
@@ -2009,8 +2151,8 @@ apiDescribe('Database', persistence => {
2009
2151
batch . set ( ref , { title : 'olive' } , { merge : true } )
2010
2152
) . to . throw (
2011
2153
'Function WriteBatch.set() called with invalid ' +
2012
- 'data (via `toFirestore()`). Unsupported field value: undefined ' +
2013
- '(found in field author in document posts/some-post)'
2154
+ 'data (via `toFirestore()`). Unsupported field value: undefined ' +
2155
+ '(found in field author in document posts/some-post)'
2014
2156
) ;
2015
2157
} ) ;
2016
2158
} ) ;
0 commit comments