From f64dd14d465b05f85f463d6d13de229ec797ef10 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 2 Nov 2018 15:45:33 -0700 Subject: [PATCH] Validate that at least one argument is provided for Cursor --- dev/src/reference.ts | 16 ++++++++-------- dev/test/query.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dev/src/reference.ts b/dev/src/reference.ts index b2c950759..2d1b25f0d 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -1355,9 +1355,9 @@ export class Query { */ startAt(...fieldValuesOrDocumentSnapshot: Array): Query { - const options = extend(true, {}, this._queryOptions); + this._validator.minNumberOfArguments('startAt', arguments, 1); - fieldValuesOrDocumentSnapshot = [].slice.call(arguments); + const options = extend(true, {}, this._queryOptions); const fieldOrders = this.createImplicitOrderBy(fieldValuesOrDocumentSnapshot); @@ -1390,9 +1390,9 @@ export class Query { */ startAfter(...fieldValuesOrDocumentSnapshot: Array): Query { - const options = extend(true, {}, this._queryOptions); + this._validator.minNumberOfArguments('startAfter', arguments, 1); - fieldValuesOrDocumentSnapshot = [].slice.call(arguments); + const options = extend(true, {}, this._queryOptions); const fieldOrders = this.createImplicitOrderBy(fieldValuesOrDocumentSnapshot); @@ -1424,9 +1424,9 @@ export class Query { */ endBefore(...fieldValuesOrDocumentSnapshot: Array): Query { - const options = extend(true, {}, this._queryOptions); + this._validator.minNumberOfArguments('endBefore', arguments, 1); - fieldValuesOrDocumentSnapshot = [].slice.call(arguments); + const options = extend(true, {}, this._queryOptions); const fieldOrders = this.createImplicitOrderBy(fieldValuesOrDocumentSnapshot); @@ -1458,9 +1458,9 @@ export class Query { */ endAt(...fieldValuesOrDocumentSnapshot: Array): Query { - const options = extend(true, {}, this._queryOptions); + this._validator.minNumberOfArguments('endAt', arguments, 1); - fieldValuesOrDocumentSnapshot = [].slice.call(arguments); + const options = extend(true, {}, this._queryOptions); const fieldOrders = this.createImplicitOrderBy(fieldValuesOrDocumentSnapshot); diff --git a/dev/test/query.ts b/dev/test/query.ts index fa086bbe2..43d277a62 100644 --- a/dev/test/query.ts +++ b/dev/test/query.ts @@ -1228,6 +1228,14 @@ describe('startAt() interface', () => { /Only a direct child can be used as a query boundary. Found: 'coll\/doc\/coll\/doc\/coll'./); }); + it('requires at least one value', () => { + const query = firestore.collection('coll/doc/coll'); + + expect(() => { + query.startAt(); + }).to.throw(/Function 'startAt\(\)' requires at least 1 argument./); + }); + it('can specify document snapshot', () => { const overrides = { runQuery: (request) => {