Skip to content

Commit a2dfb52

Browse files
committed
Firestore: Add test that verifies count query error message when missing index
1 parent 6df2784 commit a2dfb52

File tree

1 file changed

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

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
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;
21+
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.toDataMap;
2022
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
2123
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitForException;
2224
import static com.google.firebase.firestore.testutil.TestUtil.map;
@@ -25,14 +27,21 @@
2527
import static org.junit.Assert.assertEquals;
2628
import static org.junit.Assert.assertFalse;
2729
import static org.junit.Assert.assertNotEquals;
30+
import static org.junit.Assert.assertThrows;
2831
import static org.junit.Assert.assertTrue;
32+
import static org.junit.Assume.assumeFalse;
2933

3034
import androidx.test.ext.junit.runners.AndroidJUnit4;
35+
36+
import com.google.android.gms.tasks.Task;
37+
import com.google.android.gms.tasks.Tasks;
3138
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
3239
import org.junit.After;
3340
import org.junit.Test;
3441
import org.junit.runner.RunWith;
3542

43+
import java.util.Collections;
44+
3645
@RunWith(AndroidJUnit4.class)
3746
public class CountTest {
3847

@@ -253,4 +262,23 @@ public void testFailWithoutNetwork() {
253262
AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
254263
assertEquals(3L, snapshot.getCount());
255264
}
265+
266+
@Test
267+
public void testFailWithGoodMessageIfMissingIndex() {
268+
assumeFalse(
269+
"Skip this test when running against the Firestore emulator because the Firestore emulator "
270+
+ "does not use indexes and never fails with a 'missing index' error",
271+
BuildConfig.USE_EMULATOR_FOR_TESTS);
272+
273+
CollectionReference collection = testCollectionWithDocs(Collections.emptyMap());
274+
Query compositeIndexQuery = collection.whereEqualTo("field1", 42).whereLessThan("field2", 99);
275+
AggregateQuery compositeIndexCountQuery = compositeIndexQuery.count();
276+
Task<AggregateQuerySnapshot> task = compositeIndexCountQuery.get(AggregateSource.SERVER);
277+
278+
Throwable throwable = assertThrows(Throwable.class, () -> waitFor(task));
279+
280+
Throwable cause = throwable.getCause();
281+
assertThat(cause).hasMessageThat().ignoringCase().contains("index");
282+
assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com");
283+
}
256284
}

0 commit comments

Comments
 (0)