Skip to content

Commit

Permalink
feat(GeoFirestore): add method for collectionGroup, fixes #187
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Aug 1, 2020
1 parent a65f5d9 commit 7d34d87
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/GeoFirestore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GeoFirestoreTypes} from 'geofirestore-core';

import {GeoCollectionReference} from './GeoCollectionReference';
import {GeoQuery} from './GeoQuery';
import {GeoWriteBatch} from './GeoWriteBatch';

/**
Expand Down Expand Up @@ -54,6 +55,20 @@ export class GeoFirestore {
);
}

/**
* Creates and returns a new GeoQuery that includes all documents in the
* database that are contained in a collection or subcollection with the
* given collectionId.
*
* @param collectionId Identifies the collections to query over. Every
* collection or subcollection with this ID as the last segment of its path
* will be included. Cannot contain a slash.
* @return The created GeoQuery.
*/
collectionGroup(collectionId: string): GeoQuery {
return new GeoQuery(this._firestore.collectionGroup(collectionId));
}

/**
* Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within
* the transaction has changed, the updateFunction will be retried. If it fails to commit after 5 attempts, the transaction will fail.
Expand Down
14 changes: 10 additions & 4 deletions test/GeoFirestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('GeoFirestore Tests:', () => {

describe('batch():', () => {
it('batch() returns a new GeoWriteBatch based on a Firestore WriteBatch', () => {
expect(new GeoFirestore(firestore).batch()['_writeBatch']).to.deep.equal(
expect(new GeoFirestore(firestore).batch().native).to.deep.equal(
firestore.batch()
);
});
Expand All @@ -55,13 +55,19 @@ describe('GeoFirestore Tests:', () => {
describe('collection():', () => {
it('collection() returns a new GeoCollectionReference based on a Firestore CollectionReference', () => {
expect(
new GeoFirestore(firestore).collection(testCollectionName)[
'_collection'
]
new GeoFirestore(firestore).collection(testCollectionName).native
).to.deep.equal(firestore.collection(testCollectionName));
});
});

describe('collectionGroup():', () => {
it('collectionGroup() returns a new GeoQuery based on a Firestore Query', () => {
expect(
new GeoFirestore(firestore).collectionGroup(testCollectionName).native
).to.deep.equal(firestore.collectionGroup(testCollectionName));
});
});

describe('runTransaction():', () => {
it("runTransaction() doesn't throw an error when a valid `updateFunction` is passed in", () => {
expect(() =>
Expand Down

0 comments on commit 7d34d87

Please sign in to comment.