Skip to content

Commit 3a4b71d

Browse files
Held Write Ack Removal Spec Tests (#2018)
1 parent 2266788 commit 3a4b71d

16 files changed

+65408
-36449
lines changed

Firestore/Example/Tests/SpecTests/FSTSpecTests.mm

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,19 @@ - (SnapshotVersion)parseVersion:(NSNumber *_Nullable)version {
174174
return testutil::Version(version.longLongValue);
175175
}
176176

177-
- (FSTDocumentViewChange *)parseChange:(NSArray *)change ofType:(FSTDocumentViewChangeType)type {
178-
BOOL hasMutations = NO;
179-
for (NSUInteger i = 3; i < change.count; ++i) {
180-
if ([change[i] isEqual:@"local"]) {
181-
hasMutations = YES;
182-
}
183-
}
184-
NSNumber *version = change[1];
185-
XCTAssert([change[0] isKindOfClass:[NSString class]]);
186-
FSTDocument *doc =
187-
FSTTestDoc(util::MakeString((NSString *)change[0]), version.longLongValue, change[2],
188-
hasMutations ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced);
177+
- (FSTDocumentViewChange *)parseChange:(NSDictionary *)jsonDoc
178+
ofType:(FSTDocumentViewChangeType)type {
179+
NSNumber *version = jsonDoc[@"version"];
180+
NSDictionary *options = jsonDoc[@"options"];
181+
FSTDocumentState documentState = [options[@"hasLocalMutations"] isEqualToNumber:@YES]
182+
? FSTDocumentStateLocalMutations
183+
: ([options[@"hasCommittedMutations"] isEqualToNumber:@YES]
184+
? FSTDocumentStateCommittedMutations
185+
: FSTDocumentStateSynced);
186+
187+
XCTAssert([jsonDoc[@"key"] isKindOfClass:[NSString class]]);
188+
FSTDocument *doc = FSTTestDoc(util::MakeString((NSString *)jsonDoc[@"key"]),
189+
version.longLongValue, jsonDoc[@"value"], documentState);
189190
return [FSTDocumentViewChange changeWithDocument:doc type:type];
190191
}
191192

@@ -270,11 +271,12 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity {
270271
[self doWatchEntity:watchSpec];
271272
}
272273
} else if (watchEntity[@"doc"]) {
273-
NSArray *docSpec = watchEntity[@"doc"];
274-
FSTDocumentKey *key = FSTTestDocKey(docSpec[0]);
275-
FSTObjectValue *_Nullable value =
276-
[docSpec[2] isKindOfClass:[NSNull class]] ? nil : FSTTestObjectValue(docSpec[2]);
277-
SnapshotVersion version = [self parseVersion:docSpec[1]];
274+
NSDictionary *docSpec = watchEntity[@"doc"];
275+
FSTDocumentKey *key = FSTTestDocKey(docSpec[@"key"]);
276+
FSTObjectValue *_Nullable value = [docSpec[@"value"] isKindOfClass:[NSNull class]]
277+
? nil
278+
: FSTTestObjectValue(docSpec[@"value"]);
279+
SnapshotVersion version = [self parseVersion:docSpec[@"version"]];
278280
FSTMaybeDocument *doc = value ? [FSTDocument documentWithData:value
279281
key:key
280282
version:std::move(version)
@@ -493,22 +495,22 @@ - (void)validateEvent:(FSTQueryEvent *)actual matches:(NSDictionary *)expected {
493495
} else {
494496
NSMutableArray *expectedChanges = [NSMutableArray array];
495497
NSMutableArray *removed = expected[@"removed"];
496-
for (NSArray *changeSpec in removed) {
498+
for (NSDictionary *changeSpec in removed) {
497499
[expectedChanges
498500
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeRemoved]];
499501
}
500502
NSMutableArray *added = expected[@"added"];
501-
for (NSArray *changeSpec in added) {
503+
for (NSDictionary *changeSpec in added) {
502504
[expectedChanges
503505
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeAdded]];
504506
}
505507
NSMutableArray *modified = expected[@"modified"];
506-
for (NSArray *changeSpec in modified) {
508+
for (NSDictionary *changeSpec in modified) {
507509
[expectedChanges
508510
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeModified]];
509511
}
510512
NSMutableArray *metadata = expected[@"metadata"];
511-
for (NSArray *changeSpec in metadata) {
513+
for (NSDictionary *changeSpec in metadata) {
512514
[expectedChanges
513515
addObject:[self parseChange:changeSpec ofType:FSTDocumentViewChangeTypeMetadata]];
514516
}

Firestore/Example/Tests/SpecTests/json/collection_spec_test.json

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@
3838
{
3939
"watchEntity": {
4040
"docs": [
41-
[
42-
"collection/key",
43-
1000,
44-
{
41+
{
42+
"key": "collection/key",
43+
"version": 1000,
44+
"value": {
4545
"foo": "bar"
46+
},
47+
"options": {
48+
"hasLocalMutations": false,
49+
"hasCommittedMutations": false
4650
}
47-
]
51+
}
4852
],
4953
"targets": [
5054
2
@@ -61,7 +65,8 @@
6165
},
6266
{
6367
"watchSnapshot": {
64-
"version": 1001
68+
"version": 1001,
69+
"targetIds": []
6570
},
6671
"expect": [
6772
{
@@ -71,13 +76,17 @@
7176
"orderBys": []
7277
},
7378
"added": [
74-
[
75-
"collection/key",
76-
1000,
77-
{
79+
{
80+
"key": "collection/key",
81+
"version": 1000,
82+
"value": {
7883
"foo": "bar"
84+
},
85+
"options": {
86+
"hasLocalMutations": false,
87+
"hasCommittedMutations": false
7988
}
80-
]
89+
}
8190
],
8291
"errorCode": 0,
8392
"fromCache": false,
@@ -133,14 +142,17 @@
133142
"orderBys": []
134143
},
135144
"added": [
136-
[
137-
"collection/key",
138-
0,
139-
{
145+
{
146+
"key": "collection/key",
147+
"version": 0,
148+
"value": {
140149
"foo": "bar"
141150
},
142-
"local"
143-
]
151+
"options": {
152+
"hasLocalMutations": true,
153+
"hasCommittedMutations": false
154+
}
155+
}
144156
],
145157
"errorCode": 0,
146158
"fromCache": true,

0 commit comments

Comments
 (0)