|
1 | 1 | var expect = require('expect.js');
|
2 | 2 | var async = require('async');
|
| 3 | +var Backend = require('sharedb').Backend; |
3 | 4 |
|
4 | 5 | // Call this function inside a `describe` block. Assumes that
|
5 | 6 | // `this.db` is set to be a ShareDB instance that supports certain
|
@@ -28,6 +29,29 @@ module.exports = function() {
|
28 | 29 | });
|
29 | 30 | });
|
30 | 31 |
|
| 32 | + it('$count with createSubscribeQuery', function(done) { |
| 33 | + var connection = new Backend({db: this.db}) .connect(); |
| 34 | + async.parallel([ |
| 35 | + function(cb) { connection.get('testcollection', 'test1').create({x: 1, y: 1}, cb); }, |
| 36 | + function(cb) { connection.get('testcollection', 'test2').create({x: 2, y: 2}, cb); }, |
| 37 | + function(cb) { connection.get('testcollection', 'test3').create({x: 3, y: 2}, cb); } |
| 38 | + ], function(err) { |
| 39 | + var query = {$count: true, y: 2}; |
| 40 | + if (err) return done(err); |
| 41 | + var query = connection.createSubscribeQuery('testcollection', query, null, function(err, results, extra) { |
| 42 | + if (err) return done(err); |
| 43 | + |
| 44 | + expect(results).eql([]); |
| 45 | + expect(extra).eql(2); |
| 46 | + connection.get('testcollection', 'test3').submitOp({p: ['y'], na: 1}); |
| 47 | + }); |
| 48 | + query.on('extra', function(extra) { |
| 49 | + expect(extra).eql(1); |
| 50 | + done(); |
| 51 | + }); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
31 | 55 | it('$sort, $skip and $limit should order, skip and limit', function(done) {
|
32 | 56 | var snapshots = [
|
33 | 57 | {type: 'json0', v: 1, data: {x: 1}, id: "test1"},
|
|
0 commit comments