Skip to content

Commit 50fae3c

Browse files
authored
Firestore: Add test that verifies count query error message when missing index (#4232)
1 parent aafdd1e commit 50fae3c

File tree

1 file changed

+24
-0
lines changed
  • firebase-firestore/src/androidTest/java/com/google/firebase/firestore

1 file changed

+24
-0
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/CountTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.firestore;
1616

17+
import static com.google.common.truth.Truth.assertThat;
1718
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection;
1819
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
1920
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
@@ -25,10 +26,14 @@
2526
import static org.junit.Assert.assertEquals;
2627
import static org.junit.Assert.assertFalse;
2728
import static org.junit.Assert.assertNotEquals;
29+
import static org.junit.Assert.assertThrows;
2830
import static org.junit.Assert.assertTrue;
31+
import static org.junit.Assume.assumeFalse;
2932

3033
import androidx.test.ext.junit.runners.AndroidJUnit4;
34+
import com.google.android.gms.tasks.Task;
3135
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
36+
import java.util.Collections;
3237
import org.junit.After;
3338
import org.junit.Test;
3439
import org.junit.runner.RunWith;
@@ -253,4 +258,23 @@ public void testFailWithoutNetwork() {
253258
AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
254259
assertEquals(3L, snapshot.getCount());
255260
}
261+
262+
@Test
263+
public void testFailWithGoodMessageIfMissingIndex() {
264+
assumeFalse(
265+
"Skip this test when running against the Firestore emulator because the Firestore emulator "
266+
+ "does not use indexes and never fails with a 'missing index' error",
267+
BuildConfig.USE_EMULATOR_FOR_TESTS);
268+
269+
CollectionReference collection = testCollectionWithDocs(Collections.emptyMap());
270+
Query compositeIndexQuery = collection.whereEqualTo("field1", 42).whereLessThan("field2", 99);
271+
AggregateQuery compositeIndexCountQuery = compositeIndexQuery.count();
272+
Task<AggregateQuerySnapshot> task = compositeIndexCountQuery.get(AggregateSource.SERVER);
273+
274+
Throwable throwable = assertThrows(Throwable.class, () -> waitFor(task));
275+
276+
Throwable cause = throwable.getCause();
277+
assertThat(cause).hasMessageThat().ignoringCase().contains("index");
278+
assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com");
279+
}
256280
}

0 commit comments

Comments
 (0)