Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
/*
2
* dispatch-test.js: Tests for the core dispatch method.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
vows = require('vows'),
11
director = require('../../../lib/director');
12
13
vows.describe('director/cli/dispatch').addBatch({
14
"An instance of director.cli.Router": {
15
topic: function () {
16
var router = new director.cli.Router(),
17
that = this;
18
19
that.matched = {};
20
that.matched['users'] = [];
21
that.matched['apps'] = []
22
23
router.on('users create', function () {
24
that.matched['users'].push('on users create');
25
});
26
27
router.on(/apps (\w+\s\w+)/, function () {
28
assert.equal(arguments.length, 1);
29
that.matched['apps'].push('on apps (\\w+\\s\\w+)');
30
});
31
32
return router;
33
},
34
"should have the correct routing table": function (router) {
35
assert.isObject(router.routes.users);
36
assert.isObject(router.routes.users.create);
37
},
38
"the dispatch() method": {
39
"users create": function (router) {
40
assert.isTrue(router.dispatch('on', 'users create'));
41
assert.equal(this.matched.users[0], 'on users create');
42
},
43
"apps foo bar": function (router) {
44
assert.isTrue(router.dispatch('on', 'apps foo bar'));
45
assert.equal(this.matched['apps'][0], 'on apps (\\w+\\s\\w+)');
46
},
47
"not here": function (router) {
48
assert.isFalse(router.dispatch('on', 'not here'));
49
},
50
"still not here": function (router) {
51
assert.isFalse(router.dispatch('on', 'still not here'));
52
}
53
}
54
}
55
}).export(module);
56
57