aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Core
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/Core
parent8e70791465f9b5e4bb75dfc18de4a4ed90961974 (diff)
Array Contains Queries (not added to public headers yet). (#1138)
Diffstat (limited to 'Firestore/Example/Tests/Core')
-rw-r--r--Firestore/Example/Tests/Core/FSTQueryTests.mm49
1 files changed, 49 insertions, 0 deletions
diff --git a/Firestore/Example/Tests/Core/FSTQueryTests.mm b/Firestore/Example/Tests/Core/FSTQueryTests.mm
index 02310aa..6118d0f 100644
--- a/Firestore/Example/Tests/Core/FSTQueryTests.mm
+++ b/Firestore/Example/Tests/Core/FSTQueryTests.mm
@@ -151,6 +151,55 @@ NS_ASSUME_NONNULL_BEGIN
XCTAssertFalse([query2 matchesDocument:doc6]);
}
+- (void)testArrayContainsFilter {
+ FSTQuery *query = [FSTTestQuery("collection")
+ queryByAddingFilter:FSTTestFilter("array", @"array_contains", @42)];
+
+ // not an array.
+ FSTDocument *doc = FSTTestDoc("collection/1", 0, @{ @"array" : @1 }, NO);
+ XCTAssertFalse([query matchesDocument:doc]);
+
+ // empty array.
+ doc = FSTTestDoc("collection/1", 0, @{ @"array" : @[] }, NO);
+ XCTAssertFalse([query matchesDocument:doc]);
+
+ // array without element (and make sure it doesn't match in a nested field or a different field).
+ doc = FSTTestDoc(
+ "collection/1", 0,
+ @{ @"array" : @[ @41, @"42",
+ @{ @"a" : @42,
+ @"b" : @[ @42 ] } ],
+ @"different" : @[ @42 ] },
+ NO);
+ XCTAssertFalse([query matchesDocument:doc]);
+
+ // array with element.
+ doc = FSTTestDoc("collection/1", 0, @{ @"array" : @[ @1, @"2", @42, @{ @"a" : @1 } ] }, NO);
+ XCTAssertTrue([query matchesDocument:doc]);
+}
+
+- (void)testArrayContainsFilterWithObjectValue {
+ // Search for arrays containing the object { a: [42] }
+ FSTQuery *query =
+ [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("array", @"array_contains",
+ @{ @"a" : @[ @42 ] })];
+
+ // array without element.
+ FSTDocument *doc = FSTTestDoc(
+ "collection/1", 0,
+ @{ @"array" : @[
+ @{ @"a" : @42 },
+ @{ @"a" : @[ @42, @43 ] },
+ @{ @"b" : @[ @42 ] }
+ ] },
+ NO);
+ XCTAssertFalse([query matchesDocument:doc]);
+
+ // array with element.
+ doc = FSTTestDoc("collection/1", 0, @{ @"array" : @[ @1, @"2", @42, @{ @"a" : @[ @42 ] } ] }, NO);
+ XCTAssertTrue([query matchesDocument:doc]);
+}
+
- (void)testNullFilter {
FSTQuery *query =
[FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @"==", [NSNull null])];