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