From a5eb8952f8eadf1f59de1b0e7e9b91d497664fa7 Mon Sep 17 00:00:00 2001 From: Gil Date: Mon, 9 Jul 2018 10:03:27 -0700 Subject: Add allMutationsAffectingDocumentKeys to FSTMutationQueue (#1479) * Pod updates for Cocapods 1.5.3 * Add allMutationsAffectingDocumentKeys --- .../Example/Tests/Local/FSTMutationQueueTests.mm | 84 +++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) (limited to 'Firestore/Example') diff --git a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm index 5b5bdd1..17e6ccb 100644 --- a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm +++ b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm @@ -31,11 +31,14 @@ #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/document_key_set.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" namespace testutil = firebase::firestore::testutil; using firebase::firestore::auth::User; using firebase::firestore::model::DocumentKey; +using firebase::firestore::model::DocumentKeySet; +using firebase::firestore::testutil::Key; NS_ASSUME_NONNULL_BEGIN @@ -284,7 +287,7 @@ NS_ASSUME_NONNULL_BEGIN self.persistence.run("testAllMutationBatchesAffectingDocumentKey", [&]() { NSArray *mutations = @[ - FSTTestSetMutation(@"fob/bar", + FSTTestSetMutation(@"foi/bar", @{ @"a" : @1 }), FSTTestSetMutation(@"foo/bar", @{ @"a" : @1 }), @@ -315,6 +318,85 @@ NS_ASSUME_NONNULL_BEGIN }); } +- (void)testAllMutationBatchesAffectingDocumentKeys { + if ([self isTestBaseClass]) return; + + self.persistence.run("testAllMutationBatchesAffectingDocumentKey", [&]() { + NSArray *mutations = @[ + FSTTestSetMutation(@"fob/bar", + @{ @"a" : @1 }), + FSTTestSetMutation(@"foo/bar", + @{ @"a" : @1 }), + FSTTestPatchMutation("foo/bar", + @{ @"b" : @1 }, {}), + FSTTestSetMutation(@"foo/bar/suffix/key", + @{ @"a" : @1 }), + FSTTestSetMutation(@"foo/baz", + @{ @"a" : @1 }), + FSTTestSetMutation(@"food/bar", + @{ @"a" : @1 }) + ]; + + // Store all the mutations. + NSMutableArray *batches = [NSMutableArray array]; + for (FSTMutation *mutation in mutations) { + FSTMutationBatch *batch = + [self.mutationQueue addMutationBatchWithWriteTime:[FIRTimestamp timestamp] + mutations:@[ mutation ]]; + [batches addObject:batch]; + } + + DocumentKeySet keys{ + Key("foo/bar"), + Key("foo/baz"), + }; + + NSArray *expected = @[ batches[1], batches[2], batches[4] ]; + NSArray *matches = + [self.mutationQueue allMutationBatchesAffectingDocumentKeys:keys]; + + XCTAssertEqualObjects(matches, expected); + }); +} + +- (void)testAllMutationBatchesAffectingDocumentKeys_handlesOverlap { + if ([self isTestBaseClass]) return; + + self.persistence.run("testAllMutationBatchesAffectingDocumentKeys_handlesOverlap", [&]() { + NSArray *group1 = @[ + FSTTestSetMutation(@"foo/bar", + @{ @"a" : @1 }), + FSTTestSetMutation(@"foo/baz", + @{ @"a" : @1 }), + ]; + FSTMutationBatch *batch1 = + [self.mutationQueue addMutationBatchWithWriteTime:[FIRTimestamp timestamp] + mutations:group1]; + + NSArray *group2 = @[ FSTTestSetMutation(@"food/bar", @{ @"a" : @1 }) ]; + [self.mutationQueue addMutationBatchWithWriteTime:[FIRTimestamp timestamp] mutations:group2]; + + NSArray *group3 = @[ + FSTTestSetMutation(@"foo/bar", + @{ @"b" : @1 }), + ]; + FSTMutationBatch *batch3 = + [self.mutationQueue addMutationBatchWithWriteTime:[FIRTimestamp timestamp] + mutations:group3]; + + DocumentKeySet keys{ + Key("foo/bar"), + Key("foo/baz"), + }; + + NSArray *expected = @[ batch1, batch3 ]; + NSArray *matches = + [self.mutationQueue allMutationBatchesAffectingDocumentKeys:keys]; + + XCTAssertEqualObjects(matches, expected); + }); +} + - (void)testAllMutationBatchesAffectingQuery { if ([self isTestBaseClass]) return; -- cgit v1.2.3