@@ -2050,8 +2050,8 @@ describe('countQuery()', () => {
2050
2050
} ) ;
2051
2051
2052
2052
it ( 'run count query on empty test collection' , ( ) => {
2053
- return withTestCollection ( async collection => {
2054
- const snapshot = await getCount ( query ( collection ) ) ;
2053
+ return withTestCollection ( async coll => {
2054
+ const snapshot = await getCount ( coll ) ;
2055
2055
expect ( snapshot . data ( ) . count ) . to . equal ( 0 ) ;
2056
2056
} ) ;
2057
2057
} ) ;
@@ -2062,20 +2062,34 @@ describe('countQuery()', () => {
2062
2062
{ author : 'authorA' , title : 'titleB' } ,
2063
2063
{ author : 'authorB' , title : 'titleC' }
2064
2064
] ;
2065
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2066
- const snapshot = await getCount ( query ( collection ) ) ;
2065
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2066
+ const snapshot = await getCount ( coll ) ;
2067
2067
expect ( snapshot . data ( ) . count ) . to . equal ( 3 ) ;
2068
2068
} ) ;
2069
2069
} ) ;
2070
2070
2071
+ it ( 'run count query fails on invalid collection reference' , ( ) => {
2072
+ return withTestDb ( async db => {
2073
+ const queryForRejection = collection ( db , '__badpath__' ) ;
2074
+
2075
+ try {
2076
+ await getCount ( queryForRejection ) ;
2077
+ } catch ( e ) {
2078
+ expect ( ( e as Error ) ?. message ) . to . equal (
2079
+ 'Request failed with error: Bad Request'
2080
+ ) ;
2081
+ }
2082
+ } ) ;
2083
+ } ) ;
2084
+
2071
2085
it ( 'count query supports filter' , ( ) => {
2072
2086
const testDocs = [
2073
2087
{ author : 'authorA' , title : 'titleA' } ,
2074
2088
{ author : 'authorA' , title : 'titleB' } ,
2075
2089
{ author : 'authorB' , title : 'titleC' }
2076
2090
] ;
2077
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2078
- const query_ = query ( collection , where ( 'author' , '==' , 'authorA' ) ) ;
2091
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2092
+ const query_ = query ( coll , where ( 'author' , '==' , 'authorA' ) ) ;
2079
2093
const snapshot = await getCount ( query_ ) ;
2080
2094
expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
2081
2095
} ) ;
@@ -2087,12 +2101,8 @@ describe('countQuery()', () => {
2087
2101
{ author : 'authorA' , title : 'titleB' } ,
2088
2102
{ author : 'authorB' , title : 'titleC' }
2089
2103
] ;
2090
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2091
- const query_ = query (
2092
- collection ,
2093
- where ( 'author' , '==' , 'authorA' ) ,
2094
- limit ( 1 )
2095
- ) ;
2104
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2105
+ const query_ = query ( coll , where ( 'author' , '==' , 'authorA' ) , limit ( 1 ) ) ;
2096
2106
const snapshot = await getCount ( query_ ) ;
2097
2107
expect ( snapshot . data ( ) . count ) . to . equal ( 1 ) ;
2098
2108
} ) ;
@@ -2104,12 +2114,8 @@ describe('countQuery()', () => {
2104
2114
{ author : 'authorA' , title : 'titleB' } ,
2105
2115
{ author : 'authorB' , title : 'titleC' }
2106
2116
] ;
2107
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2108
- const query_ = query (
2109
- collection ,
2110
- where ( 'author' , '==' , 'authorA' ) ,
2111
- limit ( 3 )
2112
- ) ;
2117
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2118
+ const query_ = query ( coll , where ( 'author' , '==' , 'authorA' ) , limit ( 3 ) ) ;
2113
2119
const snapshot = await getCount ( query_ ) ;
2114
2120
expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
2115
2121
} ) ;
@@ -2122,8 +2128,8 @@ describe('countQuery()', () => {
2122
2128
{ author : 'authorB' , title : null } ,
2123
2129
{ author : 'authorB' }
2124
2130
] ;
2125
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2126
- const query_ = query ( collection , orderBy ( 'title' ) ) ;
2131
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2132
+ const query_ = query ( coll , orderBy ( 'title' ) ) ;
2127
2133
const snapshot = await getCount ( query_ ) ;
2128
2134
expect ( snapshot . data ( ) . count ) . to . equal ( 3 ) ;
2129
2135
} ) ;
@@ -2136,8 +2142,8 @@ describe('countQuery()', () => {
2136
2142
{ id : 2 , author : 'authorB' , title : 'titleC' } ,
2137
2143
{ id : null , author : 'authorB' , title : 'titleD' }
2138
2144
] ;
2139
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2140
- const query_ = query ( collection , orderBy ( 'id' ) , startAt ( 2 ) ) ;
2145
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2146
+ const query_ = query ( coll , orderBy ( 'id' ) , startAt ( 2 ) ) ;
2141
2147
const snapshot = await getCount ( query_ ) ;
2142
2148
expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
2143
2149
} ) ;
@@ -2150,8 +2156,8 @@ describe('countQuery()', () => {
2150
2156
{ id : 2 , author : 'authorB' , title : 'titleC' } ,
2151
2157
{ id : null , author : 'authorB' , title : 'titleD' }
2152
2158
] ;
2153
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2154
- const query_ = query ( collection , orderBy ( 'id' ) , startAfter ( 2 ) ) ;
2159
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2160
+ const query_ = query ( coll , orderBy ( 'id' ) , startAfter ( 2 ) ) ;
2155
2161
const snapshot = await getCount ( query_ ) ;
2156
2162
expect ( snapshot . data ( ) . count ) . to . equal ( 1 ) ;
2157
2163
} ) ;
@@ -2164,8 +2170,8 @@ describe('countQuery()', () => {
2164
2170
{ id : 2 , author : 'authorB' , title : 'titleC' } ,
2165
2171
{ id : null , author : 'authorB' , title : 'titleD' }
2166
2172
] ;
2167
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2168
- const query_ = query ( collection , orderBy ( 'id' ) , startAt ( 1 ) , endAt ( 2 ) ) ;
2173
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2174
+ const query_ = query ( coll , orderBy ( 'id' ) , startAt ( 1 ) , endAt ( 2 ) ) ;
2169
2175
const snapshot = await getCount ( query_ ) ;
2170
2176
expect ( snapshot . data ( ) . count ) . to . equal ( 2 ) ;
2171
2177
} ) ;
@@ -2178,8 +2184,8 @@ describe('countQuery()', () => {
2178
2184
{ id : 2 , author : 'authorB' , title : 'titleC' } ,
2179
2185
{ id : null , author : 'authorB' , title : 'titleD' }
2180
2186
] ;
2181
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2182
- const query_ = query ( collection , orderBy ( 'id' ) , startAt ( 1 ) , endBefore ( 2 ) ) ;
2187
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2188
+ const query_ = query ( coll , orderBy ( 'id' ) , startAt ( 1 ) , endBefore ( 2 ) ) ;
2183
2189
const snapshot = await getCount ( query_ ) ;
2184
2190
expect ( snapshot . data ( ) . count ) . to . equal ( 1 ) ;
2185
2191
} ) ;
@@ -2191,9 +2197,9 @@ describe('countQuery()', () => {
2191
2197
{ author : 'authorA' , title : 'titleB' } ,
2192
2198
{ author : 'authorB' , title : 'titleC' }
2193
2199
] ;
2194
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2200
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2195
2201
const query_ = query (
2196
- collection ,
2202
+ coll ,
2197
2203
where ( 'author' , '==' , 'authorA' )
2198
2204
) . withConverter ( postConverter ) ;
2199
2205
const snapshot = await getCount ( query_ ) ;
@@ -2223,15 +2229,15 @@ describe('countQuery()', () => {
2223
2229
} ) ;
2224
2230
} ) ;
2225
2231
2226
- it ( 'aggregateSnapshotEqual on same queries' , ( ) => {
2232
+ it ( 'aggregateSnapshotEqual on same queries be truthy ' , ( ) => {
2227
2233
const testDocs = [
2228
2234
{ author : 'authorA' , title : 'titleA' } ,
2229
2235
{ author : 'authorA' , title : 'titleB' } ,
2230
2236
{ author : 'authorB' , title : 'titleC' }
2231
2237
] ;
2232
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2233
- const query1 = query ( collection , where ( 'author' , '==' , 'authorA' ) ) ;
2234
- const query2 = query ( collection , where ( 'author' , '==' , 'authorA' ) ) ;
2238
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2239
+ const query1 = query ( coll , where ( 'author' , '==' , 'authorA' ) ) ;
2240
+ const query2 = query ( coll , where ( 'author' , '==' , 'authorA' ) ) ;
2235
2241
const snapshot1A = await getCount ( query1 ) ;
2236
2242
const snapshot1B = await getCount ( query1 ) ;
2237
2243
const snapshot2 = await getCount ( query2 ) ;
@@ -2240,26 +2246,26 @@ describe('countQuery()', () => {
2240
2246
} ) ;
2241
2247
} ) ;
2242
2248
2243
- it ( 'aggregateSnapshotEqual on different queries' , ( ) => {
2249
+ it ( 'aggregateSnapshotEqual on different queries be falsy ' , ( ) => {
2244
2250
const testDocs = [
2245
2251
{ author : 'authorA' , title : 'titleA' } ,
2246
2252
{ author : 'authorA' , title : 'titleB' } ,
2247
2253
{ author : 'authorB' , title : 'titleC' } ,
2248
2254
{ author : 'authorB' , title : 'titleD' }
2249
2255
] ;
2250
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2251
- const query1 = query ( collection , where ( 'author' , '==' , 'authorA' ) ) ;
2252
- const query2 = query ( collection , where ( 'author' , '==' , 'authorB' ) ) ;
2256
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2257
+ const query1 = query ( coll , where ( 'author' , '==' , 'authorA' ) ) ;
2258
+ const query2 = query ( coll , where ( 'author' , '==' , 'authorB' ) ) ;
2253
2259
const snapshot1 = await getCount ( query1 ) ;
2254
2260
const snapshot2 = await getCount ( query2 ) ;
2255
2261
expect ( aggregateSnapshotEqual ( snapshot1 , snapshot2 ) ) . to . be . false ;
2256
2262
} ) ;
2257
2263
} ) ;
2258
2264
2259
2265
it ( 'count query fails on a terminated Firestore' , ( ) => {
2260
- return withTestCollection ( async collection => {
2261
- await terminate ( collection . firestore ) ;
2262
- expect ( ( ) => getCount ( query ( collection ) ) ) . to . throw (
2266
+ return withTestCollection ( async coll => {
2267
+ await terminate ( coll . firestore ) ;
2268
+ expect ( ( ) => getCount ( coll ) ) . to . throw (
2263
2269
'The client has already been terminated.'
2264
2270
) ;
2265
2271
} ) ;
@@ -2271,9 +2277,9 @@ describe('countQuery()', () => {
2271
2277
{ author : 'authorA' , title : 'titleB' } ,
2272
2278
{ author : 'authorB' , title : 'titleC' }
2273
2279
] ;
2274
- return withTestCollectionAndInitialData ( testDocs , async collection => {
2275
- const promise = getCount ( query ( collection ) ) ;
2276
- await terminate ( collection . firestore ) ;
2280
+ return withTestCollectionAndInitialData ( testDocs , async coll => {
2281
+ const promise = getCount ( coll ) ;
2282
+ await terminate ( coll . firestore ) ;
2277
2283
const snapshot = await promise ;
2278
2284
expect ( snapshot . data ( ) . count ) . to . equal ( 3 ) ;
2279
2285
} ) ;
0 commit comments