Skip to content

Commit 73a3b71

Browse files
author
jude.kwashie
committed
add e2e test
1 parent efa81ca commit 73a3b71

File tree

3 files changed

+235
-189
lines changed

3 files changed

+235
-189
lines changed

packages/firestore/e2e/Aggregate/AggregateQuery.e2e.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

packages/firestore/ios/RNFBFirestore/RNFBFirestoreCollectionModule.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ - (void)invalidate {
229229
: (RCTPromiseRejectBlock)reject) {
230230
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
231231
databaseId:databaseId];
232-
232+
233233
FIRQuery *firestoreBaseQuery = [RNFBFirestoreCommon getQueryForFirestore:firestore
234234
path:path type:type];
235235
RNFBFirestoreQuery *firestoreQuery =

0 commit comments

Comments
 (0)