-
Notifications
You must be signed in to change notification settings - Fork 55
/
streaming.js
72 lines (59 loc) · 1.67 KB
/
streaming.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
65
66
67
68
69
var utils = require('utilities')
, assert = require('assert')
, config = require('../../config')
, model = require('../../../lib')
, tests;
tests = {
'test all, data event for each row': function (next) {
var processor
, incr = 0;
processor = model.Person.all();
processor.on('data', function (item) {
incr++;
});
processor.on('end', function () {
assert.equal(20, incr);
next();
});
}
, 'test all, no callback when none passed': function (next) {
var processor
, incr = 0;
processor = model.Person.all();
assert.ok(!processor.callback);
next();
}
, 'test all, data events in order': function (next) {
var processor
, incr = 0
, letters = 'abcdefghijklmnopqrst'.split('');
processor = model.Person.all({}, {sort: 'title'});
processor.on('data', function (item) {
assert.equal(letters[incr], item.title);
incr++;
});
processor.on('end', next);
}
, 'test all, error event': function (next) {
var processor
, adapter = model.Person.adapter
, origExec
, methodName = adapter.name == 'sqlite' ?
'all' : 'exec';
// Temporarily punch out the exec method to run a
// query with bad SQL, produce an error
origExec = adapter[methodName];
adapter[methodName] = function () {
arguments[0] = 'asdf' + arguments[0];
return origExec.apply(adapter, arguments);
};
processor = model.Person.all();
processor.on('error', function (err) {
// Important: Put the exec method back where it was
adapter[methodName] = origExec;
assert.ok(err);
next();
});
}
};
module.exports = tests;