forked from meteorhacks/meteor-aggregate
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
41 lines (33 loc) · 1.1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Tinytest.add('method signature', function(test) {
const coll = new Mongo.Collection(Random.id());
test.equal(typeof coll.aggregate, 'function');
});
Tinytest.add("let's aggregate", function(test) {
const coll = new Mongo.Collection(Random.id());
coll.insert({resTime: 20});
coll.insert({resTime: 40});
const result = coll.aggregate([
{$group: {_id: null, resTime: {$sum: "$resTime"}}}
]);
test.equal(result, [{_id: null, resTime: 60}]);
});
Tinytest.add("aggregate on Meteor.users", function(test) {
const coll = Meteor.users;
coll.remove({});
coll.insert({resTime: 20});
coll.insert({resTime: 40});
const result = coll.aggregate([
{$group: {_id: null, resTime: {$sum: "$resTime"}}}
]);
test.equal(result, [{_id: null, resTime: 60}]);
});
Tinytest.add("using some options", function(test) {
const coll = new Mongo.Collection(Random.id());
coll.insert({resTime: 20});
coll.insert({resTime: 40});
const options = {explain: true};
const result = coll.aggregate([
{$group: {_id: null, resTime: {$sum: "$resTime"}}}
], options);
test.equal(typeof result[0], 'object');
});