Skip to content

Commit 785492b

Browse files
committed
Add test for querySubscribe with
1 parent 1c43f69 commit 785492b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/query.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var expect = require('expect.js');
22
var async = require('async');
3+
var Backend = require('sharedb').Backend;
34

45
// Call this function inside a `describe` block. Assumes that
56
// `this.db` is set to be a ShareDB instance that supports certain
@@ -28,6 +29,29 @@ module.exports = function() {
2829
});
2930
});
3031

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+
3155
it('$sort, $skip and $limit should order, skip and limit', function(done) {
3256
var snapshots = [
3357
{type: 'json0', v: 1, data: {x: 1}, id: "test1"},

0 commit comments

Comments
 (0)