@@ -563,5 +563,49 @@ describe('getAggregateFromServer()', function () {
563
563
data . averageBaz . should . eql ( - 0.19999999999999998 ) ;
564
564
} ) ;
565
565
} ) ;
566
+
567
+ describe ( 'collectionGroup()' , function ( ) {
568
+ it ( 'test count, sum, average with collectionGroup' , async function ( ) {
569
+ const {
570
+ getAggregateFromServer,
571
+ doc,
572
+ setDoc,
573
+ collection,
574
+ getFirestore,
575
+ count,
576
+ average,
577
+ collectionGroup,
578
+ sum,
579
+ FieldPath,
580
+ } = firestoreModular ;
581
+ const firestore = getFirestore ( ) ;
582
+
583
+ const colRef = collection ( firestore , 'collectionGroup' ) ;
584
+
585
+ await Promise . all ( [
586
+ setDoc ( doc ( colRef , 'one' ) , { docId : '123' , status : 'paid' , amount : 100 } ) ,
587
+ setDoc ( doc ( colRef , 'two' ) , { docId : '123' , status : 'paid' , amount : 200 } ) ,
588
+ setDoc ( doc ( colRef , 'three' ) , { docId : '123' , status : 'unpaid' , amount : 400 } ) ,
589
+ ] ) ;
590
+
591
+ const query = collectionGroup ( firestore , 'collectionGroup' )
592
+ . where ( 'docId' , '==' , '123' )
593
+ . where ( 'status' , '==' , 'paid' ) ;
594
+
595
+ const aggregateSpec = {
596
+ countCollection : count ( ) ,
597
+ averageAmount : average ( new FieldPath ( 'amount' ) ) ,
598
+ sumAmount : sum ( new FieldPath ( 'amount' ) ) ,
599
+ } ;
600
+
601
+ const result = await getAggregateFromServer ( query , aggregateSpec ) ;
602
+
603
+ const data = result . data ( ) ;
604
+
605
+ data . countCollection . should . eql ( 2 ) ;
606
+ data . averageAmount . should . eql ( 150 ) ;
607
+ data . sumAmount . should . eql ( 300 ) ;
608
+ } ) ;
609
+ } ) ;
566
610
} ) ;
567
611
} ) ;
0 commit comments