Skip to content

Validate QueryPurpose in spec test #10954

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
merged 4 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,13 @@ - (void)validateExpectedState:(nullable NSDictionary *)expectedState {
std::vector<TargetData> queries;
for (id queryJson in queriesJson) {
Query query = [self parseQuery:queryJson];
// TODO(mcg): populate the purpose of the target once it's possible to encode that in
// the spec tests. For now, hard-code that it's a listen despite the fact that it's
// not always the right value.
TargetData target_data(query.ToTarget(), targetID, 0, QueryPurpose::Listen);

QueryPurpose purpose = QueryPurpose::Listen;
if ([queryData objectForKey:@"targetPurpose"] != nil) {
purpose = static_cast<QueryPurpose>([queryData[@"targetPurpose"] intValue]);
}

TargetData target_data(query.ToTarget(), targetID, 0, purpose);
if ([queryData objectForKey:@"resumeToken"] != nil) {
target_data = target_data.WithResumeToken(
MakeResumeToken(queryData[@"resumeToken"]), SnapshotVersion::None());
Expand Down Expand Up @@ -887,11 +890,13 @@ - (void)validateActiveTargets {
XCTAssertNotEqual(found, actualTargets.end(), @"Expected active target not found: %s",
targetData.ToString().c_str());

// TODO(mcg): validate the purpose of the target once it's possible to encode that in the
// spec tests. For now, only validate properties that can be validated.
// TODO(Mila): Replace the XCTAssertEqual() checks on the individual properties of TargetData
// below with the single assertEquals on the TargetData objects themselves if the sequenceNumber
// is ever made to be consistent.
// XCTAssertEqualObjects(actualTargets[targetID], TargetData);

const TargetData &actual = found->second;

XCTAssertEqual(actual.purpose(), targetData.purpose());
XCTAssertEqual(actual.target(), targetData.target());
XCTAssertEqual(actual.target_id(), targetData.target_id());
XCTAssertEqual(actual.snapshot_version(), targetData.snapshot_version());
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Example/Tests/SpecTests/json/bundle_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,8 @@
"path": "collection/a"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,24 @@
"path": "collection"
}
}
]
],
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": "",
"targetPurpose": 1
}
}
}
},
{
"restart": true,
Expand Down Expand Up @@ -414,7 +431,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -910,7 +928,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -976,7 +995,8 @@
"path": "collection/2"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand All @@ -988,7 +1008,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1043,7 +1064,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1475,7 +1497,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1541,7 +1564,8 @@
"path": "collection/2"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand All @@ -1553,7 +1577,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1618,7 +1643,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1822,7 +1848,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1888,7 +1915,8 @@
"path": "collection/2"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand All @@ -1900,7 +1928,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1965,7 +1994,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -2219,7 +2249,24 @@
"path": "collection"
}
}
]
],
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": "",
"targetPurpose": 1
}
}
}
}
]
}
Expand Down
Loading