@@ -36,90 +36,86 @@ import {
3636 withTestCollection ,
3737 withTestDb
3838} from '../util/helpers' ;
39- import { USE_EMULATOR } from '../util/settings' ;
4039
41- ( USE_EMULATOR ? apiDescribe : apiDescribe . skip ) (
42- 'Count quries' ,
43- ( persistence : boolean ) => {
44- it ( 'can run count query getCountFromServer' , ( ) => {
45- const testDocs = {
46- a : { author : 'authorA' , title : 'titleA' } ,
47- b : { author : 'authorB' , title : 'titleB' }
48- } ;
49- return withTestCollection ( persistence , testDocs , async coll => {
50- const snapshot = await getCountFromServer ( coll ) ;
51- expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
52- } ) ;
40+ apiDescribe ( 'Count quries' , ( persistence : boolean ) => {
41+ it ( 'can run count query getCountFromServer' , ( ) => {
42+ const testDocs = {
43+ a : { author : 'authorA' , title : 'titleA' } ,
44+ b : { author : 'authorB' , title : 'titleB' }
45+ } ;
46+ return withTestCollection ( persistence , testDocs , async coll => {
47+ const snapshot = await getCountFromServer ( coll ) ;
48+ expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
5349 } ) ;
50+ } ) ;
5451
55- it ( "count query doesn't use converter" , ( ) => {
56- const testDocs = {
57- a : { author : 'authorA' , title : 'titleA' } ,
58- b : { author : 'authorB' , title : 'titleB' }
59- } ;
60- const throwingConverter = {
61- toFirestore ( obj : never ) : DocumentData {
62- throw new Error ( 'should never be called' ) ;
63- } ,
64- fromFirestore ( snapshot : QueryDocumentSnapshot ) : never {
65- throw new Error ( 'should never be called' ) ;
66- }
67- } ;
68- return withTestCollection ( persistence , testDocs , async coll => {
69- const query_ = query (
70- coll ,
71- where ( 'author' , '==' , 'authorA' )
72- ) . withConverter ( throwingConverter ) ;
73- const snapshot = await getCountFromServer ( query_ ) ;
74- expect ( snapshot . data ( ) . count ) . to . equal ( 1 ) ;
75- } ) ;
52+ it ( "count query doesn't use converter" , ( ) => {
53+ const testDocs = {
54+ a : { author : 'authorA' , title : 'titleA' } ,
55+ b : { author : 'authorB' , title : 'titleB' }
56+ } ;
57+ const throwingConverter = {
58+ toFirestore ( obj : never ) : DocumentData {
59+ throw new Error ( 'should never be called' ) ;
60+ } ,
61+ fromFirestore ( snapshot : QueryDocumentSnapshot ) : never {
62+ throw new Error ( 'should never be called' ) ;
63+ }
64+ } ;
65+ return withTestCollection ( persistence , testDocs , async coll => {
66+ const query_ = query (
67+ coll ,
68+ where ( 'author' , '==' , 'authorA' )
69+ ) . withConverter ( throwingConverter ) ;
70+ const snapshot = await getCountFromServer ( query_ ) ;
71+ expect ( snapshot . data ( ) . count ) . to . equal ( 1 ) ;
7672 } ) ;
73+ } ) ;
7774
78- it ( 'count query supports collection groups' , ( ) => {
79- return withTestDb ( persistence , async db => {
80- const collectionGroupId = doc ( collection ( db , 'aggregateQueryTest' ) ) . id ;
81- const docPaths = [
82- `${ collectionGroupId } /cg-doc1` ,
83- `abc/123/${ collectionGroupId } /cg-doc2` ,
84- `zzz${ collectionGroupId } /cg-doc3` ,
85- `abc/123/zzz${ collectionGroupId } /cg-doc4` ,
86- `abc/123/zzz/${ collectionGroupId } `
87- ] ;
88- const batch = writeBatch ( db ) ;
89- for ( const docPath of docPaths ) {
90- batch . set ( doc ( db , docPath ) , { x : 1 } ) ;
91- }
92- await batch . commit ( ) ;
93- const snapshot = await getCountFromServer (
94- collectionGroup ( db , collectionGroupId )
95- ) ;
96- expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
97- } ) ;
75+ it ( 'count query supports collection groups' , ( ) => {
76+ return withTestDb ( persistence , async db => {
77+ const collectionGroupId = doc ( collection ( db , 'aggregateQueryTest' ) ) . id ;
78+ const docPaths = [
79+ `${ collectionGroupId } /cg-doc1` ,
80+ `abc/123/${ collectionGroupId } /cg-doc2` ,
81+ `zzz${ collectionGroupId } /cg-doc3` ,
82+ `abc/123/zzz${ collectionGroupId } /cg-doc4` ,
83+ `abc/123/zzz/${ collectionGroupId } `
84+ ] ;
85+ const batch = writeBatch ( db ) ;
86+ for ( const docPath of docPaths ) {
87+ batch . set ( doc ( db , docPath ) , { x : 1 } ) ;
88+ }
89+ await batch . commit ( ) ;
90+ const snapshot = await getCountFromServer (
91+ collectionGroup ( db , collectionGroupId )
92+ ) ;
93+ expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
9894 } ) ;
95+ } ) ;
9996
100- it ( 'getCountFromServer fails if firestore is terminated' , ( ) => {
101- return withEmptyTestCollection ( persistence , async ( coll , firestore ) => {
102- await terminate ( firestore ) ;
103- expect ( ( ) => getCountFromServer ( coll ) ) . to . throw (
104- 'The client has already been terminated.'
105- ) ;
106- } ) ;
97+ it ( 'getCountFromServer fails if firestore is terminated' , ( ) => {
98+ return withEmptyTestCollection ( persistence , async ( coll , firestore ) => {
99+ await terminate ( firestore ) ;
100+ expect ( ( ) => getCountFromServer ( coll ) ) . to . throw (
101+ 'The client has already been terminated.'
102+ ) ;
107103 } ) ;
104+ } ) ;
108105
109- it ( "terminate doesn't crash when there is count query in flight" , ( ) => {
110- return withEmptyTestCollection ( persistence , async ( coll , firestore ) => {
111- void getCountFromServer ( coll ) ;
112- await terminate ( firestore ) ;
113- } ) ;
106+ it ( "terminate doesn't crash when there is count query in flight" , ( ) => {
107+ return withEmptyTestCollection ( persistence , async ( coll , firestore ) => {
108+ void getCountFromServer ( coll ) ;
109+ await terminate ( firestore ) ;
114110 } ) ;
111+ } ) ;
115112
116- it ( 'getCountFromServer fails if user is offline' , ( ) => {
117- return withEmptyTestCollection ( persistence , async ( coll , firestore ) => {
118- await disableNetwork ( firestore ) ;
119- await expect ( getCountFromServer ( coll ) ) . to . be . eventually . rejectedWith (
120- 'Failed to get count result because the client is offline'
121- ) ;
122- } ) ;
113+ it ( 'getCountFromServer fails if user is offline' , ( ) => {
114+ return withEmptyTestCollection ( persistence , async ( coll , firestore ) => {
115+ await disableNetwork ( firestore ) ;
116+ await expect ( getCountFromServer ( coll ) ) . to . be . eventually . rejectedWith (
117+ 'Failed to get count result because the client is offline'
118+ ) ;
123119 } ) ;
124- }
125- ) ;
120+ } ) ;
121+ } ) ;
0 commit comments