UNPKG

2.19 kBJavaScriptView Raw
1var assert = require ('assert');
2var web_routes = require ('../lib/webapp/routes.js');
3var path = require ('path');
4
5function hasRoute(app, route){
6 return app.routes.get.filter(function(item){return item.path === route;}).length;
7}
8
9describe ('routes', function(){
10
11 it('has the necessary routes', function(done){
12 var app = require('express')();
13 var configPath = path.join(process.cwd(), 'test', 'fixtures', 'config','valid-config.json');
14 var config = require('../lib/config-manager')(configPath);
15 web_routes(app, null, null, config);
16 assert.ok(hasRoute(app, "/"));
17 assert.ok(hasRoute(app, "/:dashboard"));
18 assert.ok(hasRoute(app, "/:dashboard/js"));
19 assert.ok(hasRoute(app, "/widgets/:widget"));
20 assert.ok(hasRoute(app, "/widgets/:widget/js"));
21 assert.ok(hasRoute(app, "/log"));
22 done();
23 });
24
25 describe ('/log route', function(){
26
27 it('should return error if live logging is not enabled', function(done){
28 var app = require('express')();
29 var configPath = path.join(process.cwd(), 'test', 'fixtures', 'config','log-disabled.json');
30 var config = require('../lib/config-manager')(configPath);
31 web_routes(app, null, null, config);
32
33 var logRoute = app.routes.get.filter(function(item){return item.path === '/log';})[0];
34 var res = { end: function (msg){
35 assert.ok(msg.indexOf('live logging it disabled')>-1);
36 done();
37 }};
38 logRoute.callbacks[0]({}, res);
39 });
40
41 it('should render view if live logging is enabled', function(done){
42 var app = require('express')();
43 var configPath = path.join(process.cwd(), 'test', 'fixtures', 'config','log-enabled.json');
44 var config = require('../lib/config-manager')(configPath);
45 web_routes(app, null, null, config);
46
47 var logRoute = app.routes.get.filter(function(item){return item.path === '/log';})[0];
48 var viewPath = path.join(__dirname, "../", "templates", "dashboard-log.ejs");
49 var res = { render: function (view){
50 assert.equal(viewPath, view);
51 done();
52 }};
53 logRoute.callbacks[0]({}, res);
54 });
55
56 });
57});
\No newline at end of file