@@ -22,7 +22,9 @@ import chaiAsPromised from 'chai-as-promised';
22
22
23
23
import {
24
24
countQuery ,
25
- getAggregateFromServerDirect
25
+ getAggregateFromServerDirect ,
26
+ aggregateQueryEqual ,
27
+ aggregateQuerySnapshotEqual
26
28
} from '../../src/lite-api/aggregate' ;
27
29
import { Bytes } from '../../src/lite-api/bytes' ;
28
30
import {
@@ -2046,16 +2048,28 @@ describe('withConverter() support', () => {
2046
2048
2047
2049
describe ( 'countQuery()' , ( ) => {
2048
2050
const converter = {
2049
- toFirestore ( input : { id : string , content : string } ) : DocumentData {
2050
- return { key : input . id , value :input . content } ;
2051
+ toFirestore ( input : { id : string ; content : string } ) : DocumentData {
2052
+ return { key : input . id , value : input . content } ;
2051
2053
} ,
2052
- fromFirestore ( snapshot : QueryDocumentSnapshot ) : { id : string , content : string } {
2054
+ fromFirestore ( snapshot : QueryDocumentSnapshot ) : {
2055
+ id : string ;
2056
+ content : string ;
2057
+ } {
2053
2058
const data = snapshot . data ( ) ;
2054
- return { content :data . value , id :data . documentId } ;
2059
+ return { content : data . value , id : data . documentId } ;
2055
2060
}
2056
2061
} ;
2057
2062
2058
- it . only ( 'empty collection count equals to 0' , ( ) => {
2063
+ const testDocs = [
2064
+ { key : 'a' , value : 'Adam' } ,
2065
+ { key : 'b' , value : 'Bob' } ,
2066
+ { key : 'c' , value : 'Chris' } ,
2067
+ { key : 'a' , value : 'Anna' } ,
2068
+ { key : 'b' , value : 'Bill' } ,
2069
+ { key : 'c' , value : 'Cooper' }
2070
+ ] ;
2071
+
2072
+ it ( 'empty collection count equals to 0' , ( ) => {
2059
2073
return withTestCollection ( async coll => {
2060
2074
const countQuery_ = countQuery ( query ( coll ) ) ;
2061
2075
expect ( countQuery_ . type ) . to . equal ( 'AggregateQuery' ) ;
@@ -2065,114 +2079,108 @@ describe('countQuery()', () => {
2065
2079
} ) ;
2066
2080
} ) ;
2067
2081
2068
- it . only ( 'test collection count equals to 6' , ( ) => {
2069
- const testDocs = [
2070
- { key : 'a' } ,
2071
- { key : 'b' } ,
2072
- { key : 'c' } ,
2073
- { key : 'd' } ,
2074
- { key : 'e' } ,
2075
- { key : 'f' }
2076
- ] ;
2082
+ it ( 'test collection count equals to 6' , ( ) => {
2077
2083
return withTestCollectionAndInitialData ( testDocs , async collection => {
2078
2084
const countQuery_ = countQuery ( query ( collection ) ) ;
2079
2085
const snapshot = await getAggregateFromServerDirect ( countQuery_ ) ;
2080
2086
expect ( snapshot . getCount ( ) ) . to . equal ( 6 ) ;
2081
2087
} ) ;
2082
2088
} ) ;
2083
2089
2084
- it . only ( 'test collection count with filter' , ( ) => {
2085
- const testDocs = [
2086
- { key : 'a' } ,
2087
- { key : 'b' } ,
2088
- { key : 'c' } ,
2089
- { key : 'a' } ,
2090
- { key : 'b' } ,
2091
- { key : 'c' }
2092
- ] ;
2090
+ it ( 'test collection count with filter' , ( ) => {
2093
2091
return withTestCollectionAndInitialData ( testDocs , async collection => {
2094
- let query_ = query ( collection , where ( 'key' , '==' , 'a' ) ) ;
2092
+ const query_ = query ( collection , where ( 'key' , '==' , 'a' ) ) ;
2095
2093
2096
2094
const countQuery_ = countQuery ( query_ ) ;
2097
2095
const snapshot = await getAggregateFromServerDirect ( countQuery_ ) ;
2098
2096
expect ( snapshot . getCount ( ) ) . to . equal ( 2 ) ;
2099
2097
} ) ;
2100
2098
} ) ;
2101
2099
2102
- it . only ( 'test collection count with filter effected by small limit' , ( ) => {
2103
- const testDocs = [
2104
- { key : 'a' } ,
2105
- { key : 'b' } ,
2106
- { key : 'c' } ,
2107
- { key : 'a' } ,
2108
- { key : 'b' } ,
2109
- { key : 'c' }
2110
- ] ;
2100
+ it ( 'test collection count with filter effected by small limit' , ( ) => {
2111
2101
// limit that is less that the actual count would work like count up_to.
2112
2102
return withTestCollectionAndInitialData ( testDocs , async collection => {
2113
- let query_ = query ( collection , where ( 'key' , '==' , 'a' ) , limit ( 1 ) ) ;
2103
+ const query_ = query ( collection , where ( 'key' , '==' , 'a' ) , limit ( 1 ) ) ;
2114
2104
2115
2105
const countQuery_ = countQuery ( query_ ) ;
2116
2106
const snapshot = await getAggregateFromServerDirect ( countQuery_ ) ;
2117
2107
expect ( snapshot . getCount ( ) ) . to . equal ( 1 ) ;
2118
2108
} ) ;
2119
2109
} ) ;
2120
2110
2121
- it . only ( 'test collection count with filter not effected by large limit' , ( ) => {
2122
- const testDocs = [
2123
- { key : 'a' } ,
2124
- { key : 'b' } ,
2125
- { key : 'c' } ,
2126
- { key : 'a' } ,
2127
- { key : 'b' } ,
2128
- { key : 'c' }
2129
- ] ;
2111
+ it ( 'test collection count with filter not effected by large limit' , ( ) => {
2130
2112
//limit that is larger than actual count wouldn't impact the return value
2131
2113
return withTestCollectionAndInitialData ( testDocs , async collection => {
2132
- let query_ = query ( collection , where ( 'key' , '==' , 'a' ) , limit ( 3 ) ) ;
2114
+ const query_ = query ( collection , where ( 'key' , '==' , 'a' ) , limit ( 3 ) ) ;
2133
2115
2134
2116
const countQuery_ = countQuery ( query_ ) ;
2135
2117
const snapshot = await getAggregateFromServerDirect ( countQuery_ ) ;
2136
2118
expect ( snapshot . getCount ( ) ) . to . equal ( 2 ) ;
2137
2119
} ) ;
2138
2120
} ) ;
2139
2121
2140
- it . only ( 'test collection count with converter on query' , ( ) => {
2141
- const testDocs = [
2142
- { key : 'a' , value :"Adam" } ,
2143
- { key : 'b' , value : "Bob" } ,
2144
- { key : 'c' , value : "Chris" } ,
2145
- { key : 'a' , value :"Anna" } ,
2146
- { key : 'b' , value : "Bill" } ,
2147
- { key : 'c' , value : "Cooper" }
2148
- ] ;
2122
+ it ( 'test collection count with converter on query' , ( ) => {
2149
2123
//testing out the converter impact on the AggregateQuery type
2150
2124
return withTestCollectionAndInitialData ( testDocs , async collection => {
2151
- let query_ = query ( collection , where ( 'key' , '==' , 'a' ) ) . withConverter ( converter ) ;
2125
+ const query_ = query ( collection , where ( 'key' , '==' , 'a' ) ) . withConverter (
2126
+ converter
2127
+ ) ;
2152
2128
2153
2129
const countQuery_ = countQuery ( query_ ) ;
2154
2130
const snapshot = await getAggregateFromServerDirect ( countQuery_ ) ;
2155
2131
expect ( snapshot . getCount ( ) ) . to . equal ( 2 ) ;
2156
2132
} ) ;
2157
2133
} ) ;
2158
2134
2159
- it . only ( 'test collection count with converter on collection' , ( ) => {
2160
- const testDocs = [
2161
- { key : 'a' , value :"Adam" } ,
2162
- { key : 'b' , value : "Bob" } ,
2163
- { key : 'c' , value : "Chris" } ,
2164
- { key : 'a' , value :"Anna" } ,
2165
- { key : 'b' , value : "Bill" } ,
2166
- { key : 'c' , value : "Cooper" }
2167
- ] ;
2135
+ it ( 'test collection count with converter on collection' , ( ) => {
2168
2136
//testing out the converter impact on the AggregateQuery type
2169
2137
return withTestCollectionAndInitialData ( testDocs , async collection => {
2170
2138
const ref = collection . withConverter ( converter ) ;
2171
- let query_ = query ( ref , where ( 'key' , '==' , 'a' ) ) ;
2139
+ const query_ = query ( ref , where ( 'key' , '==' , 'a' ) ) ;
2172
2140
2173
2141
const countQuery_ = countQuery ( query_ ) ;
2174
2142
const snapshot = await getAggregateFromServerDirect ( countQuery_ ) ;
2175
2143
expect ( snapshot . getCount ( ) ) . to . equal ( 2 ) ;
2176
2144
} ) ;
2177
2145
} ) ;
2146
+
2147
+ it ( 'aggregateQueryEqual returns true on same queries' , ( ) => {
2148
+ return withTestCollectionAndInitialData ( testDocs , async collection => {
2149
+ const query_1 = query ( collection , where ( 'key' , '==' , 'a' ) ) ;
2150
+ const query_2 = query ( collection , where ( 'key' , '==' , 'a' ) ) ;
2151
+
2152
+ const countQuery_1 = countQuery ( query_1 ) ;
2153
+ const countQuery_2 = countQuery ( query_2 ) ;
2154
+ expect ( aggregateQueryEqual ( countQuery_1 , countQuery_2 ) ) . to . be . true ;
2155
+ } ) ;
2156
+ } ) ;
2157
+
2158
+ it ( 'aggregateQueryEqual returns false on different queries' , ( ) => {
2159
+ return withTestCollectionAndInitialData ( testDocs , async collection => {
2160
+ const query_1 = query ( collection , where ( 'key' , '==' , 'a' ) ) ;
2161
+ const query_2 = query ( collection , where ( 'key' , '!=' , 'a' ) ) ;
2162
+
2163
+ const countQuery_1 = countQuery ( query_1 ) ;
2164
+ const countQuery_2 = countQuery ( query_2 ) ;
2165
+ expect ( aggregateQueryEqual ( countQuery_1 , countQuery_2 ) ) . to . be . false ;
2166
+ } ) ;
2167
+ } ) ;
2168
+
2169
+ it ( 'aggregateQuerySnapshotEqual returns true on same queries' , ( ) => {
2170
+ return withTestCollectionAndInitialData ( testDocs , async collection => {
2171
+ const query_original = query ( collection , where ( 'key' , '==' , 'a' ) ) ;
2172
+ const query_copy = query ( collection , where ( 'key' , '==' , 'a' ) ) ;
2173
+
2174
+ const countQuery_original_1 = countQuery ( query_original ) ;
2175
+ const countQuery_original_2 = countQuery ( query_original ) ;
2176
+ const countQuery_copy = countQuery ( query_copy ) ;
2177
+
2178
+ const snapshot_original_1 = await getAggregateFromServerDirect ( countQuery_original_1 ) ;
2179
+ const snapshot_original_2 = await getAggregateFromServerDirect ( countQuery_original_2 ) ;
2180
+ const snapshot_copy = await getAggregateFromServerDirect ( countQuery_copy ) ;
2181
+
2182
+ expect ( aggregateQuerySnapshotEqual ( snapshot_original_1 , snapshot_original_2 ) ) . to . be . true ;
2183
+ expect ( aggregateQuerySnapshotEqual ( snapshot_original_1 , snapshot_copy ) ) . to . be . true ;
2184
+ } ) ;
2185
+ } ) ;
2178
2186
} ) ;
0 commit comments