Skip to content

Held Write Ack Removal Spec Tests#2018

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 1 commit into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,18 +174,19 @@ - (SnapshotVersion)parseVersion:(NSNumber *_Nullable)version {
return testutil::Version(version.longLongValue);
}

- (FSTDocumentViewChange *)parseChange:(NSArray *)change ofType:(FSTDocumentViewChangeType)type {
BOOL hasMutations = NO;
for (NSUInteger i = 3; i < change.count; ++i) {
if ([change[i] isEqual:@"local"]) {
hasMutations = YES;
}
}
NSNumber *version = change[1];
XCTAssert([change[0] isKindOfClass:[NSString class]]);
FSTDocument *doc =
FSTTestDoc(util::MakeString((NSString *)change[0]), version.longLongValue, change[2],
hasMutations ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced);
- (FSTDocumentViewChange *)parseChange:(NSDictionary *)jsonDoc
ofType:(FSTDocumentViewChangeType)type {
NSNumber *version = jsonDoc[@"version"];
NSDictionary *options = jsonDoc[@"options"];
FSTDocumentState documentState = [options[@"hasLocalMutations"] isEqualToNumber:@YES]
? FSTDocumentStateLocalMutations
: ([options[@"hasCommittedMutations"] isEqualToNumber:@YES]
? FSTDocumentStateCommittedMutations
: FSTDocumentStateSynced);

XCTAssert([jsonDoc[@"key"] isKindOfClass:[NSString class]]);
FSTDocument *doc = FSTTestDoc(util::MakeString((NSString *)jsonDoc[@"key"]),
version.longLongValue, jsonDoc[@"value"], documentState);
return [FSTDocumentViewChange changeWithDocument:doc type:type];
}

Expand DownExpand Up@@ -270,11 +271,12 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity {
[self doWatchEntity:watchSpec];
}
} else if (watchEntity[@"doc"]) {
NSArray *docSpec = watchEntity[@"doc"];
FSTDocumentKey *key = FSTTestDocKey(docSpec[0]);
FSTObjectValue *_Nullable value =
[docSpec[2] isKindOfClass:[NSNull class]] ? nil : FSTTestObjectValue(docSpec[2]);
SnapshotVersion version = [self parseVersion:docSpec[1]];
NSDictionary *docSpec = watchEntity[@"doc"];
FSTDocumentKey *key = FSTTestDocKey(docSpec[@"key"]);
FSTObjectValue *_Nullable value = [docSpec[@"value"] isKindOfClass:[NSNull class]]
? nil
: FSTTestObjectValue(docSpec[@"value"]);
SnapshotVersion version = [self parseVersion:docSpec[@"version"]];
FSTMaybeDocument *doc = value ? [FSTDocument documentWithData:value
key:key
version:std::move(version)
Expand DownExpand Up@@ -493,22 +495,22 @@ - (void)validateEvent:(FSTQueryEvent *)actual matches:(NSDictionary *)expected {
} else {
NSMutableArray *expectedChanges = [NSMutableArray array];
NSMutableArray *removed = expected[@"removed"];
for (NSArray *changeSpec in removed) {
for (NSDictionary *changeSpec in removed) {
[expectedChanges
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeRemoved]];
}
NSMutableArray *added = expected[@"added"];
for (NSArray *changeSpec in added) {
for (NSDictionary *changeSpec in added) {
[expectedChanges
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeAdded]];
}
NSMutableArray *modified = expected[@"modified"];
for (NSArray *changeSpec in modified) {
for (NSDictionary *changeSpec in modified) {
[expectedChanges
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeModified]];
}
NSMutableArray *metadata = expected[@"metadata"];
for (NSArray *changeSpec in metadata) {
for (NSDictionary *changeSpec in metadata) {
[expectedChanges
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeMetadata]];
}
Expand Down
46 changes: 29 additions & 17 deletions Firestore/Example/Tests/SpecTests/json/collection_spec_test.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,13 +38,17 @@
{
"watchEntity": {
"docs": [
[
"collection/key",
1000,
{
{
"key": "collection/key",
"version": 1000,
"value": {
"foo": "bar"
},
"options": {
"hasLocalMutations": false,
"hasCommittedMutations": false
}
]
}
],
"targets": [
2
Expand All@@ -61,7 +65,8 @@
},
{
"watchSnapshot": {
"version": 1001
"version": 1001,
"targetIds": []
},
"expect": [
{
Expand All@@ -71,13 +76,17 @@
"orderBys": []
},
"added": [
[
"collection/key",
1000,
{
{
"key": "collection/key",
"version": 1000,
"value": {
"foo": "bar"
},
"options": {
"hasLocalMutations": false,
"hasCommittedMutations": false
}
]
}
],
"errorCode": 0,
"fromCache": false,
Expand DownExpand Up@@ -133,14 +142,17 @@
"orderBys": []
},
"added": [
[
"collection/key",
0,
{
{
"key": "collection/key",
"version": 0,
"value": {
"foo": "bar"
},
"local"
]
"options": {
"hasLocalMutations": true,
"hasCommittedMutations": false
}
}
],
"errorCode": 0,
"fromCache": true,
Expand Down
Loading
close