FSTMutationTests.mm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/Model/FSTMutation.h"
  17. #import <FirebaseFirestore/FIRFieldValue.h>
  18. #import <FirebaseFirestore/FIRTimestamp.h>
  19. #import <XCTest/XCTest.h>
  20. #include <vector>
  21. #import "Firestore/Source/API/FIRFieldValue+Internal.h"
  22. #import "Firestore/Source/Model/FSTDocument.h"
  23. #import "Firestore/Source/Model/FSTFieldValue.h"
  24. #import "Firestore/Example/Tests/Util/FSTHelpers.h"
  25. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  26. #include "Firestore/core/src/firebase/firestore/model/field_mask.h"
  27. #include "Firestore/core/src/firebase/firestore/model/field_transform.h"
  28. #include "Firestore/core/src/firebase/firestore/model/precondition.h"
  29. #include "Firestore/core/src/firebase/firestore/model/transform_operations.h"
  30. #include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
  31. namespace testutil = firebase::firestore::testutil;
  32. using firebase::firestore::model::ArrayTransform;
  33. using firebase::firestore::model::DocumentKey;
  34. using firebase::firestore::model::FieldMask;
  35. using firebase::firestore::model::FieldPath;
  36. using firebase::firestore::model::FieldTransform;
  37. using firebase::firestore::model::Precondition;
  38. using firebase::firestore::model::TransformOperation;
  39. @interface FSTMutationTests : XCTestCase
  40. @end
  41. @implementation FSTMutationTests {
  42. FIRTimestamp *_timestamp;
  43. }
  44. - (void)setUp {
  45. _timestamp = [FIRTimestamp timestamp];
  46. }
  47. - (void)testAppliesSetsToDocuments {
  48. NSDictionary *docData = @{@"foo" : @"foo-value", @"baz" : @"baz-value"};
  49. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  50. FSTMutation *set = FSTTestSetMutation(@"collection/key", @{@"bar" : @"bar-value"});
  51. FSTMaybeDocument *setDoc = [set applyToLocalDocument:baseDoc
  52. baseDocument:baseDoc
  53. localWriteTime:_timestamp];
  54. NSDictionary *expectedData = @{@"bar" : @"bar-value"};
  55. XCTAssertEqualObjects(
  56. setDoc, FSTTestDoc("collection/key", 0, expectedData, FSTDocumentStateLocalMutations));
  57. }
  58. - (void)testAppliesPatchesToDocuments {
  59. NSDictionary *docData = @{@"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value"};
  60. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  61. FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {});
  62. FSTMaybeDocument *patchedDoc = [patch applyToLocalDocument:baseDoc
  63. baseDocument:baseDoc
  64. localWriteTime:_timestamp];
  65. NSDictionary *expectedData = @{@"foo" : @{@"bar" : @"new-bar-value"}, @"baz" : @"baz-value"};
  66. XCTAssertEqualObjects(
  67. patchedDoc, FSTTestDoc("collection/key", 0, expectedData, FSTDocumentStateLocalMutations));
  68. }
  69. - (void)testDeletesValuesFromTheFieldMask {
  70. NSDictionary *docData = @{@"foo" : @{@"bar" : @"bar-value", @"baz" : @"baz-value"}};
  71. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  72. DocumentKey key = testutil::Key("collection/key");
  73. FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:key
  74. fieldMask:{testutil::Field("foo.bar")}
  75. value:[FSTObjectValue objectValue]
  76. precondition:Precondition::None()];
  77. FSTMaybeDocument *patchedDoc = [patch applyToLocalDocument:baseDoc
  78. baseDocument:baseDoc
  79. localWriteTime:_timestamp];
  80. NSDictionary *expectedData = @{@"foo" : @{@"baz" : @"baz-value"}};
  81. XCTAssertEqualObjects(
  82. patchedDoc, FSTTestDoc("collection/key", 0, expectedData, FSTDocumentStateLocalMutations));
  83. }
  84. - (void)testPatchesPrimitiveValue {
  85. NSDictionary *docData = @{@"foo" : @"foo-value", @"baz" : @"baz-value"};
  86. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  87. FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {});
  88. FSTMaybeDocument *patchedDoc = [patch applyToLocalDocument:baseDoc
  89. baseDocument:baseDoc
  90. localWriteTime:_timestamp];
  91. NSDictionary *expectedData = @{@"foo" : @{@"bar" : @"new-bar-value"}, @"baz" : @"baz-value"};
  92. XCTAssertEqualObjects(
  93. patchedDoc, FSTTestDoc("collection/key", 0, expectedData, FSTDocumentStateLocalMutations));
  94. }
  95. - (void)testPatchingDeletedDocumentsDoesNothing {
  96. FSTMaybeDocument *baseDoc = FSTTestDeletedDoc("collection/key", 0, NO);
  97. FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"bar"}, {});
  98. FSTMaybeDocument *patchedDoc = [patch applyToLocalDocument:baseDoc
  99. baseDocument:baseDoc
  100. localWriteTime:_timestamp];
  101. XCTAssertEqualObjects(patchedDoc, baseDoc);
  102. }
  103. - (void)testAppliesLocalServerTimestampTransformToDocuments {
  104. NSDictionary *docData = @{@"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value"};
  105. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  106. FSTMutation *transform = FSTTestTransformMutation(
  107. @"collection/key", @{@"foo.bar" : [FIRFieldValue fieldValueForServerTimestamp]});
  108. FSTMaybeDocument *transformedDoc = [transform applyToLocalDocument:baseDoc
  109. baseDocument:baseDoc
  110. localWriteTime:_timestamp];
  111. // Server timestamps aren't parsed, so we manually insert it.
  112. FSTObjectValue *expectedData =
  113. FSTTestObjectValue(@{@"foo" : @{@"bar" : @"<server-timestamp>"}, @"baz" : @"baz-value"});
  114. expectedData =
  115. [expectedData objectBySettingValue:[FSTServerTimestampValue
  116. serverTimestampValueWithLocalWriteTime:_timestamp
  117. previousValue:nil]
  118. forPath:testutil::Field("foo.bar")];
  119. FSTDocument *expectedDoc = [FSTDocument documentWithData:expectedData
  120. key:FSTTestDocKey(@"collection/key")
  121. version:testutil::Version(0)
  122. state:FSTDocumentStateLocalMutations];
  123. XCTAssertEqualObjects(transformedDoc, expectedDoc);
  124. }
  125. // NOTE: This is more a test of FSTUserDataConverter code than FSTMutation code but we don't have
  126. // unit tests for it currently. We could consider removing this test once we have integration tests.
  127. - (void)testCreateArrayUnionTransform {
  128. FSTTransformMutation *transform = FSTTestTransformMutation(@"collection/key", @{
  129. @"foo" : [FIRFieldValue fieldValueForArrayUnion:@[ @"tag" ]],
  130. @"bar.baz" :
  131. [FIRFieldValue fieldValueForArrayUnion:@[ @YES, @{@"nested" : @{@"a" : @[ @1, @2 ]}} ]]
  132. });
  133. XCTAssertEqual(transform.fieldTransforms.size(), 2);
  134. const FieldTransform &first = transform.fieldTransforms[0];
  135. XCTAssertEqual(first.path(), FieldPath({"foo"}));
  136. {
  137. std::vector<FSTFieldValue *> expectedElements{FSTTestFieldValue(@"tag")};
  138. ArrayTransform expected(TransformOperation::Type::ArrayUnion, expectedElements);
  139. XCTAssertEqual(static_cast<const ArrayTransform &>(first.transformation()), expected);
  140. }
  141. const FieldTransform &second = transform.fieldTransforms[1];
  142. XCTAssertEqual(second.path(), FieldPath({"bar", "baz"}));
  143. {
  144. std::vector<FSTFieldValue *> expectedElements {
  145. FSTTestFieldValue(@YES), FSTTestFieldValue(@{@"nested" : @{@"a" : @[ @1, @2 ]}})
  146. };
  147. ArrayTransform expected(TransformOperation::Type::ArrayUnion, expectedElements);
  148. XCTAssertEqual(static_cast<const ArrayTransform &>(second.transformation()), expected);
  149. }
  150. }
  151. // NOTE: This is more a test of FSTUserDataConverter code than FSTMutation code but we don't have
  152. // unit tests for it currently. We could consider removing this test once we have integration tests.
  153. - (void)testCreateArrayRemoveTransform {
  154. FSTTransformMutation *transform = FSTTestTransformMutation(@"collection/key", @{
  155. @"foo" : [FIRFieldValue fieldValueForArrayRemove:@[ @"tag" ]],
  156. });
  157. XCTAssertEqual(transform.fieldTransforms.size(), 1);
  158. const FieldTransform &first = transform.fieldTransforms[0];
  159. XCTAssertEqual(first.path(), FieldPath({"foo"}));
  160. {
  161. std::vector<FSTFieldValue *> expectedElements{FSTTestFieldValue(@"tag")};
  162. const ArrayTransform expected(TransformOperation::Type::ArrayRemove, expectedElements);
  163. XCTAssertEqual(static_cast<const ArrayTransform &>(first.transformation()), expected);
  164. }
  165. }
  166. - (void)testAppliesLocalArrayUnionTransformToMissingField {
  167. auto baseDoc = @{};
  168. auto transform = @{@"missing" : [FIRFieldValue fieldValueForArrayUnion:@[ @1, @2 ]]};
  169. auto expected = @{@"missing" : @[ @1, @2 ]};
  170. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  171. }
  172. - (void)testAppliesLocalArrayUnionTransformToNonArrayField {
  173. auto baseDoc = @{@"non-array" : @42};
  174. auto transform = @{@"non-array" : [FIRFieldValue fieldValueForArrayUnion:@[ @1, @2 ]]};
  175. auto expected = @{@"non-array" : @[ @1, @2 ]};
  176. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  177. }
  178. - (void)testAppliesLocalArrayUnionTransformWithNonExistingElements {
  179. auto baseDoc = @{@"array" : @[ @1, @3 ]};
  180. auto transform = @{@"array" : [FIRFieldValue fieldValueForArrayUnion:@[ @2, @4 ]]};
  181. auto expected = @{@"array" : @[ @1, @3, @2, @4 ]};
  182. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  183. }
  184. - (void)testAppliesLocalArrayUnionTransformWithExistingElements {
  185. auto baseDoc = @{@"array" : @[ @1, @3 ]};
  186. auto transform = @{@"array" : [FIRFieldValue fieldValueForArrayUnion:@[ @1, @3 ]]};
  187. auto expected = @{@"array" : @[ @1, @3 ]};
  188. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  189. }
  190. - (void)testAppliesLocalArrayUnionTransformWithDuplicateExistingElements {
  191. // Duplicate entries in your existing array should be preserved.
  192. auto baseDoc = @{@"array" : @[ @1, @2, @2, @3 ]};
  193. auto transform = @{@"array" : [FIRFieldValue fieldValueForArrayUnion:@[ @2 ]]};
  194. auto expected = @{@"array" : @[ @1, @2, @2, @3 ]};
  195. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  196. }
  197. - (void)testAppliesLocalArrayUnionTransformWithDuplicateUnionElements {
  198. // Duplicate entries in your union array should only be added once.
  199. auto baseDoc = @{@"array" : @[ @1, @3 ]};
  200. auto transform = @{@"array" : [FIRFieldValue fieldValueForArrayUnion:@[ @2, @2 ]]};
  201. auto expected = @{@"array" : @[ @1, @3, @2 ]};
  202. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  203. }
  204. - (void)testAppliesLocalArrayUnionTransformWithNonPrimitiveElements {
  205. // Union nested object values (one existing, one not).
  206. auto baseDoc = @{@"array" : @[ @1, @{@"a" : @"b"} ]};
  207. auto transform =
  208. @{@"array" : [FIRFieldValue fieldValueForArrayUnion:@[ @{@"a" : @"b"}, @{@"c" : @"d"} ]]};
  209. auto expected = @{@"array" : @[ @1, @{@"a" : @"b"}, @{@"c" : @"d"} ]};
  210. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  211. }
  212. - (void)testAppliesLocalArrayUnionTransformWithPartiallyOverlappingElements {
  213. // Union objects that partially overlap an existing object.
  214. auto baseDoc = @{@"array" : @[ @1, @{@"a" : @"b", @"c" : @"d"} ]};
  215. auto transform =
  216. @{@"array" : [FIRFieldValue fieldValueForArrayUnion:@[ @{@"a" : @"b"}, @{@"c" : @"d"} ]]};
  217. auto expected =
  218. @{@"array" : @[ @1, @{@"a" : @"b", @"c" : @"d"}, @{@"a" : @"b"}, @{@"c" : @"d"} ]};
  219. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  220. }
  221. - (void)testAppliesLocalArrayRemoveTransformToMissingField {
  222. auto baseDoc = @{};
  223. auto transform = @{@"missing" : [FIRFieldValue fieldValueForArrayRemove:@[ @1, @2 ]]};
  224. auto expected = @{@"missing" : @[]};
  225. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  226. }
  227. - (void)testAppliesLocalArrayRemoveTransformToNonArrayField {
  228. auto baseDoc = @{@"non-array" : @42};
  229. auto transform = @{@"non-array" : [FIRFieldValue fieldValueForArrayRemove:@[ @1, @2 ]]};
  230. auto expected = @{@"non-array" : @[]};
  231. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  232. }
  233. - (void)testAppliesLocalArrayRemoveTransformWithNonExistingElements {
  234. auto baseDoc = @{@"array" : @[ @1, @3 ]};
  235. auto transform = @{@"array" : [FIRFieldValue fieldValueForArrayRemove:@[ @2, @4 ]]};
  236. auto expected = @{@"array" : @[ @1, @3 ]};
  237. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  238. }
  239. - (void)testAppliesLocalArrayRemoveTransformWithExistingElements {
  240. auto baseDoc = @{@"array" : @[ @1, @2, @3, @4 ]};
  241. auto transform = @{@"array" : [FIRFieldValue fieldValueForArrayRemove:@[ @1, @3 ]]};
  242. auto expected = @{@"array" : @[ @2, @4 ]};
  243. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  244. }
  245. - (void)testAppliesLocalArrayRemoveTransformWithNonPrimitiveElements {
  246. // Remove nested object values (one existing, one not).
  247. auto baseDoc = @{@"array" : @[ @1, @{@"a" : @"b"} ]};
  248. auto transform =
  249. @{@"array" : [FIRFieldValue fieldValueForArrayRemove:@[ @{@"a" : @"b"}, @{@"c" : @"d"} ]]};
  250. auto expected = @{@"array" : @[ @1 ]};
  251. [self transformBaseDoc:baseDoc with:transform expecting:expected];
  252. }
  253. // Helper to test a particular transform scenario.
  254. - (void)transformBaseDoc:(NSDictionary<NSString *, id> *)baseData
  255. with:(NSDictionary<NSString *, id> *)transformData
  256. expecting:(NSDictionary<NSString *, id> *)expectedData {
  257. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, baseData, FSTDocumentStateSynced);
  258. FSTMutation *transform = FSTTestTransformMutation(@"collection/key", transformData);
  259. FSTMaybeDocument *transformedDoc = [transform applyToLocalDocument:baseDoc
  260. baseDocument:baseDoc
  261. localWriteTime:_timestamp];
  262. FSTDocument *expectedDoc = [FSTDocument documentWithData:FSTTestObjectValue(expectedData)
  263. key:FSTTestDocKey(@"collection/key")
  264. version:testutil::Version(0)
  265. state:FSTDocumentStateLocalMutations];
  266. XCTAssertEqualObjects(transformedDoc, expectedDoc);
  267. }
  268. - (void)testAppliesServerAckedServerTimestampTransformToDocuments {
  269. NSDictionary *docData = @{@"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value"};
  270. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  271. FSTMutation *transform = FSTTestTransformMutation(
  272. @"collection/key", @{@"foo.bar" : [FIRFieldValue fieldValueForServerTimestamp]});
  273. FSTMutationResult *mutationResult = [[FSTMutationResult alloc]
  274. initWithVersion:testutil::Version(1)
  275. transformResults:@[ [FSTTimestampValue timestampValue:_timestamp] ]];
  276. FSTMaybeDocument *transformedDoc = [transform applyToRemoteDocument:baseDoc
  277. mutationResult:mutationResult];
  278. NSDictionary *expectedData = @{@"foo" : @{@"bar" : _timestamp.dateValue}, @"baz" : @"baz-value"};
  279. XCTAssertEqualObjects(transformedDoc, FSTTestDoc("collection/key", 1, expectedData,
  280. FSTDocumentStateCommittedMutations));
  281. }
  282. - (void)testAppliesServerAckedArrayTransformsToDocuments {
  283. NSDictionary *docData = @{@"array_1" : @[ @1, @2 ], @"array_2" : @[ @"a", @"b" ]};
  284. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  285. FSTMutation *transform = FSTTestTransformMutation(@"collection/key", @{
  286. @"array_1" : [FIRFieldValue fieldValueForArrayUnion:@[ @2, @3 ]],
  287. @"array_2" : [FIRFieldValue fieldValueForArrayRemove:@[ @"a", @"c" ]]
  288. });
  289. // Server just sends null transform results for array operations.
  290. FSTMutationResult *mutationResult = [[FSTMutationResult alloc]
  291. initWithVersion:testutil::Version(1)
  292. transformResults:@[ [FSTNullValue nullValue], [FSTNullValue nullValue] ]];
  293. FSTMaybeDocument *transformedDoc = [transform applyToRemoteDocument:baseDoc
  294. mutationResult:mutationResult];
  295. NSDictionary *expectedData = @{@"array_1" : @[ @1, @2, @3 ], @"array_2" : @[ @"b" ]};
  296. XCTAssertEqualObjects(transformedDoc, FSTTestDoc("collection/key", 1, expectedData,
  297. FSTDocumentStateCommittedMutations));
  298. }
  299. - (void)testDeleteDeletes {
  300. NSDictionary *docData = @{@"foo" : @"bar"};
  301. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  302. FSTMutation *mutation = FSTTestDeleteMutation(@"collection/key");
  303. FSTMaybeDocument *result = [mutation applyToLocalDocument:baseDoc
  304. baseDocument:baseDoc
  305. localWriteTime:_timestamp];
  306. XCTAssertEqualObjects(result, FSTTestDeletedDoc("collection/key", 0, NO));
  307. }
  308. - (void)testSetWithMutationResult {
  309. NSDictionary *docData = @{@"foo" : @"bar"};
  310. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  311. FSTMutation *set = FSTTestSetMutation(@"collection/key", @{@"foo" : @"new-bar"});
  312. FSTMutationResult *mutationResult =
  313. [[FSTMutationResult alloc] initWithVersion:testutil::Version(4) transformResults:nil];
  314. FSTMaybeDocument *setDoc = [set applyToRemoteDocument:baseDoc mutationResult:mutationResult];
  315. NSDictionary *expectedData = @{@"foo" : @"new-bar"};
  316. XCTAssertEqualObjects(
  317. setDoc, FSTTestDoc("collection/key", 4, expectedData, FSTDocumentStateCommittedMutations));
  318. }
  319. - (void)testPatchWithMutationResult {
  320. NSDictionary *docData = @{@"foo" : @"bar"};
  321. FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, FSTDocumentStateSynced);
  322. FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"new-bar"}, {});
  323. FSTMutationResult *mutationResult =
  324. [[FSTMutationResult alloc] initWithVersion:testutil::Version(4) transformResults:nil];
  325. FSTMaybeDocument *patchedDoc = [patch applyToRemoteDocument:baseDoc
  326. mutationResult:mutationResult];
  327. NSDictionary *expectedData = @{@"foo" : @"new-bar"};
  328. XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 4, expectedData,
  329. FSTDocumentStateCommittedMutations));
  330. }
  331. #define ASSERT_VERSION_TRANSITION(mutation, base, result, expected) \
  332. do { \
  333. FSTMaybeDocument *actual = [mutation applyToRemoteDocument:base mutationResult:result]; \
  334. XCTAssertEqualObjects(actual, expected); \
  335. } while (0);
  336. /**
  337. * Tests the transition table documented in FSTMutation.h.
  338. */
  339. - (void)testTransitions {
  340. FSTDocument *docV3 = FSTTestDoc("collection/key", 3, @{}, FSTDocumentStateSynced);
  341. FSTDeletedDocument *deletedV3 = FSTTestDeletedDoc("collection/key", 3, NO);
  342. FSTMutation *setMutation = FSTTestSetMutation(@"collection/key", @{});
  343. FSTMutation *patchMutation = FSTTestPatchMutation("collection/key", @{}, {});
  344. FSTMutation *transformMutation = FSTTestTransformMutation(@"collection/key", @{});
  345. FSTMutation *deleteMutation = FSTTestDeleteMutation(@"collection/key");
  346. FSTDeletedDocument *docV7Deleted = FSTTestDeletedDoc("collection/key", 7, YES);
  347. FSTDocument *docV7Committed =
  348. FSTTestDoc("collection/key", 7, @{}, FSTDocumentStateCommittedMutations);
  349. FSTUnknownDocument *docV7Unknown = FSTTestUnknownDoc("collection/key", 7);
  350. FSTMutationResult *mutationResult =
  351. [[FSTMutationResult alloc] initWithVersion:testutil::Version(7) transformResults:nil];
  352. FSTMutationResult *transformResult =
  353. [[FSTMutationResult alloc] initWithVersion:testutil::Version(7) transformResults:@[]];
  354. ASSERT_VERSION_TRANSITION(setMutation, docV3, mutationResult, docV7Committed);
  355. ASSERT_VERSION_TRANSITION(setMutation, deletedV3, mutationResult, docV7Committed);
  356. ASSERT_VERSION_TRANSITION(setMutation, nil, mutationResult, docV7Committed);
  357. ASSERT_VERSION_TRANSITION(patchMutation, docV3, mutationResult, docV7Committed);
  358. ASSERT_VERSION_TRANSITION(patchMutation, deletedV3, mutationResult, docV7Unknown);
  359. ASSERT_VERSION_TRANSITION(patchMutation, nil, mutationResult, docV7Unknown);
  360. ASSERT_VERSION_TRANSITION(transformMutation, docV3, transformResult, docV7Committed);
  361. ASSERT_VERSION_TRANSITION(transformMutation, deletedV3, transformResult, docV7Unknown);
  362. ASSERT_VERSION_TRANSITION(transformMutation, nil, transformResult, docV7Unknown);
  363. ASSERT_VERSION_TRANSITION(deleteMutation, docV3, mutationResult, docV7Deleted);
  364. ASSERT_VERSION_TRANSITION(deleteMutation, deletedV3, mutationResult, docV7Deleted);
  365. ASSERT_VERSION_TRANSITION(deleteMutation, nil, mutationResult, docV7Deleted);
  366. }
  367. #undef ASSERT_TRANSITION
  368. @end