Skip to content

MIEQ: add negative test cases #5383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitForException;
import static com.google.firebase.firestore.testutil.TestUtil.expectError;
import static com.google.firebase.firestore.testutil.TestUtil.map;
import static java.util.Arrays.asList;
Expand Down Expand Up @@ -2193,4 +2194,45 @@ public void testMultipleInequalityFromCacheAndFromServer() {
Query query5 = collection.where(or(greaterThan("a", 2), lessThan("b", 1)));
checkOnlineAndOfflineResultsMatch(query5, "doc1", "doc3");
}

@Test
public void testMultipleInequalityRejectsIfDocumentKeyIsNotTheLastOrderByField() {
// TODO(MIEQ): Enable this test against production when possible.
assumeTrue(
"Skip this test if running against production because multiple inequality is "
+ "not supported yet.",
isRunningAgainstEmulator());

CollectionReference collection = testCollection();

// Implicitly ordered by: __name__ asc, 'key' asc,
Query query = collection.whereNotEqualTo("key", 42).orderBy(FieldPath.documentId());
Exception e = waitForException(query.get());
FirebaseFirestoreException firestoreException = (FirebaseFirestoreException) e;
assertTrue(
firestoreException
.getMessage()
.contains("order by clause cannot contain more fields after the key"));
}

@Test
public void testMultipleInequalityRejectsIfDocumentKeyAppearsOnlyInEqualityFilter() {
// TODO(MIEQ): Enable this test against production when possible.
assumeTrue(
"Skip this test if running against production because multiple inequality is "
+ "not supported yet.",
isRunningAgainstEmulator());

CollectionReference collection = testCollection();

Query query =
collection.whereNotEqualTo("key", 42).whereEqualTo(FieldPath.documentId(), "doc1");
Exception e = waitForException(query.get());
FirebaseFirestoreException firestoreException = (FirebaseFirestoreException) e;
assertTrue(
firestoreException
.getMessage()
.contains(
"Equality on key is not allowed if there are other inequality fields and key does not appear in inequalities."));
}
}