Skip to content

Commit 5dcaafd

Browse files
author
Brian Chen
committed
WIP: all tests passing, needs backward localserializer compat
1 parent e624789 commit 5dcaafd

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

Firestore/Example/Tests/Util/FSTHelpers.mm

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
1818

19+
#import <FirebaseFirestore/FIRFieldValue.h>
1920
#import <FirebaseFirestore/FIRGeoPoint.h>
2021

2122
#include <set>
22-
#include <utility>
2323

2424
#import "Firestore/Source/API/FSTUserDataConverter.h"
2525

@@ -29,6 +29,9 @@
2929
#include "Firestore/core/src/model/resource_path.h"
3030
#include "Firestore/core/src/model/set_mutation.h"
3131

32+
#import <Firestore/core/test/unit/testutil/testutil.h>
33+
34+
namespace testutil = firebase::firestore::testutil;
3235
namespace util = firebase::firestore::util;
3336

3437
using firebase::firestore::core::ParsedSetData;
@@ -131,26 +134,22 @@ SetMutation FSTTestSetMutation(NSString *path, NSDictionary<NSString *, id> *val
131134
PatchMutation FSTTestPatchMutation(NSString *path,
132135
NSDictionary<NSString *, id> *values,
133136
const std::vector<FieldPath> &updateMask) {
134-
BOOL merge = !updateMask.empty();
137+
// Replace '<DELETE>' sentinel from JSON.
138+
NSMutableDictionary *mutableValues = [values mutableCopy];
139+
[mutableValues enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *) {
140+
if ([value isEqual:kDeleteSentinel]) {
141+
const FieldPath fieldPath = testutil::Field(util::MakeString(key));
142+
mutableValues[key] = [FIRFieldValue fieldValueForDelete];
143+
}
144+
}];
135145

136146
FSTUserDataConverter *converter = FSTTestUserDataConverter();
137-
ParsedUpdateData parsed = [converter parsedUpdateData:values];
138-
139-
// __block ObjectValue objectValue = ObjectValue::Empty();
140-
// __block std::set<FieldPath> fieldMaskPaths;
141-
// [values enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *) {
142-
// const FieldPath path = testutil::Field(key);
143-
// fieldMaskPaths.insert(path);
144-
// if (![value isEqual:kDeleteSentinel]) {
145-
// FieldValue parsedValue = FSTTestFieldValue(value);
146-
// objectValue = objectValue.Set(path, std::move(parsedValue));
147-
// }
148-
// }];
147+
ParsedUpdateData parsed = [converter parsedUpdateData:mutableValues];
149148

150149
DocumentKey key = FSTTestDocKey(path);
150+
151+
BOOL merge = !updateMask.empty();
151152
Precondition precondition = merge ? Precondition::None() : Precondition::Exists(true);
152-
// FieldMask mask(merge ? std::set<FieldPath>(updateMask.begin(), updateMask.end())
153-
// : fieldMaskPaths);
154153
return PatchMutation(key, parsed.data(), parsed.fieldMask(), precondition,
155154
parsed.field_transforms());
156155
}

Firestore/core/test/unit/testutil/testutil.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ model::PatchMutation PatchMutationHelper(
370370
const FieldValue& value = kv.second;
371371
if (!value.is_string() || value.string_value() != kDeleteSentinel) {
372372
object_value = object_value.Set(field_path, value);
373+
} else if (value.string_value() == kDeleteSentinel) {
374+
object_value =
375+
object_value.Set(field_path, object_value.Delete(field_path));
373376
}
374377
}
375378

0 commit comments

Comments
 (0)