@@ -1385,156 +1385,4 @@ apiDescribe('Aggregation queries - sum / average', persistence => {
1385
1385
expect ( snapshot . data ( ) . countOfDocs ) . to . equal ( 4 ) ;
1386
1386
} ) ;
1387
1387
} ) ;
1388
-
1389
- // Only run tests that require indexes against the emulator, because we don't
1390
- // have a way to dynamically create the indexes when running the tests.
1391
- ( USE_EMULATOR ? apiDescribe : apiDescribe . skip ) (
1392
- 'queries requiring indexes' ,
1393
- ( ) => {
1394
- it ( 'aggregate query supports collection groups - multi-aggregate' , ( ) => {
1395
- return withTestDb ( persistence , async db => {
1396
- const collectionGroupId = doc (
1397
- collection ( db , 'aggregateQueryTest' )
1398
- ) . id ;
1399
- const docPaths = [
1400
- `${ collectionGroupId } /cg-doc1` ,
1401
- `abc/123/${ collectionGroupId } /cg-doc2` ,
1402
- `zzz${ collectionGroupId } /cg-doc3` ,
1403
- `abc/123/zzz${ collectionGroupId } /cg-doc4` ,
1404
- `abc/123/zzz/${ collectionGroupId } `
1405
- ] ;
1406
- const batch = writeBatch ( db ) ;
1407
- for ( const docPath of docPaths ) {
1408
- batch . set ( doc ( db , docPath ) , { x : 2 } ) ;
1409
- }
1410
- await batch . commit ( ) ;
1411
- const snapshot = await getAggregateFromServer (
1412
- collectionGroup ( db , collectionGroupId ) ,
1413
- {
1414
- count : count ( ) ,
1415
- sum : sum ( 'x' ) ,
1416
- avg : average ( 'x' )
1417
- }
1418
- ) ;
1419
- expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
1420
- expect ( snapshot . data ( ) . sum ) . to . equal ( 4 ) ;
1421
- expect ( snapshot . data ( ) . avg ) . to . equal ( 2 ) ;
1422
- } ) ;
1423
- } ) ;
1424
-
1425
- it ( 'performs aggregations on documents with all aggregated fields using getAggregationFromServer' , ( ) => {
1426
- const testDocs = {
1427
- a : { author : 'authorA' , title : 'titleA' , pages : 100 , year : 1980 } ,
1428
- b : { author : 'authorB' , title : 'titleB' , pages : 50 , year : 2020 } ,
1429
- c : { author : 'authorC' , title : 'titleC' , pages : 150 , year : 2021 } ,
1430
- d : { author : 'authorD' , title : 'titleD' , pages : 50 }
1431
- } ;
1432
- return withTestCollection ( persistence , testDocs , async coll => {
1433
- const snapshot = await getAggregateFromServer ( coll , {
1434
- totalPages : sum ( 'pages' ) ,
1435
- averagePages : average ( 'pages' ) ,
1436
- averageYear : average ( 'year' ) ,
1437
- count : count ( )
1438
- } ) ;
1439
- expect ( snapshot . data ( ) . totalPages ) . to . equal ( 300 ) ;
1440
- expect ( snapshot . data ( ) . averagePages ) . to . equal ( 100 ) ;
1441
- expect ( snapshot . data ( ) . averageYear ) . to . equal ( 2007 ) ;
1442
- expect ( snapshot . data ( ) . count ) . to . equal ( 3 ) ;
1443
- } ) ;
1444
- } ) ;
1445
-
1446
- it ( 'performs aggregates on multiple fields where one aggregate could cause short-circuit due to NaN using getAggregationFromServer' , ( ) => {
1447
- const testDocs = {
1448
- a : {
1449
- author : 'authorA' ,
1450
- title : 'titleA' ,
1451
- pages : 100 ,
1452
- year : 1980 ,
1453
- rating : 5
1454
- } ,
1455
- b : {
1456
- author : 'authorB' ,
1457
- title : 'titleB' ,
1458
- pages : 50 ,
1459
- year : 2020 ,
1460
- rating : 4
1461
- } ,
1462
- c : {
1463
- author : 'authorC' ,
1464
- title : 'titleC' ,
1465
- pages : 100 ,
1466
- year : 1980 ,
1467
- rating : Number . NaN
1468
- } ,
1469
- d : {
1470
- author : 'authorD' ,
1471
- title : 'titleD' ,
1472
- pages : 50 ,
1473
- year : 2020 ,
1474
- rating : 0
1475
- }
1476
- } ;
1477
- return withTestCollection ( persistence , testDocs , async coll => {
1478
- const snapshot = await getAggregateFromServer ( coll , {
1479
- totalRating : sum ( 'rating' ) ,
1480
- totalPages : sum ( 'pages' ) ,
1481
- averageYear : average ( 'year' )
1482
- } ) ;
1483
- expect ( snapshot . data ( ) . totalRating ) . to . be . NaN ;
1484
- expect ( snapshot . data ( ) . totalPages ) . to . equal ( 300 ) ;
1485
- expect ( snapshot . data ( ) . averageYear ) . to . equal ( 2000 ) ;
1486
- } ) ;
1487
- } ) ;
1488
-
1489
- it ( 'performs aggregates when using `array-contains-any` operator getAggregationFromServer' , ( ) => {
1490
- const testDocs = {
1491
- a : {
1492
- author : 'authorA' ,
1493
- title : 'titleA' ,
1494
- pages : 100 ,
1495
- year : 1980 ,
1496
- rating : [ 5 , 1000 ]
1497
- } ,
1498
- b : {
1499
- author : 'authorB' ,
1500
- title : 'titleB' ,
1501
- pages : 50 ,
1502
- year : 2020 ,
1503
- rating : [ 4 ]
1504
- } ,
1505
- c : {
1506
- author : 'authorC' ,
1507
- title : 'titleC' ,
1508
- pages : 100 ,
1509
- year : 1980 ,
1510
- rating : [ 2222 , 3 ]
1511
- } ,
1512
- d : {
1513
- author : 'authorD' ,
1514
- title : 'titleD' ,
1515
- pages : 50 ,
1516
- year : 2020 ,
1517
- rating : [ 0 ]
1518
- }
1519
- } ;
1520
- return withTestCollection ( persistence , testDocs , async coll => {
1521
- const snapshot = await getAggregateFromServer (
1522
- query ( coll , where ( 'rating' , 'array-contains-any' , [ 5 , 3 ] ) ) ,
1523
- {
1524
- totalRating : sum ( 'rating' ) ,
1525
- averageRating : average ( 'rating' ) ,
1526
- totalPages : sum ( 'pages' ) ,
1527
- averagePages : average ( 'pages' ) ,
1528
- countOfDocs : count ( )
1529
- }
1530
- ) ;
1531
- expect ( snapshot . data ( ) . totalRating ) . to . equal ( 0 ) ;
1532
- expect ( snapshot . data ( ) . averageRating ) . to . be . null ;
1533
- expect ( snapshot . data ( ) . totalPages ) . to . equal ( 200 ) ;
1534
- expect ( snapshot . data ( ) . averagePages ) . to . equal ( 100 ) ;
1535
- expect ( snapshot . data ( ) . countOfDocs ) . to . equal ( 2 ) ;
1536
- } ) ;
1537
- } ) ;
1538
- }
1539
- ) ;
1540
1388
} ) ;
0 commit comments