Skip to content

Commit c9849a0

Browse files
unify error
1 parent 113883e commit c9849a0

File tree

2 files changed

+28
-58
lines changed

2 files changed

+28
-58
lines changed

packages/firestore/test/integration/api/validation.test.ts

Lines changed: 27 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { ALT_PROJECT_ID, DEFAULT_PROJECT_ID } from '../util/settings';
3131
const FieldPath = firebaseExport.FieldPath;
3232
const FieldValue = firebaseExport.FieldValue;
3333
const newTestFirestore = firebaseExport.newTestFirestore;
34-
const usesFunctionalApi = firebaseExport.usesFunctionalApi;
3534

3635
// We're using 'as any' to pass invalid values to APIs for testing purposes.
3736
/* eslint-disable @typescript-eslint/no-explicit-any */
@@ -117,24 +116,14 @@ apiDescribe('Validation:', (persistence: boolean) => {
117116
persistence,
118117
'disallows changing settings after use',
119118
async db => {
120-
let errorMsg =
121-
'Firestore has already been started and its settings can no ' +
122-
'longer be changed. ';
123-
124-
if (usesFunctionalApi()) {
125-
errorMsg +=
126-
'initializeFirestore() cannot be called after calling ' +
127-
'getFirestore()';
128-
} else {
129-
errorMsg +=
130-
'You can only modify settings before calling any other ' +
131-
'methods on a Firestore object.';
132-
}
133-
134119
await db.doc('foo/bar').set({});
135120
expect(() =>
136121
db.settings({ host: 'something-else.example.com' })
137-
).to.throw(errorMsg);
122+
).to.throw(
123+
'Firestore has already been started and its settings can no ' +
124+
'longer be changed. You can only modify settings before calling any other ' +
125+
'methods on a Firestore object.'
126+
);
138127
}
139128
);
140129

@@ -661,10 +650,9 @@ apiDescribe('Validation:', (persistence: boolean) => {
661650
expect(() =>
662651
collection.where('test', '==', { test: FieldValue.increment(1) })
663652
).to.throw(
664-
`Function ${
665-
usesFunctionalApi() ? 'where' : 'Query.where'
666-
}() called with invalid data. FieldValue.increment() can only be ` +
667-
'used with update() and set() (found in field test)'
653+
'Function Query.where() called with invalid data. ' +
654+
'FieldValue.increment() can only be used with update() and set() ' +
655+
'(found in field test)'
668656
);
669657
});
670658
});
@@ -673,14 +661,10 @@ apiDescribe('Validation:', (persistence: boolean) => {
673661
validationIt(persistence, 'with non-positive limit fail', db => {
674662
const collection = db.collection('test');
675663
expect(() => collection.limit(0)).to.throw(
676-
`Function ${
677-
usesFunctionalApi() ? 'limit' : 'Query.limit'
678-
}() requires a positive number, but it was: 0.`
664+
`Function Query.limit() requires a positive number, but it was: 0.`
679665
);
680666
expect(() => collection.limitToLast(-1)).to.throw(
681-
`Function ${
682-
usesFunctionalApi() ? 'limitToLast' : 'Query.limitToLast'
683-
}() requires a positive number, but it was: -1.`
667+
`Function Query.limitToLast() requires a positive number, but it was: -1.`
684668
);
685669
});
686670

@@ -771,10 +755,9 @@ apiDescribe('Validation:', (persistence: boolean) => {
771755
const collection = db.collection('collection');
772756
const query = collection.orderBy('foo');
773757
const reason =
774-
`Too many arguments provided to ${
775-
usesFunctionalApi() ? 'startAt' : 'Query.startAt'
776-
}(). The number of arguments must be less than or equal to the ` +
777-
`number of orderBy() clauses`;
758+
'Too many arguments provided to Query.startAt(). The number of ' +
759+
'arguments must be less than or equal to the number of orderBy() ' +
760+
'clauses';
778761
expect(() => query.startAt(1, 2)).to.throw(reason);
779762
expect(() => query.orderBy('bar').startAt(1, 2, 3)).to.throw(reason);
780763
}
@@ -792,22 +775,18 @@ apiDescribe('Validation:', (persistence: boolean) => {
792775
.orderBy(FieldPath.documentId());
793776
expect(() => query.startAt(1)).to.throw(
794777
'Invalid query. Expected a string for document ID in ' +
795-
`${
796-
usesFunctionalApi() ? 'startAt' : 'Query.startAt'
797-
}(), but got a number`
778+
'Query.startAt(), but got a number'
798779
);
799780
expect(() => query.startAt('foo/bar')).to.throw(
800-
`Invalid query. When querying a collection and ordering by FieldPath.documentId(), ` +
801-
`the value passed to ${
802-
usesFunctionalApi() ? 'startAt' : 'Query.startAt'
803-
}() must be a plain document ID, but 'foo/bar' contains a slash.`
781+
'Invalid query. When querying a collection and ordering by FieldPath.documentId(), ' +
782+
'the value passed to Query.startAt() must be a plain document ID, ' +
783+
"but 'foo/bar' contains a slash."
804784
);
805785
expect(() => cgQuery.startAt('foo')).to.throw(
806-
`Invalid query. When querying a collection group and ordering by ` +
807-
`FieldPath.documentId(), the value passed to ${
808-
usesFunctionalApi() ? 'startAt' : 'Query.startAt'
809-
}() must result in a valid document path, but 'foo' is not because ` +
810-
`it contains an odd number of segments.`
786+
'Invalid query. When querying a collection group and ordering by ' +
787+
'FieldPath.documentId(), the value passed to Query.startAt() ' +
788+
"must result in a valid document path, but 'foo' is not because " +
789+
'it contains an odd number of segments.'
811790
);
812791
}
813792
);
@@ -1287,21 +1266,12 @@ apiDescribe('Validation:', (persistence: boolean) => {
12871266

12881267
validationIt(persistence, 'cannot pass undefined as a field value', db => {
12891268
const collection = db.collection('test');
1290-
if (usesFunctionalApi()) {
1291-
expect(() => collection.where('foo', '==', undefined)).to.throw(
1292-
'Function where() called with invalid data. Unsupported field value: undefined'
1293-
);
1294-
expect(() => collection.orderBy('foo').startAt(undefined)).to.throw(
1295-
'Function startAt() called with invalid data. Unsupported field value: undefined'
1296-
);
1297-
} else {
1298-
expect(() => collection.where('foo', '==', undefined)).to.throw(
1299-
'Function Query.where() called with invalid data. Unsupported field value: undefined'
1300-
);
1301-
expect(() => collection.orderBy('foo').startAt(undefined)).to.throw(
1302-
'Function Query.startAt() called with invalid data. Unsupported field value: undefined'
1303-
);
1304-
}
1269+
expect(() => collection.where('foo', '==', undefined)).to.throw(
1270+
'Function Query.where() called with invalid data. Unsupported field value: undefined'
1271+
);
1272+
expect(() => collection.orderBy('foo').startAt(undefined)).to.throw(
1273+
'Function Query.startAt() called with invalid data. Unsupported field value: undefined'
1274+
);
13051275
});
13061276
});
13071277
});

packages/firestore/test/integration/util/firebase_export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { getFirestore } from '../../../exp/src/api/database';
4646
* Firestore API. Used to exclude some tests, e.g. those that validate invalid
4747
* TypeScript input.
4848
*/
49-
export function usesFunctionalApi(): boolean {
49+
function usesFunctionalApi(): boolean {
5050
// Use the firebase namespace to detect if `firebase.firestore` has been
5151
// registered, which is only registered in the classic version of Firestore.
5252
return !('firestore' in firebase);

0 commit comments

Comments
 (0)