Skip to content

Add expected count to Target #10872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
5 changes: 5 additions & 0 deletions Firestore/Example/Tests/SpecTests/FSTMockDatastore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ void WatchQuery(const TargetData& query) override {
// Snapshot version is ignored on the wire
TargetData sentTargetData =
query.WithResumeToken(query.resume_token(), SnapshotVersion::None());

if (query.expected_count().has_value()) {
sentTargetData = sentTargetData.WithExpectedCount(query.expected_count().value());
}

datastore_->IncrementWatchStreamRequests();
active_targets_[query.target_id()] = sentTargetData;
}
Expand Down
10 changes: 9 additions & 1 deletion Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ - (void)validateExpectedState:(nullable NSDictionary *)expectedState {
target_data = target_data.WithResumeToken(
ByteString(), [self parseVersion:queryData[@"readTime"]]);
}

if ([queryData objectForKey:@"expectedCount"] != nil) {
target_data = target_data.WithExpectedCount([queryData[@"expectedCount"] intValue]);
}
queries.push_back(std::move(target_data));
}
expectedActiveTargets[targetID] = std::move(queries);
Expand Down Expand Up @@ -896,7 +900,11 @@ - (void)validateActiveTargets {
XCTAssertEqual(actual.target_id(), targetData.target_id());
XCTAssertEqual(actual.snapshot_version(), targetData.snapshot_version());
XCTAssertEqual(actual.resume_token(), targetData.resume_token());

if (targetData.expected_count().has_value()) {
HARD_ASSERT(actual.expected_count().has_value(),
"Actual Target data doesn't have expected count.");
XCTAssertEqual(actual.expected_count().value(), targetData.expected_count().value());
}
actualTargets.erase(targetID);
}

Expand Down
Loading