aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Integration
diff options
context:
space:
mode:
authorGravatar Michael Lehenbauer <mikelehen@gmail.com>2018-04-23 10:03:55 -0700
committerGravatar GitHub <noreply@github.com>2018-04-23 10:03:55 -0700
commite4384c3e809556e75907df74cd116307f397472f (patch)
tree98841eba1d45eb94adcb798b6f792c16ba4b8d18 /Firestore/Example/Tests/Integration
parent8e70791465f9b5e4bb75dfc18de4a4ed90961974 (diff)
Array Contains Queries (not added to public headers yet). (#1138)
Diffstat (limited to 'Firestore/Example/Tests/Integration')
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRQueryTests.mm45
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRValidationTests.mm22
2 files changed, 64 insertions, 3 deletions
diff --git a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm
index d1c0d75..bdd3df1 100644
--- a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm
+++ b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm
@@ -20,8 +20,7 @@
#import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
-#import "Firestore/Source/API/FIRFirestore+Internal.h"
-#import "Firestore/Source/Core/FSTFirestoreClient.h"
+#import "Firestore/Source/API/FIRQuery+Internal.h"
@interface FIRQueryTests : FSTIntegrationTestCase
@end
@@ -294,4 +293,46 @@
]));
}
+// TODO(array-features): Enable once backend support lands.
+- (void)xtestArrayContainsQueries {
+ NSDictionary *testDocs = @{
+ @"a" : @{@"array" : @[ @42 ]},
+ @"b" : @{@"array" : @[ @"a", @42, @"c" ]},
+ @"c" : @{@"array" : @[ @41.999, @"42",
+ @{ @"a" : @[ @42 ] } ]},
+ @"d" : @{@"array" : @[ @42 ], @"array2" : @[ @"bingo" ]}
+ };
+ FIRCollectionReference *collection = [self collectionRefWithDocuments:testDocs];
+
+ // Search for 42
+ FIRQuerySnapshot *snapshot =
+ [self readDocumentSetForRef:[collection queryWhereField:@"array" arrayContains:@42]];
+ XCTAssertEqualObjects(FIRQuerySnapshotGetData(snapshot), (@[
+ @{ @"array" : @[ @42 ] },
+ @{ @"array" : @[ @"a", @42, @"c" ] },
+ @{ @"array" : @[ @42 ],
+ @"array2" : @[ @"bingo" ] }
+ ]));
+
+ // Search for "array" to contain both @42 and "a".
+ snapshot = [self readDocumentSetForRef:[[collection queryWhereField:@"array" arrayContains:@42]
+ queryWhereField:@"array"
+ arrayContains:@"a"]];
+ XCTAssertEqualObjects(FIRQuerySnapshotGetData(snapshot), (@[
+ @{ @"array" : @[ @"a", @42, @"c" ] },
+ ]));
+
+ // Search two different array fields ("array" contains 42 and "array2" contains "bingo").
+ snapshot = [self readDocumentSetForRef:[[collection queryWhereField:@"array" arrayContains:@42]
+ queryWhereField:@"array2"
+ arrayContains:@"bingo"]];
+ XCTAssertEqualObjects(FIRQuerySnapshotGetData(snapshot), (@[
+ @{ @"array" : @[ @42 ],
+ @"array2" : @[ @"bingo" ] }
+ ]));
+
+ // NOTE: The backend doesn't currently support null, NaN, objects, or arrays, so there isn't much
+ // of anything else interesting to test.
+}
+
@end
diff --git a/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm b/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm
index ee0f386..6d10aba 100644
--- a/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm
+++ b/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm
@@ -19,6 +19,7 @@
#import <XCTest/XCTest.h>
#import "Firestore/Source/API/FIRFieldValue+Internal.h"
+#import "Firestore/Source/API/FIRQuery+Internal.h"
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
@@ -419,14 +420,20 @@
@"Invalid Query. Query limit (-1) is invalid. Limit must be positive.");
}
-- (void)testQueryInequalityOnNullOrNaNFails {
+- (void)testNonEqualityQueriesOnNullOrNaNFail {
FSTAssertThrows([[self collectionRef] queryWhereField:@"a" isGreaterThan:nil],
@"Invalid Query. You can only perform equality comparisons on nil / NSNull.");
FSTAssertThrows([[self collectionRef] queryWhereField:@"a" isGreaterThan:[NSNull null]],
@"Invalid Query. You can only perform equality comparisons on nil / NSNull.");
+ FSTAssertThrows([[self collectionRef] queryWhereField:@"a" arrayContains:nil],
+ @"Invalid Query. You can only perform equality comparisons on nil / NSNull.");
+ FSTAssertThrows([[self collectionRef] queryWhereField:@"a" arrayContains:[NSNull null]],
+ @"Invalid Query. You can only perform equality comparisons on nil / NSNull.");
FSTAssertThrows([[self collectionRef] queryWhereField:@"a" isGreaterThan:@(NAN)],
@"Invalid Query. You can only perform equality comparisons on NaN.");
+ FSTAssertThrows([[self collectionRef] queryWhereField:@"a" arrayContains:@(NAN)],
+ @"Invalid Query. You can only perform equality comparisons on NaN.");
}
- (void)testQueryCannotBeCreatedFromDocumentsMissingSortValues {
@@ -498,6 +505,12 @@
@"Invalid query. When querying by document ID you must provide a valid string or "
"DocumentReference, but it was of type: __NSCFNumber";
FSTAssertThrows([collection queryWhereFieldPath:[FIRFieldPath documentID] isEqualTo:@1], reason);
+
+ reason =
+ @"Invalid query. You can't do arrayContains queries on document ID since document IDs are "
+ @"not arrays.";
+ FSTAssertThrows([collection queryWhereFieldPath:[FIRFieldPath documentID] arrayContains:@1],
+ reason);
}
- (void)testQueryInequalityFieldMustMatchFirstOrderByField {
@@ -526,6 +539,8 @@
XCTAssertNoThrow([base queryWhereField:@"y" isEqualTo:@"cat"],
@"Inequality and equality on different fields works");
+ XCTAssertNoThrow([base queryWhereField:@"y" arrayContains:@"cat"],
+ @"Inequality and array_contains on different fields works");
XCTAssertNoThrow([base queryOrderedByField:@"x"], @"inequality same as order by works");
XCTAssertNoThrow([[coll queryOrderedByField:@"x"] queryWhereField:@"x" isGreaterThan:@32],
@@ -535,6 +550,11 @@
XCTAssertNoThrow([[[coll queryOrderedByField:@"x"] queryOrderedByField:@"y"] queryWhereField:@"x"
isGreaterThan:@32],
@"inequality same as first order by works.");
+
+ XCTAssertNoThrow([[coll queryOrderedByField:@"x"] queryWhereField:@"y" isEqualTo:@"cat"],
+ @"equality different than orderBy works.");
+ XCTAssertNoThrow([[coll queryOrderedByField:@"x"] queryWhereField:@"y" arrayContains:@"cat"],
+ @"array_contains different than orderBy works.");
}
#pragma mark - GeoPoint Validation