Skip to content

Commit 554ad41

Browse files
authored
Change some tests to validate against message prefix only (#8839)
1 parent 62827f3 commit 554ad41

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Firestore/Example/Tests/Integration/API/FIRValidationTests.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,9 @@ - (void)testQueriesFilteredByDocumentIdMustUseStringsOrDocumentReferences {
556556
[collection queryWhereFieldPath:[FIRFieldPath documentID] isEqualTo:@"foo/bar/baz"], reason);
557557

558558
reason = @"Invalid query. When querying by document ID you must provide a valid string or "
559-
"DocumentReference, but it was of type: __NSCFNumber";
560-
FSTAssertThrows([collection queryWhereFieldPath:[FIRFieldPath documentID] isEqualTo:@1], reason);
559+
"DocumentReference, but it was of type:";
560+
FSTAssertExceptionPrefix([collection queryWhereFieldPath:[FIRFieldPath documentID] isEqualTo:@1],
561+
reason);
561562

562563
reason = @"Invalid query. When querying a collection group by document ID, the value "
563564
"provided must result in a valid document path, but 'foo/bar/baz' is not because it "
@@ -586,9 +587,10 @@ - (void)testQueriesUsingInAndDocumentIdMustHaveProperDocumentReferencesInArray {
586587
reason);
587588

588589
reason = @"Invalid query. When querying by document ID you must provide a valid string or "
589-
"DocumentReference, but it was of type: __NSArrayI";
590+
"DocumentReference, but it was of type:";
590591
NSArray *value = @[ @1, @2 ];
591-
FSTAssertThrows([collection queryWhereFieldPath:[FIRFieldPath documentID] in:value], reason);
592+
FSTAssertExceptionPrefix([collection queryWhereFieldPath:[FIRFieldPath documentID] in:value],
593+
reason);
592594

593595
reason = @"Invalid query. When querying a collection group by document ID, the value "
594596
"provided must result in a valid document path, but 'foo' is not because it "

Firestore/Example/Tests/Util/FSTHelpers.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ inline NSString *FSTRemoveExceptionPrefix(NSString *exception) {
6767
}
6868
}
6969

70+
inline NSString *FSTTakeMessagePrefix(NSString *exception, NSInteger length) {
71+
return [exception substringToIndex:length];
72+
}
73+
7074
// Helper for validating API exceptions.
7175
#define FSTAssertThrows(expression, exceptionReason, ...) \
7276
do { \
@@ -81,6 +85,23 @@ inline NSString *FSTRemoveExceptionPrefix(NSString *exception) {
8185
XCTAssertTrue(didThrow, ##__VA_ARGS__); \
8286
} while (0)
8387

88+
// Helper for validating API exceptions.
89+
#define FSTAssertExceptionPrefix(expression, prefix, ...) \
90+
do { \
91+
BOOL didThrow = NO; \
92+
@try { \
93+
(void)(expression); \
94+
} @catch (NSException * exception) { \
95+
didThrow = YES; \
96+
NSString *expectedMessage = FSTRemoveExceptionPrefix(prefix); \
97+
NSString *actualMessage = FSTRemoveExceptionPrefix(exception.reason); \
98+
NSInteger length = expectedMessage.length; \
99+
XCTAssertEqualObjects(FSTTakeMessagePrefix(actualMessage, length), \
100+
FSTTakeMessagePrefix(expectedMessage, length)); \
101+
} \
102+
XCTAssertTrue(didThrow, ##__VA_ARGS__); \
103+
} while (0)
104+
84105
/** Creates a new NSDate from components. Note that year, month, and day are all one-based. */
85106
NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int second);
86107

0 commit comments

Comments
 (0)