Skip to content

Commit 981e6f1

Browse files
authored
create sample count test cases (#6506)
1 parent 7f42490 commit 981e6f1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { expect } from 'chai';
19+
import {
20+
countQuery,
21+
getAggregateFromServerDirect,
22+
query
23+
} from '../util/firebase_export';
24+
import { apiDescribe, withTestCollection } from '../util/helpers';
25+
26+
apiDescribe('Aggregation COUNT query:', (persistence: boolean) => {
27+
it('empty collection count equals to 0', () => {
28+
const testDocs = {};
29+
return withTestCollection(persistence, testDocs, collection => {
30+
const countQuery_ = countQuery(query(collection));
31+
return getAggregateFromServerDirect(countQuery_).then(snapshot => {
32+
expect(snapshot.getCount()).to.equal(0);
33+
});
34+
});
35+
});
36+
37+
it('test collection count equals to 6', () => {
38+
const testDocs = {
39+
a: { k: 'a' },
40+
b: { k: 'b' },
41+
c: { k: 'c' },
42+
d: { k: 'd' },
43+
e: { k: 'e' },
44+
f: { k: 'f' }
45+
};
46+
return withTestCollection(persistence, testDocs, collection => {
47+
const countQuery_ = countQuery(query(collection));
48+
return getAggregateFromServerDirect(countQuery_).then(snapshot => {
49+
expect(snapshot.getCount()).to.equal(6);
50+
});
51+
});
52+
});
53+
});

0 commit comments

Comments
 (0)