Skip to content
4 changes: 4 additions & 0 deletions packages/cloud_firestore/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [UNPUBLISHED]

- **FIX**: Added `==` operator override to `CollectionReferencePlatform`.

## 0.14.0-dev.1

Along with the below changes, the plugin has undergone a quality of life update to better support exceptions thrown. Any Firestore specific errors now return a `FirebaseException`, allowing you to directly access the code (e.g. `permission-denied`) and message.

**`Firestore`**:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ abstract class CollectionReferencePlatform extends QueryPlatform {
DocumentReferencePlatform doc([String path]) {
throw UnimplementedError("doc() is not implemented");
}

@override
bool operator ==(dynamic o) =>
o is CollectionReferencePlatform &&
o.firestore == firestore &&
o.path == path;

@override
int get hashCode => path.hashCode;

@override
String toString() => '$CollectionReferencePlatform($path)';
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class TestCollectionReference extends CollectionReferencePlatform {
: super(FirebaseFirestorePlatform.instance, '$_kCollectionId');
}

/// Collection reference pointing to the same collection as
/// [TestCollectionReference].
///
/// However, this has a leading `/` for testing path equality.
class ShadowTestCollectionReference extends CollectionReferencePlatform {
ShadowTestCollectionReference._()
: super(FirebaseFirestorePlatform.instance, '/$_kCollectionId');
}

class TestSubcollectionReference extends CollectionReferencePlatform {
TestSubcollectionReference._()
: super(FirebaseFirestorePlatform.instance,
Expand All @@ -42,6 +51,12 @@ void main() {
expect(collection.id, equals(_kCollectionId));
});

test('==', () {
final other = ShadowTestCollectionReference._();
final collection = TestCollectionReference._();
expect(other, equals(collection));
});

test("parent", () {
final collection = TestSubcollectionReference._();
final parent = collection.parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ class TestDocumentReference extends DocumentReferencePlatform {
'$_kCollectionId/$_kDocumentId');
}

/// Collection reference pointing to the same collection as
/// [TestDocumentReference].
///
/// However, this has a leading `/` for testing path equality.
class ShadowTestDocumentReference extends DocumentReferencePlatform {
ShadowTestDocumentReference._()
: super(FirebaseFirestorePlatform.instance,
'/$_kCollectionId/$_kDocumentId');
}

void main() {
initializeMethodChannel();

Expand All @@ -37,6 +47,12 @@ void main() {
expect(document.path, equals("$_kCollectionId/$_kDocumentId"));
});

test('==', () {
final other = ShadowTestDocumentReference._();
final reference = TestDocumentReference._();
expect(other, equals(reference));
});

test("id", () {
final document = TestDocumentReference._();
expect(document.id, equals(_kDocumentId));
Expand Down