@@ -28,6 +28,38 @@ @interface FIRCountTests : FSTIntegrationTestCase
2828
2929@implementation FIRCountTests
3030
31+ - (void )testAggregateQueryEquals {
32+ FIRCollectionReference* coll1 = [self collectionRefWithDocuments: @{}];
33+ FIRCollectionReference* coll1Same = [[coll1 firestore ] collectionWithPath: [coll1 path ]];
34+ FIRAggregateQuery* query1 = [coll1 count ];
35+ FIRAggregateQuery* query1Same = [coll1Same count ];
36+
37+ FIRCollectionReference* sub = [[coll1 documentWithPath: @" bar" ] collectionWithPath: @" baz" ];
38+ FIRAggregateQuery* query2 = [[[sub queryWhereField: @" a" isEqualTo: @1 ] queryLimitedTo: 100 ] count ];
39+ FIRAggregateQuery* query2Same = [[[sub queryWhereField: @" a"
40+ isEqualTo: @1 ] queryLimitedTo: 100 ] count ];
41+ FIRAggregateQuery* query3 = [[[sub queryWhereField: @" b"
42+ isEqualTo: @1 ] queryOrderedByField: @" c" ] count ];
43+ FIRAggregateQuery* query3Same = [[[sub queryWhereField: @" b"
44+ isEqualTo: @1 ] queryOrderedByField: @" c" ] count ];
45+
46+ XCTAssertEqualObjects (query1, query1Same);
47+ XCTAssertEqualObjects (query2, query2Same);
48+ XCTAssertEqualObjects (query3, query3Same);
49+
50+ XCTAssertEqual ([query1 hash ], [query1Same hash ]);
51+ XCTAssertEqual ([query2 hash ], [query2Same hash ]);
52+ XCTAssertEqual ([query3 hash ], [query3Same hash ]);
53+
54+ XCTAssertFalse ([query1 isEqual: nil ]);
55+ XCTAssertFalse ([query1 isEqual: @" string" ]);
56+ XCTAssertFalse ([query1 isEqual: query2]);
57+ XCTAssertFalse ([query2 isEqual: query3]);
58+
59+ XCTAssertNotEqual ([query1 hash ], [query2 hash ]);
60+ XCTAssertNotEqual ([query2 hash ], [query3 hash ]);
61+ }
62+
3163- (void )testCanRunCountQuery {
3264 // TODO(b/246758022): Remove this (and below) once COUNT is release for the backend.
3365 if (![FSTIntegrationTestCase isRunningAgainstEmulator ]) {
@@ -77,6 +109,48 @@ - (void)testCanRunCountWithOrderBys {
77109 XCTAssertEqual (snapshot.count , [NSNumber numberWithLong: 3L ]);
78110}
79111
112+ - (void )testSnapshotEquals {
113+ if (![FSTIntegrationTestCase isRunningAgainstEmulator ]) {
114+ return ;
115+ }
116+
117+ FIRCollectionReference* testCollection = [self collectionRefWithDocuments: @{
118+ @" a" : @{@" k" : @" a" },
119+ @" b" : @{@" k" : @" b" },
120+ @" c" : @{@" k" : @" c" }
121+ }];
122+
123+ FIRAggregateQuerySnapshot* snapshot1 =
124+ [self readSnapshotForAggregate: [[testCollection queryWhereField: @" k" isEqualTo: @" b" ] count ]];
125+ FIRAggregateQuerySnapshot* snapshot1Same =
126+ [self readSnapshotForAggregate: [[testCollection queryWhereField: @" k" isEqualTo: @" b" ] count ]];
127+
128+ FIRAggregateQuerySnapshot* snapshot2 =
129+ [self readSnapshotForAggregate: [[testCollection queryWhereField: @" k" isEqualTo: @" a" ] count ]];
130+ [self writeDocumentRef: [testCollection documentWithPath: @" d" ] data: @{@" k" : @" a" }];
131+ FIRAggregateQuerySnapshot* snapshot2Different =
132+ [self readSnapshotForAggregate: [[testCollection queryWhereField: @" k" isEqualTo: @" a" ] count ]];
133+
134+ FIRAggregateQuerySnapshot* snapshot3 =
135+ [self readSnapshotForAggregate: [[testCollection queryWhereField: @" k" isEqualTo: @" b" ] count ]];
136+ FIRAggregateQuerySnapshot* snapshot3Different =
137+ [self readSnapshotForAggregate: [[testCollection queryWhereField: @" k" isEqualTo: @" c" ] count ]];
138+
139+ XCTAssertEqualObjects (snapshot1, snapshot1Same);
140+ XCTAssertEqual ([snapshot1 hash ], [snapshot1Same hash ]);
141+ XCTAssertEqualObjects ([snapshot1 query ], [[testCollection queryWhereField: @" k"
142+ isEqualTo: @" b" ] count ]);
143+
144+ XCTAssertNotEqualObjects (snapshot1, nil );
145+ XCTAssertNotEqualObjects (snapshot1, @" string" );
146+ XCTAssertNotEqualObjects (snapshot1, snapshot2);
147+ XCTAssertNotEqual ([snapshot1 hash ], [snapshot2 hash ]);
148+ XCTAssertNotEqualObjects (snapshot2, snapshot2Different);
149+ XCTAssertNotEqual ([snapshot2 hash ], [snapshot2Different hash ]);
150+ XCTAssertNotEqualObjects (snapshot3, snapshot3Different);
151+ XCTAssertNotEqual ([snapshot3 hash ], [snapshot3Different hash ]);
152+ }
153+
80154- (void )testTerminateDoesNotCrashWithFlyingCountQuery {
81155 if (![FSTIntegrationTestCase isRunningAgainstEmulator ]) {
82156 return ;
0 commit comments