diff --git a/packages/firestore/test/integration/api/aggregation.test.ts b/packages/firestore/test/integration/api/aggregation.test.ts index 0c0e9db0b15..ad590451e17 100644 --- a/packages/firestore/test/integration/api/aggregation.test.ts +++ b/packages/firestore/test/integration/api/aggregation.test.ts @@ -36,90 +36,86 @@ import { withTestCollection, withTestDb } from '../util/helpers'; -import { USE_EMULATOR } from '../util/settings'; -(USE_EMULATOR ? apiDescribe : apiDescribe.skip)( - 'Count quries', - (persistence: boolean) => { - it('can run count query getCountFromServer', () => { - const testDocs = { - a: { author: 'authorA', title: 'titleA' }, - b: { author: 'authorB', title: 'titleB' } - }; - return withTestCollection(persistence, testDocs, async coll => { - const snapshot = await getCountFromServer(coll); - expect(snapshot.data().count).to.equal(2); - }); +apiDescribe('Count quries', (persistence: boolean) => { + it('can run count query getCountFromServer', () => { + const testDocs = { + a: { author: 'authorA', title: 'titleA' }, + b: { author: 'authorB', title: 'titleB' } + }; + return withTestCollection(persistence, testDocs, async coll => { + const snapshot = await getCountFromServer(coll); + expect(snapshot.data().count).to.equal(2); }); + }); - it("count query doesn't use converter", () => { - const testDocs = { - a: { author: 'authorA', title: 'titleA' }, - b: { author: 'authorB', title: 'titleB' } - }; - const throwingConverter = { - toFirestore(obj: never): DocumentData { - throw new Error('should never be called'); - }, - fromFirestore(snapshot: QueryDocumentSnapshot): never { - throw new Error('should never be called'); - } - }; - return withTestCollection(persistence, testDocs, async coll => { - const query_ = query( - coll, - where('author', '==', 'authorA') - ).withConverter(throwingConverter); - const snapshot = await getCountFromServer(query_); - expect(snapshot.data().count).to.equal(1); - }); + it("count query doesn't use converter", () => { + const testDocs = { + a: { author: 'authorA', title: 'titleA' }, + b: { author: 'authorB', title: 'titleB' } + }; + const throwingConverter = { + toFirestore(obj: never): DocumentData { + throw new Error('should never be called'); + }, + fromFirestore(snapshot: QueryDocumentSnapshot): never { + throw new Error('should never be called'); + } + }; + return withTestCollection(persistence, testDocs, async coll => { + const query_ = query( + coll, + where('author', '==', 'authorA') + ).withConverter(throwingConverter); + const snapshot = await getCountFromServer(query_); + expect(snapshot.data().count).to.equal(1); }); + }); - it('count query supports collection groups', () => { - return withTestDb(persistence, async db => { - const collectionGroupId = doc(collection(db, 'aggregateQueryTest')).id; - const docPaths = [ - `${collectionGroupId}/cg-doc1`, - `abc/123/${collectionGroupId}/cg-doc2`, - `zzz${collectionGroupId}/cg-doc3`, - `abc/123/zzz${collectionGroupId}/cg-doc4`, - `abc/123/zzz/${collectionGroupId}` - ]; - const batch = writeBatch(db); - for (const docPath of docPaths) { - batch.set(doc(db, docPath), { x: 1 }); - } - await batch.commit(); - const snapshot = await getCountFromServer( - collectionGroup(db, collectionGroupId) - ); - expect(snapshot.data().count).to.equal(2); - }); + it('count query supports collection groups', () => { + return withTestDb(persistence, async db => { + const collectionGroupId = doc(collection(db, 'aggregateQueryTest')).id; + const docPaths = [ + `${collectionGroupId}/cg-doc1`, + `abc/123/${collectionGroupId}/cg-doc2`, + `zzz${collectionGroupId}/cg-doc3`, + `abc/123/zzz${collectionGroupId}/cg-doc4`, + `abc/123/zzz/${collectionGroupId}` + ]; + const batch = writeBatch(db); + for (const docPath of docPaths) { + batch.set(doc(db, docPath), { x: 1 }); + } + await batch.commit(); + const snapshot = await getCountFromServer( + collectionGroup(db, collectionGroupId) + ); + expect(snapshot.data().count).to.equal(2); }); + }); - it('getCountFromServer fails if firestore is terminated', () => { - return withEmptyTestCollection(persistence, async (coll, firestore) => { - await terminate(firestore); - expect(() => getCountFromServer(coll)).to.throw( - 'The client has already been terminated.' - ); - }); + it('getCountFromServer fails if firestore is terminated', () => { + return withEmptyTestCollection(persistence, async (coll, firestore) => { + await terminate(firestore); + expect(() => getCountFromServer(coll)).to.throw( + 'The client has already been terminated.' + ); }); + }); - it("terminate doesn't crash when there is count query in flight", () => { - return withEmptyTestCollection(persistence, async (coll, firestore) => { - void getCountFromServer(coll); - await terminate(firestore); - }); + it("terminate doesn't crash when there is count query in flight", () => { + return withEmptyTestCollection(persistence, async (coll, firestore) => { + void getCountFromServer(coll); + await terminate(firestore); }); + }); - it('getCountFromServer fails if user is offline', () => { - return withEmptyTestCollection(persistence, async (coll, firestore) => { - await disableNetwork(firestore); - await expect(getCountFromServer(coll)).to.be.eventually.rejectedWith( - 'Failed to get count result because the client is offline' - ); - }); + it('getCountFromServer fails if user is offline', () => { + return withEmptyTestCollection(persistence, async (coll, firestore) => { + await disableNetwork(firestore); + await expect(getCountFromServer(coll)).to.be.eventually.rejectedWith( + 'Failed to get count result because the client is offline' + ); }); - } -); + }); +}); diff --git a/packages/firestore/test/integration/api_internal/aggregation.test.ts b/packages/firestore/test/integration/api_internal/aggregation.test.ts deleted file mode 100644 index 47a4dbdf860..00000000000 --- a/packages/firestore/test/integration/api_internal/aggregation.test.ts +++ /dev/null @@ -1,122 +0,0 @@ -/** - * @license - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** This file is emporarily staying in api_internal folder till aggregate queries are public. */ -import { expect } from 'chai'; - -import { getCountFromServer } from '../../../src/api/aggregate'; -import { - collection, - collectionGroup, - doc, - disableNetwork, - query, - terminate, - where, - writeBatch, - DocumentData, - QueryDocumentSnapshot -} from '../util/firebase_export'; -import { - apiDescribe, - withEmptyTestCollection, - withTestCollection, - withTestDb -} from '../util/helpers'; - -apiDescribe('Count quries', (persistence: boolean) => { - it('can run count query getCountFromServer', () => { - const testDocs = { - a: { author: 'authorA', title: 'titleA' }, - b: { author: 'authorB', title: 'titleB' } - }; - return withTestCollection(persistence, testDocs, async coll => { - const snapshot = await getCountFromServer(coll); - expect(snapshot.data().count).to.equal(2); - }); - }); - - it("count query doesn't use converter", () => { - const testDocs = { - a: { author: 'authorA', title: 'titleA' }, - b: { author: 'authorB', title: 'titleB' } - }; - const throwingConverter = { - toFirestore(obj: never): DocumentData { - throw new Error('should never be called'); - }, - fromFirestore(snapshot: QueryDocumentSnapshot): never { - throw new Error('should never be called'); - } - }; - return withTestCollection(persistence, testDocs, async coll => { - const query_ = query( - coll, - where('author', '==', 'authorA') - ).withConverter(throwingConverter); - const snapshot = await getCountFromServer(query_); - expect(snapshot.data().count).to.equal(1); - }); - }); - - it('count query supports collection groups', () => { - return withTestDb(persistence, async db => { - const collectionGroupId = doc(collection(db, 'aggregateQueryTest')).id; - const docPaths = [ - `${collectionGroupId}/cg-doc1`, - `abc/123/${collectionGroupId}/cg-doc2`, - `zzz${collectionGroupId}/cg-doc3`, - `abc/123/zzz${collectionGroupId}/cg-doc4`, - `abc/123/zzz/${collectionGroupId}` - ]; - const batch = writeBatch(db); - for (const docPath of docPaths) { - batch.set(doc(db, docPath), { x: 1 }); - } - await batch.commit(); - const snapshot = await getCountFromServer( - collectionGroup(db, collectionGroupId) - ); - expect(snapshot.data().count).to.equal(2); - }); - }); - - it('getCountFromServer fails if firestore is terminated', () => { - return withEmptyTestCollection(persistence, async (coll, firestore) => { - await terminate(firestore); - expect(() => getCountFromServer(coll)).to.throw( - 'The client has already been terminated.' - ); - }); - }); - - it("terminate doesn't crash when there is count query in flight", () => { - return withEmptyTestCollection(persistence, async (coll, firestore) => { - void getCountFromServer(coll); - await terminate(firestore); - }); - }); - - it('getCountFromServer fails if user is offline', () => { - return withEmptyTestCollection(persistence, async (coll, firestore) => { - await disableNetwork(firestore); - await expect(getCountFromServer(coll)).to.be.eventually.rejectedWith( - 'Failed to get count result because the client is offline' - ); - }); - }); -});