|
15 | 15 | package com.google.firebase.firestore;
|
16 | 16 |
|
17 | 17 | import static com.google.common.truth.Truth.assertThat;
|
| 18 | +import static com.google.firebase.firestore.Filter.and; |
| 19 | +import static com.google.firebase.firestore.Filter.equalTo; |
| 20 | +import static com.google.firebase.firestore.Filter.greaterThan; |
| 21 | +import static com.google.firebase.firestore.Filter.inArray; |
| 22 | +import static com.google.firebase.firestore.Filter.notInArray; |
| 23 | +import static com.google.firebase.firestore.Filter.or; |
18 | 24 | import static com.google.firebase.firestore.testutil.Assert.assertThrows;
|
19 | 25 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testAlternateFirestore;
|
20 | 26 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection;
|
|
39 | 45 | import com.google.firebase.firestore.Transaction.Function;
|
40 | 46 | import com.google.firebase.firestore.testutil.IntegrationTestUtil;
|
41 | 47 | import com.google.firebase.firestore.util.Consumer;
|
| 48 | +import java.util.Arrays; |
42 | 49 | import java.util.Date;
|
43 | 50 | import java.util.List;
|
44 | 51 | import java.util.Map;
|
@@ -815,6 +822,74 @@ public void queriesUsingInAndDocumentIdMustHaveProperDocumentReferencesInArray()
|
815 | 822 | reason);
|
816 | 823 | }
|
817 | 824 |
|
| 825 | + @Test |
| 826 | + public void testInvalidQueryFilters() { |
| 827 | + CollectionReference collection = testCollection(); |
| 828 | + |
| 829 | + // Multiple inequalities, one of which is inside a nested composite filter. |
| 830 | + String reason = |
| 831 | + "All where filters with an inequality (notEqualTo, notIn, lessThan, lessThanOrEqualTo, greaterThan, or greaterThanOrEqualTo) must be on the same field. But you have filters on 'c' and 'r'"; |
| 832 | + expectError( |
| 833 | + () -> |
| 834 | + collection |
| 835 | + .where( |
| 836 | + or( |
| 837 | + and(equalTo("a", "b"), greaterThan("c", "d")), |
| 838 | + and(equalTo("e", "f"), equalTo("g", "h")))) |
| 839 | + .where(greaterThan("r", "s")), |
| 840 | + reason); |
| 841 | + |
| 842 | + // OrderBy and inequality on different fields. Inequality inside a nested composite filter. |
| 843 | + reason = |
| 844 | + "Invalid query. You have an inequality where filter (whereLessThan(), whereGreaterThan(), etc.) on field 'c' and so you must also have 'c' as your first orderBy() field, but your first orderBy() is currently on field 'r' instead."; |
| 845 | + expectError( |
| 846 | + () -> |
| 847 | + collection |
| 848 | + .where( |
| 849 | + or( |
| 850 | + and(equalTo("a", "b"), greaterThan("c", "d")), |
| 851 | + and(equalTo("e", "f"), equalTo("g", "h")))) |
| 852 | + .orderBy("r"), |
| 853 | + reason); |
| 854 | + |
| 855 | + // Conflicting operations within a composite filter. |
| 856 | + reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters."; |
| 857 | + expectError( |
| 858 | + () -> |
| 859 | + collection.where( |
| 860 | + or( |
| 861 | + and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))), |
| 862 | + and(equalTo("e", "f"), notInArray("c", Arrays.asList("f", "g"))))), |
| 863 | + reason); |
| 864 | + |
| 865 | + // Conflicting operations between a field filter and a composite filter. |
| 866 | + reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters."; |
| 867 | + expectError( |
| 868 | + () -> |
| 869 | + collection |
| 870 | + .where( |
| 871 | + or( |
| 872 | + and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))), |
| 873 | + and(equalTo("e", "f"), equalTo("g", "h")))) |
| 874 | + .where(notInArray("i", Arrays.asList("j", "k"))), |
| 875 | + reason); |
| 876 | + |
| 877 | + // Conflicting operations between two composite filters. |
| 878 | + reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters."; |
| 879 | + expectError( |
| 880 | + () -> |
| 881 | + collection |
| 882 | + .where( |
| 883 | + or( |
| 884 | + and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))), |
| 885 | + and(equalTo("e", "f"), equalTo("g", "h")))) |
| 886 | + .where( |
| 887 | + or( |
| 888 | + and(equalTo("i", "j"), notInArray("l", Arrays.asList("m", "n"))), |
| 889 | + and(equalTo("o", "p"), equalTo("q", "r")))), |
| 890 | + reason); |
| 891 | + } |
| 892 | + |
818 | 893 | // Helpers
|
819 | 894 |
|
820 | 895 | /** Performs a write using each write API and makes sure it succeeds. */
|
|
0 commit comments