-
Notifications
You must be signed in to change notification settings - Fork 601
/
query.exec.js
103 lines (83 loc) · 2.4 KB
/
query.exec.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var Waterline = require('../../../lib/waterline'),
assert = require('assert'),
async = require('async');
describe('Collection Query', function() {
describe('.exec()', function() {
var query;
before(function(done) {
var waterline = new Waterline();
var Model = Waterline.Collection.extend({
identity: 'user',
connection: 'foo',
attributes: {
name: {
type: 'string',
defaultsTo: 'Foo Bar'
},
doSomething: function() {}
}
});
waterline.loadCollection(Model);
// Fixture Adapter Def
var adapterDef = {
find: function(con, col, criteria, cb) {
return cb(null, [criteria]);
}
};
var connections = {
'foo': {
adapter: 'foobar'
}
};
waterline.initialize({ adapters: { foobar: adapterDef }, connections: connections }, function(err, colls) {
if (err) return done(err);
query = colls.collections.user;
done();
});
});
it('should work the same with .exec() as it does with a callback', function(done) {
// .exec() usage
query.find()
.exec(function(err, results0) {
assert(!err);
// callback usage
query.find(function (err, results1) {
assert(!err);
assert(results0.length === results1.length);
});
done();
});
});
describe('when passed a switchback (object with multiple handlers)', function () {
before(function getTheQueryResultsForTestsBelow(done) {
var self = this;
async.auto({
objUsage: function (cb) {
query.find()
.exec({
success: function (results) {
cb(null, results);
},
error: cb
});
},
cbUsage: function (cb) {
query.find().exec(cb);
}
}, function asyncComplete (err, async_data) {
// Save results for use below
self._error = err;
self._results = async_data;
done();
});
});
it('should not fail', function() {
assert(this._results);
assert(!this._error);
});
it('should work the same as it does with a callback', function() {
assert(this._results.cbUsage.length === this._results.objUsage.length);
});
});
});
});