From e8e7df57fd99c2f6a3e0b618ac25ce6459424482 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:10:11 -0500 Subject: [PATCH 1/3] add tests --- .../Tests/Integration/API/FIRQueryTests.mm | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm index b1cd36a5c49..491ff1ed491 100644 --- a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm @@ -896,6 +896,48 @@ - (void)testSdkOrdersQueryByDocumentIdTheSameWayOnlineAndOffline { ]]; } +- (void)testSnapshotListenerSortsUnicodeStringsInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a": @{@"value": @ "Łukasiewicz"}, + @"b": @{@"value": @"Sierpiński"}, + @"c": @{@"value": @"岩澤"}, + @"d": @{@"value": @"🄟"}, + @"e": @{@"value": @"P"}, + @"f": @{@"value": @"︒"}, + @"g": @{@"value": @"🐵"} + + }]; + + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = + @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g"]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsTheSameWayOnlineAndOffline { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a": @{@"value": @ "Łukasiewicz"}, + @"b": @{@"value": @"Sierpiński"}, + @"c": @{@"value": @"岩澤"}, + @"d": @{@"value": @"🄟"}, + @"e": @{@"value": @"P"}, + @"f": @{@"value": @"︒"}, + @"g": @{@"value": @"🐵"} + + }]; + + [self checkOnlineAndOfflineQuery:[collRef queryOrderedByField:@"value"] + matchesResult:@[@"b", @"a", @"c", @"f", @"e", @"d", @"g"]]; +} + - (void)testCollectionGroupQueriesWithWhereFiltersOnArbitraryDocumentIDs { // Use .document() to get a random collection group name to use but ensure it starts with 'b' // for predictable ordering. From 0c5a93d853046fa7fa03db5406ede1b9b060625b Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:19:34 -0500 Subject: [PATCH 2/3] format --- .../Tests/Integration/API/FIRQueryTests.mm | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm index 491ff1ed491..3a51e899945 100644 --- a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm @@ -898,19 +898,18 @@ - (void)testSdkOrdersQueryByDocumentIdTheSameWayOnlineAndOffline { - (void)testSnapshotListenerSortsUnicodeStringsInTheSameOrderAsServer { FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ - @"a": @{@"value": @ "Łukasiewicz"}, - @"b": @{@"value": @"Sierpiński"}, - @"c": @{@"value": @"岩澤"}, - @"d": @{@"value": @"🄟"}, - @"e": @{@"value": @"P"}, - @"f": @{@"value": @"︒"}, - @"g": @{@"value": @"🐵"} + @"a" : @{@"value" : @ "Łukasiewicz"}, + @"b" : @{@"value" : @"Sierpiński"}, + @"c" : @{@"value" : @"岩澤"}, + @"d" : @{@"value" : @"🄟"}, + @"e" : @{@"value" : @"P"}, + @"f" : @{@"value" : @"︒"}, + @"g" : @{@"value" : @"🐵"} }]; FIRQuery *query = [collRef queryOrderedByField:@"value"]; - NSArray *expectedDocs = - @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); @@ -924,18 +923,18 @@ - (void)testSnapshotListenerSortsUnicodeStringsInTheSameOrderAsServer { - (void)testSnapshotListenerSortsUnicodeStringsTheSameWayOnlineAndOffline { FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ - @"a": @{@"value": @ "Łukasiewicz"}, - @"b": @{@"value": @"Sierpiński"}, - @"c": @{@"value": @"岩澤"}, - @"d": @{@"value": @"🄟"}, - @"e": @{@"value": @"P"}, - @"f": @{@"value": @"︒"}, - @"g": @{@"value": @"🐵"} + @"a" : @{@"value" : @ "Łukasiewicz"}, + @"b" : @{@"value" : @"Sierpiński"}, + @"c" : @{@"value" : @"岩澤"}, + @"d" : @{@"value" : @"🄟"}, + @"e" : @{@"value" : @"P"}, + @"f" : @{@"value" : @"︒"}, + @"g" : @{@"value" : @"🐵"} }]; - + [self checkOnlineAndOfflineQuery:[collRef queryOrderedByField:@"value"] - matchesResult:@[@"b", @"a", @"c", @"f", @"e", @"d", @"g"]]; + matchesResult:@[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]]; } - (void)testCollectionGroupQueriesWithWhereFiltersOnArbitraryDocumentIDs { From 9811a3f85075014240f3a374ff48273edbcd1fe9 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:47:50 -0500 Subject: [PATCH 3/3] add more tests --- .../Tests/Integration/API/FIRQueryTests.mm | 117 ++++++++++++++++-- 1 file changed, 106 insertions(+), 11 deletions(-) diff --git a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm index 3a51e899945..0b92a36ea48 100644 --- a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm @@ -898,7 +898,7 @@ - (void)testSdkOrdersQueryByDocumentIdTheSameWayOnlineAndOffline { - (void)testSnapshotListenerSortsUnicodeStringsInTheSameOrderAsServer { FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ - @"a" : @{@"value" : @ "Łukasiewicz"}, + @"a" : @{@"value" : @"Łukasiewicz"}, @"b" : @{@"value" : @"Sierpiński"}, @"c" : @{@"value" : @"岩澤"}, @"d" : @{@"value" : @"🄟"}, @@ -919,22 +919,117 @@ - (void)testSnapshotListenerSortsUnicodeStringsInTheSameOrderAsServer { XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; } -- (void)testSnapshotListenerSortsUnicodeStringsTheSameWayOnlineAndOffline { +- (void)testSnapshotListenerSortsUnicodeStringsInArrayInTheSameOrderAsServer { FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ - @"a" : @{@"value" : @ "Łukasiewicz"}, - @"b" : @{@"value" : @"Sierpiński"}, - @"c" : @{@"value" : @"岩澤"}, - @"d" : @{@"value" : @"🄟"}, - @"e" : @{@"value" : @"P"}, - @"f" : @{@"value" : @"︒"}, - @"g" : @{@"value" : @"🐵"} + @"a" : @{@"value" : @[ @"Łukasiewicz" ]}, + @"b" : @{@"value" : @[ @"Sierpiński" ]}, + @"c" : @{@"value" : @[ @"岩澤" ]}, + @"d" : @{@"value" : @[ @"🄟" ]}, + @"e" : @{@"value" : @[ @"P" ]}, + @"f" : @{@"value" : @[ @"︒" ]}, + @"g" : @{@"value" : @[ @"🐵" ]} }]; - [self checkOnlineAndOfflineQuery:[collRef queryOrderedByField:@"value"] - matchesResult:@[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]]; + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsInMapInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a" : @{@"value" : @{@"foo" : @"Łukasiewicz"}}, + @"b" : @{@"value" : @{@"foo" : @"Sierpiński"}}, + @"c" : @{@"value" : @{@"foo" : @"岩澤"}}, + @"d" : @{@"value" : @{@"foo" : @"🄟"}}, + @"e" : @{@"value" : @{@"foo" : @"P"}}, + @"f" : @{@"value" : @{@"foo" : @"︒"}}, + @"g" : @{@"value" : @{@"foo" : @"🐵"}} + + }]; + + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsInMapKeyInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"a" : @{@"value" : @{@"Łukasiewicz" : @"foo"}}, + @"b" : @{@"value" : @{@"Sierpiński" : @"foo"}}, + @"c" : @{@"value" : @{@"岩澤" : @"foo"}}, + @"d" : @{@"value" : @{@"🄟" : @"foo"}}, + @"e" : @{@"value" : @{@"P" : @"foo"}}, + @"f" : @{@"value" : @{@"︒" : @"foo"}}, + @"g" : @{@"value" : @{@"🐵" : @"foo"}} + + }]; + + FIRQuery *query = [collRef queryOrderedByField:@"value"]; + NSArray *expectedDocs = @[ @"b", @"a", @"c", @"f", @"e", @"d", @"g" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; +} + +- (void)testSnapshotListenerSortsUnicodeStringsInDocumentKeyInTheSameOrderAsServer { + FIRCollectionReference *collRef = [self collectionRefWithDocuments:@{ + @"Łukasiewicz" : @{@"value" : @"foo"}, + @"Sierpiński" : @{@"value" : @"foo"}, + @"岩澤" : @{@"value" : @"foo"}, + @"🄟" : @{@"value" : @"foo"}, + @"P" : @{@"value" : @"foo"}, + @"︒" : @{@"value" : @"foo"}, + @"🐵" : @{@"value" : @"foo"} + + }]; + + FIRQuery *query = [collRef queryOrderedByFieldPath:[FIRFieldPath documentID]]; + NSArray *expectedDocs = + @[ @"Sierpiński", @"Łukasiewicz", @"岩澤", @"︒", @"P", @"🄟", @"🐵" ]; + FIRQuerySnapshot *getSnapshot = [self readDocumentSetForRef:query]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(getSnapshot), expectedDocs); + + id registration = + [query addSnapshotListener:self.eventAccumulator.valueEventHandler]; + FIRQuerySnapshot *watchSnapshot = [self.eventAccumulator awaitEventWithName:@"Snapshot"]; + XCTAssertEqualObjects(FIRQuerySnapshotGetIDs(watchSnapshot), expectedDocs); + + [registration remove]; + + [self checkOnlineAndOfflineQuery:query matchesResult:expectedDocs]; } - (void)testCollectionGroupQueriesWithWhereFiltersOnArbitraryDocumentIDs {