Skip to content

Commit 2ea6f7d

Browse files
Fix Tests
1 parent 29b40d4 commit 2ea6f7d

File tree

5 files changed

+13
-36
lines changed

5 files changed

+13
-36
lines changed

packages/firestore/exp/test/shim.ts

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader';
6767
import { isPartialObserver, PartialObserver } from '../../src/api/observer';
6868
import { isPlainObject } from '../../src/util/input_validation';
6969
import { Compat } from '../../src/compat/compat';
70+
import { validateSetOptions } from '../../src/api/database';
7071

7172
export { GeoPoint, Timestamp } from '../index';
7273
export { FieldValue } from '../../src/compat/field_value';
@@ -189,6 +190,7 @@ export class Transaction
189190
options?: legacy.SetOptions
190191
): Transaction {
191192
if (options) {
193+
validateSetOptions('Transaction.set', options);
192194
this._delegate.set(documentRef._delegate, unwrap(data), options);
193195
} else {
194196
this._delegate.set(documentRef._delegate, unwrap(data));
@@ -241,6 +243,7 @@ export class WriteBatch
241243
options?: legacy.SetOptions
242244
): WriteBatch {
243245
if (options) {
246+
validateSetOptions('WriteBatch.set', options);
244247
this._delegate.set(documentRef._delegate, unwrap(data), options);
245248
} else {
246249
this._delegate.set(documentRef._delegate, unwrap(data));
@@ -320,6 +323,7 @@ export class DocumentReference<T = legacy.DocumentData>
320323

321324
set(data: Partial<T>, options?: legacy.SetOptions): Promise<void> {
322325
if (options) {
326+
validateSetOptions('DocumentReference.set', options);
323327
return setDoc(this._delegate, unwrap(data), options);
324328
} else {
325329
return setDoc(this._delegate, unwrap(data));

packages/firestore/lite/src/api/reference.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class QueryLimitConstraint extends QueryConstraint {
409409
* @return The created `Query`.
410410
*/
411411
export function limit(limit: number): QueryConstraint {
412-
validatePositiveNumber('limit', 1, limit);
412+
validatePositiveNumber('limit', limit);
413413
return new QueryLimitConstraint('limit', limit, LimitType.First);
414414
}
415415

@@ -423,7 +423,7 @@ export function limit(limit: number): QueryConstraint {
423423
* @return The created `Query`.
424424
*/
425425
export function limitToLast(limit: number): QueryConstraint {
426-
validatePositiveNumber('limitToLast', 1, limit);
426+
validatePositiveNumber('limitToLast', limit);
427427
return new QueryLimitConstraint('limitToLast', limit, LimitType.Last);
428428
}
429429

packages/firestore/src/api/database.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ export class Query<T = DocumentData> implements PublicQuery<T> {
18371837
}
18381838

18391839
limit(n: number): PublicQuery<T> {
1840-
validatePositiveNumber('Query.limit', 1, n);
1840+
validatePositiveNumber('Query.limit', n);
18411841
return new Query(
18421842
queryWithLimit(this._query, n, LimitType.First),
18431843
this.firestore,
@@ -1846,7 +1846,7 @@ export class Query<T = DocumentData> implements PublicQuery<T> {
18461846
}
18471847

18481848
limitToLast(n: number): PublicQuery<T> {
1849-
validatePositiveNumber('Query.limitToLast', 1, n);
1849+
validatePositiveNumber('Query.limitToLast', n);
18501850
return new Query(
18511851
queryWithLimit(this._query, n, LimitType.Last),
18521852
this.firestore,
@@ -2231,7 +2231,7 @@ export class CollectionReference<T = DocumentData>
22312231
}
22322232
}
22332233

2234-
function validateSetOptions(
2234+
export function validateSetOptions(
22352235
methodName: string,
22362236
options: SetOptions | undefined
22372237
): SetOptions {

packages/firestore/src/util/input_validation.ts

+2-29
Original file line numberDiff line numberDiff line change
@@ -170,38 +170,11 @@ export function cast<T>(
170170
return obj as T;
171171
}
172172

173-
export function validatePositiveNumber(
174-
functionName: string,
175-
position: number,
176-
n: number
177-
): void {
173+
export function validatePositiveNumber(functionName: string, n: number): void {
178174
if (n <= 0) {
179175
throw new FirestoreError(
180176
Code.INVALID_ARGUMENT,
181-
`Function ${functionName}() requires its ${ordinal(
182-
position
183-
)} argument to be a positive number, but it was: ${n}.`
177+
`Function ${functionName}() requires a positive number, but it was: ${n}.`
184178
);
185179
}
186180
}
187-
188-
/** Converts a number to its english word representation */
189-
function ordinal(num: number): string {
190-
switch (num) {
191-
case 1:
192-
return 'first';
193-
case 2:
194-
return 'second';
195-
case 3:
196-
return 'third';
197-
default:
198-
return num + 'th';
199-
}
200-
}
201-
202-
/**
203-
* Formats the given word as plural conditionally given the preceding number.
204-
*/
205-
function formatPlural(num: number, str: string): string {
206-
return `${num} ${str}` + (num === 1 ? '' : 's');
207-
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,12 @@ apiDescribe('Validation:', (persistence: boolean) => {
684684
expect(() => collection.limit(0)).to.throw(
685685
`Function ${
686686
usesFunctionalApi() ? 'limit' : 'Query.limit'
687-
}() requires its first argument to be a positive number, but it was: 0.`
687+
}() requires a positive number, but it was: 0.`
688688
);
689689
expect(() => collection.limitToLast(-1)).to.throw(
690690
`Function ${
691691
usesFunctionalApi() ? 'limitToLast' : 'Query.limitToLast'
692-
}() requires its first argument to be a positive number, but it was: -1.`
692+
}() requires a positive number, but it was: -1.`
693693
);
694694
});
695695

0 commit comments

Comments
 (0)