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