@@ -1093,4 +1093,45 @@ - (void)testPerformsAverageOnlyOnNumericFields {
1093
1093
[[NSNumber numberWithDouble: 5 ] doubleValue ]);
1094
1094
}
1095
1095
1096
+ - (void )testFailWithMessageWithConsoleLinkIfMissingIndex {
1097
+ XCTSkipIf ([FSTIntegrationTestCase isRunningAgainstEmulator ],
1098
+ " Skip this test when running against the Firestore emulator because the Firestore "
1099
+ " emulator does not use indexes and never fails with a 'missing index' error." );
1100
+
1101
+ FIRCollectionReference* testCollection = [self collectionRef ];
1102
+ FIRQuery* compositeIndexQuery = [[testCollection queryWhereField: @" field1"
1103
+ isEqualTo: @42 ] queryWhereField: @" field2"
1104
+ isLessThan: @99 ];
1105
+ FIRAggregateQuery* compositeIndexAggregateQuery = [compositeIndexQuery aggregate: @[
1106
+ [FIRAggregateField aggregateFieldForCount ],
1107
+ [FIRAggregateField aggregateFieldForSumOfField: @" pages" ],
1108
+ [FIRAggregateField aggregateFieldForAverageOfField: @" pages" ]
1109
+ ]];
1110
+
1111
+ XCTestExpectation* queryCompletion = [self expectationWithDescription: @" query" ];
1112
+ [compositeIndexAggregateQuery
1113
+ aggregationWithSource: FIRAggregateSourceServer
1114
+ completion: ^(FIRAggregateQuerySnapshot* snapshot, NSError * error) {
1115
+ XCTAssertNotNil (error);
1116
+ if (error) {
1117
+ NSString * errorDescription = [error localizedDescription ];
1118
+ XCTAssertTrue ([errorDescription.lowercaseString containsString: @" index" ],
1119
+ " The NSError should have contained the word 'index' "
1120
+ " (case-insensitive), but got: %@" ,
1121
+ errorDescription);
1122
+ // TODO(b/316359394) Remove this check for the default databases once
1123
+ // cl/582465034 is rolled out to production.
1124
+ if ([[FSTIntegrationTestCase databaseID ] isEqualToString: @" (default)" ]) {
1125
+ XCTAssertTrue (
1126
+ [errorDescription containsString: @" https://console.firebase.google.com" ],
1127
+ " The NSError should have contained the string "
1128
+ " 'https://console.firebase.google.com', but got: %@" ,
1129
+ errorDescription);
1130
+ }
1131
+ }
1132
+ XCTAssertNil (snapshot);
1133
+ [queryCompletion fulfill ];
1134
+ }];
1135
+ [self awaitExpectations ];
1136
+ }
1096
1137
@end
0 commit comments