|
16 | 16 |
|
17 | 17 | #import "Firestore/Example/Tests/Util/FSTHelpers.h"
|
18 | 18 |
|
| 19 | +#import <FirebaseFirestore/FIRFieldValue.h> |
19 | 20 | #import <FirebaseFirestore/FIRGeoPoint.h>
|
20 | 21 |
|
21 | 22 | #include <set>
|
22 |
| -#include <utility> |
23 | 23 |
|
24 | 24 | #import "Firestore/Source/API/FSTUserDataConverter.h"
|
25 | 25 |
|
|
29 | 29 | #include "Firestore/core/src/model/resource_path.h"
|
30 | 30 | #include "Firestore/core/src/model/set_mutation.h"
|
31 | 31 |
|
| 32 | +#import <Firestore/core/test/unit/testutil/testutil.h> |
| 33 | + |
| 34 | +namespace testutil = firebase::firestore::testutil; |
32 | 35 | namespace util = firebase::firestore::util;
|
33 | 36 |
|
34 | 37 | using firebase::firestore::core::ParsedSetData;
|
@@ -131,26 +134,22 @@ SetMutation FSTTestSetMutation(NSString *path, NSDictionary<NSString *, id> *val
|
131 | 134 | PatchMutation FSTTestPatchMutation(NSString *path,
|
132 | 135 | NSDictionary<NSString *, id> *values,
|
133 | 136 | 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 | + }]; |
135 | 145 |
|
136 | 146 | 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]; |
149 | 148 |
|
150 | 149 | DocumentKey key = FSTTestDocKey(path);
|
| 150 | + |
| 151 | + BOOL merge = !updateMask.empty(); |
151 | 152 | Precondition precondition = merge ? Precondition::None() : Precondition::Exists(true);
|
152 |
| - // FieldMask mask(merge ? std::set<FieldPath>(updateMask.begin(), updateMask.end()) |
153 |
| - // : fieldMaskPaths); |
154 | 153 | return PatchMutation(key, parsed.data(), parsed.fieldMask(), precondition,
|
155 | 154 | parsed.field_transforms());
|
156 | 155 | }
|
|
0 commit comments