|
26 | 26 |
|
27 | 27 | #include "Firestore/core/src/model/database_id.h"
|
28 | 28 | #include "Firestore/core/src/model/field_value.h"
|
29 |
| -#include "Firestore/core/src/model/transform_mutation.h" |
| 29 | +#include "Firestore/core/src/model/patch_mutation.h" |
| 30 | +#include "Firestore/core/src/model/set_mutation.h" |
30 | 31 | #include "Firestore/core/src/model/transform_operation.h"
|
31 | 32 | #include "Firestore/core/src/nanopb/nanopb_util.h"
|
32 | 33 | #include "Firestore/core/test/unit/testutil/testutil.h"
|
|
40 | 41 | using firebase::firestore::model::FieldValue;
|
41 | 42 | using firebase::firestore::model::FieldTransform;
|
42 | 43 | using firebase::firestore::model::ObjectValue;
|
43 |
| -using firebase::firestore::model::TransformMutation; |
| 44 | +using firebase::firestore::model::PatchMutation; |
44 | 45 | using firebase::firestore::model::TransformOperation;
|
| 46 | +using firebase::firestore::model::SetMutation; |
45 | 47 | using firebase::firestore::nanopb::MakeNSData;
|
46 | 48 | using firebase::firestore::testutil::Field;
|
47 | 49 |
|
@@ -218,44 +220,66 @@ - (void)testNSDatesAreConvertedToTimestamps {
|
218 | 220 | }
|
219 | 221 |
|
220 | 222 | - (void)testCreatesArrayUnionTransforms {
|
221 |
| - TransformMutation transform = FSTTestTransformMutation(@"collection/key", @{ |
| 223 | + PatchMutation patchMutation = FSTTestPatchMutation(@"collection/key", @{ |
222 | 224 | @"foo" : [FIRFieldValue fieldValueForArrayUnion:@[ @"tag" ]],
|
223 | 225 | @"bar.baz" :
|
224 | 226 | [FIRFieldValue fieldValueForArrayUnion:@[ @YES, @{@"nested" : @{@"a" : @[ @1, @2 ]}} ]]
|
| 227 | + }, |
| 228 | + {}); |
| 229 | + XCTAssertEqual(patchMutation.field_transforms().size(), 2u); |
| 230 | + |
| 231 | + SetMutation setMutation = FSTTestSetMutation(@"collection/key", @{ |
| 232 | + @"foo" : [FIRFieldValue fieldValueForArrayUnion:@[ @"tag" ]], |
| 233 | + @"bar" : [FIRFieldValue fieldValueForArrayUnion:@[ @YES, @{@"nested" : @{@"a" : @[ @1, @2 ]}} ]] |
225 | 234 | });
|
226 |
| - XCTAssertEqual(transform.field_transforms().size(), 2u); |
| 235 | + XCTAssertEqual(setMutation.field_transforms().size(), 2u); |
227 | 236 |
|
228 |
| - const FieldTransform &first = transform.field_transforms()[0]; |
229 |
| - XCTAssertEqual(first.path(), FieldPath({"foo"})); |
| 237 | + const FieldTransform &patchFirst = patchMutation.field_transforms()[0]; |
| 238 | + XCTAssertEqual(patchFirst.path(), FieldPath({"foo"})); |
| 239 | + const FieldTransform &setFirst = setMutation.field_transforms()[0]; |
| 240 | + XCTAssertEqual(setFirst.path(), FieldPath({"foo"})); |
230 | 241 | {
|
231 | 242 | std::vector<FieldValue> expectedElements{FSTTestFieldValue(@"tag")};
|
232 | 243 | ArrayTransform expected(TransformOperation::Type::ArrayUnion, expectedElements);
|
233 |
| - XCTAssertEqual(static_cast<const ArrayTransform &>(first.transformation()), expected); |
| 244 | + XCTAssertEqual(static_cast<const ArrayTransform &>(patchFirst.transformation()), expected); |
| 245 | + XCTAssertEqual(static_cast<const ArrayTransform &>(setFirst.transformation()), expected); |
234 | 246 | }
|
235 | 247 |
|
236 |
| - const FieldTransform &second = transform.field_transforms()[1]; |
237 |
| - XCTAssertEqual(second.path(), FieldPath({"bar", "baz"})); |
| 248 | + const FieldTransform &patchSecond = patchMutation.field_transforms()[1]; |
| 249 | + XCTAssertEqual(patchSecond.path(), FieldPath({"bar", "baz"})); |
| 250 | + const FieldTransform &setSecond = setMutation.field_transforms()[1]; |
| 251 | + XCTAssertEqual(setSecond.path(), FieldPath({"bar"})); |
238 | 252 | {
|
239 | 253 | std::vector<FieldValue> expectedElements {
|
240 | 254 | FSTTestFieldValue(@YES), FSTTestFieldValue(@{@"nested" : @{@"a" : @[ @1, @2 ]}})
|
241 | 255 | };
|
242 | 256 | ArrayTransform expected(TransformOperation::Type::ArrayUnion, expectedElements);
|
243 |
| - XCTAssertEqual(static_cast<const ArrayTransform &>(second.transformation()), expected); |
| 257 | + XCTAssertEqual(static_cast<const ArrayTransform &>(patchSecond.transformation()), expected); |
| 258 | + XCTAssertEqual(static_cast<const ArrayTransform &>(setSecond.transformation()), expected); |
244 | 259 | }
|
245 | 260 | }
|
246 | 261 |
|
247 | 262 | - (void)testCreatesArrayRemoveTransforms {
|
248 |
| - TransformMutation transform = FSTTestTransformMutation(@"collection/key", @{ |
| 263 | + PatchMutation patchMutation = FSTTestPatchMutation(@"collection/key", @{ |
| 264 | + @"foo" : [FIRFieldValue fieldValueForArrayRemove:@[ @"tag" ]], |
| 265 | + }, |
| 266 | + {}); |
| 267 | + XCTAssertEqual(patchMutation.field_transforms().size(), 1u); |
| 268 | + |
| 269 | + SetMutation setMutation = FSTTestSetMutation(@"collection/key", @{ |
249 | 270 | @"foo" : [FIRFieldValue fieldValueForArrayRemove:@[ @"tag" ]],
|
250 | 271 | });
|
251 |
| - XCTAssertEqual(transform.field_transforms().size(), 1u); |
| 272 | + XCTAssertEqual(patchMutation.field_transforms().size(), 1u); |
252 | 273 |
|
253 |
| - const FieldTransform &first = transform.field_transforms()[0]; |
254 |
| - XCTAssertEqual(first.path(), FieldPath({"foo"})); |
| 274 | + const FieldTransform &patchFirst = patchMutation.field_transforms()[0]; |
| 275 | + XCTAssertEqual(patchFirst.path(), FieldPath({"foo"})); |
| 276 | + const FieldTransform &setFirst = setMutation.field_transforms()[0]; |
| 277 | + XCTAssertEqual(setFirst.path(), FieldPath({"foo"})); |
255 | 278 | {
|
256 | 279 | std::vector<FieldValue> expectedElements{FSTTestFieldValue(@"tag")};
|
257 | 280 | const ArrayTransform expected(TransformOperation::Type::ArrayRemove, expectedElements);
|
258 |
| - XCTAssertEqual(static_cast<const ArrayTransform &>(first.transformation()), expected); |
| 281 | + XCTAssertEqual(static_cast<const ArrayTransform &>(patchFirst.transformation()), expected); |
| 282 | + XCTAssertEqual(static_cast<const ArrayTransform &>(setFirst.transformation()), expected); |
259 | 283 | }
|
260 | 284 | }
|
261 | 285 |
|
|
0 commit comments