|
38 | 38 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
|
39 | 39 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
|
40 | 40 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
|
| 41 | +import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitForException; |
41 | 42 | import static com.google.firebase.firestore.testutil.TestUtil.expectError;
|
42 | 43 | import static com.google.firebase.firestore.testutil.TestUtil.map;
|
43 | 44 | import static java.util.Arrays.asList;
|
@@ -2193,4 +2194,45 @@ public void testMultipleInequalityFromCacheAndFromServer() {
|
2193 | 2194 | Query query5 = collection.where(or(greaterThan("a", 2), lessThan("b", 1)));
|
2194 | 2195 | checkOnlineAndOfflineResultsMatch(query5, "doc1", "doc3");
|
2195 | 2196 | }
|
| 2197 | + |
| 2198 | + @Test |
| 2199 | + public void testMultipleInequalityRejectsIfDocumentKeyIsNotTheLastOrderByField() { |
| 2200 | + // TODO(MIEQ): Enable this test against production when possible. |
| 2201 | + assumeTrue( |
| 2202 | + "Skip this test if running against production because multiple inequality is " |
| 2203 | + + "not supported yet.", |
| 2204 | + isRunningAgainstEmulator()); |
| 2205 | + |
| 2206 | + CollectionReference collection = testCollection(); |
| 2207 | + |
| 2208 | + // Implicitly ordered by: __name__ asc, 'key' asc, |
| 2209 | + Query query = collection.whereNotEqualTo("key", 42).orderBy(FieldPath.documentId()); |
| 2210 | + Exception e = waitForException(query.get()); |
| 2211 | + FirebaseFirestoreException firestoreException = (FirebaseFirestoreException) e; |
| 2212 | + assertTrue( |
| 2213 | + firestoreException |
| 2214 | + .getMessage() |
| 2215 | + .contains("order by clause cannot contain more fields after the key")); |
| 2216 | + } |
| 2217 | + |
| 2218 | + @Test |
| 2219 | + public void testMultipleInequalityRejectsIfDocumentKeyAppearsOnlyInEqualityFilter() { |
| 2220 | + // TODO(MIEQ): Enable this test against production when possible. |
| 2221 | + assumeTrue( |
| 2222 | + "Skip this test if running against production because multiple inequality is " |
| 2223 | + + "not supported yet.", |
| 2224 | + isRunningAgainstEmulator()); |
| 2225 | + |
| 2226 | + CollectionReference collection = testCollection(); |
| 2227 | + |
| 2228 | + Query query = |
| 2229 | + collection.whereNotEqualTo("key", 42).whereEqualTo(FieldPath.documentId(), "doc1"); |
| 2230 | + Exception e = waitForException(query.get()); |
| 2231 | + FirebaseFirestoreException firestoreException = (FirebaseFirestoreException) e; |
| 2232 | + assertTrue( |
| 2233 | + firestoreException |
| 2234 | + .getMessage() |
| 2235 | + .contains( |
| 2236 | + "Equality on key is not allowed if there are other inequality fields and key does not appear in inequalities.")); |
| 2237 | + } |
2196 | 2238 | }
|
0 commit comments