This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
/
follow.js
64 lines (58 loc) · 1.83 KB
/
follow.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var specify = require('specify')
, async = require('async')
, helpers = require('../helpers')
, timeout = helpers.timeout
, nano = helpers.nano
, nock = helpers.nock
;
var mock = nock(helpers.couch, "db/follow")
, db = nano.use("db_follow")
, feed
;
specify("db_follow:setup", timeout, function (assert) {
nano.db.create("db_follow", function (err) {
assert.equal(err, undefined, "Failed to create database");
async.parallel(
[ function(cb) { db.insert({"foo": "bar"}, "foobar", cb); }
, function(cb) { db.insert({"bar": "foo"}, "barfoo", cb); }
, function(cb) { db.insert({"foo": "baz"}, "foobaz", cb); }
]
, function(error, results){
assert.equal(error, undefined, "Should have stored docs");
});
});
});
if(!process.env.NOCK) {
// nock doesn support streaming
// please run tests with local couchdb
specify("db_follow:stream", timeout, function (assert) {
assert.expect(2);
feed = db.follow({since: 3});
var i = 3;
feed.on('change', function (change) {
assert.ok(change, "Change existed");
assert.equal(change.seq, i+1, "Seq is set correctly");
++i;
});
feed.follow();
process.nextTick(function () {
db.insert({"bar": "baz"}, "barbaz");
});
});
specify("db_follow:callback", timeout, function (assert) {
db.follow({since: 3}, function (error, change) {
assert.equal(error, undefined, "No errors happened");
assert.ok(change, "Change existed");
});
});
}
specify("db_follow:teardown", timeout, function (assert) {
if (feed && typeof feed.stop === "function") {
feed.stop();
}
nano.db.destroy("db_follow", function (err) {
assert.equal(err, undefined, "Failed to destroy database");
assert.ok(mock.isDone(), "Some mocks didn't run");
});
});
specify.run(process.argv.slice(2));