2015-07-15 19:01:23 +03:00
|
|
|
var sinon = require('sinon'),
|
|
|
|
should = require('should'),
|
|
|
|
|
|
|
|
express = require('express'),
|
|
|
|
staticTheme = require('../../../server/middleware/static-theme');
|
|
|
|
|
|
|
|
describe('staticTheme', function () {
|
|
|
|
var next;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
next = sinon.spy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call next if hbs file type', function () {
|
|
|
|
var req = {
|
2016-02-16 21:28:43 +03:00
|
|
|
path: 'mytemplate.hbs'
|
2015-07-15 19:01:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
staticTheme(null)(req, null, next);
|
2016-02-08 00:27:01 +03:00
|
|
|
next.called.should.be.true();
|
2015-07-15 19:01:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call next if md file type', function () {
|
|
|
|
var req = {
|
2016-02-16 21:28:43 +03:00
|
|
|
path: 'README.md'
|
2015-07-15 19:01:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
staticTheme(null)(req, null, next);
|
2016-02-08 00:27:01 +03:00
|
|
|
next.called.should.be.true();
|
2015-07-15 19:01:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call next if json file type', function () {
|
|
|
|
var req = {
|
2016-02-16 21:28:43 +03:00
|
|
|
path: 'sample.json'
|
2015-07-15 19:01:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
staticTheme(null)(req, null, next);
|
2016-02-08 00:27:01 +03:00
|
|
|
next.called.should.be.true();
|
2015-07-15 19:01:23 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call express.static if valid file type', function (done) {
|
|
|
|
var req = {
|
2016-02-16 21:28:43 +03:00
|
|
|
path: 'myvalidfile.css',
|
2015-09-28 13:22:55 +03:00
|
|
|
app: {
|
|
|
|
get: function () { return 'casper'; }
|
|
|
|
}
|
2015-07-15 19:01:23 +03:00
|
|
|
},
|
2015-09-28 13:22:55 +03:00
|
|
|
activeThemeStub,
|
2015-07-15 19:01:23 +03:00
|
|
|
sandbox = sinon.sandbox.create(),
|
|
|
|
expressStatic = sinon.spy(express, 'static');
|
|
|
|
|
2015-09-28 13:22:55 +03:00
|
|
|
activeThemeStub = sandbox.spy(req.app, 'get');
|
2015-07-15 19:01:23 +03:00
|
|
|
|
|
|
|
staticTheme(null)(req, null, function (reqArg, res, next2) {
|
|
|
|
/*jshint unused:false */
|
|
|
|
sandbox.restore();
|
2016-02-08 00:27:01 +03:00
|
|
|
next.called.should.be.false();
|
|
|
|
activeThemeStub.called.should.be.true();
|
|
|
|
expressStatic.called.should.be.true();
|
|
|
|
should.exist(expressStatic.args[0][1].maxAge);
|
2015-07-15 19:01:23 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-01-23 23:34:11 +03:00
|
|
|
|
|
|
|
it('should not error if active theme is missing', function (done) {
|
|
|
|
var req = {
|
2016-02-16 21:28:43 +03:00
|
|
|
path: 'myvalidfile.css',
|
2016-01-23 23:34:11 +03:00
|
|
|
app: {
|
|
|
|
get: function () { return undefined; }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
activeThemeStub,
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
activeThemeStub = sandbox.spy(req.app, 'get');
|
|
|
|
|
|
|
|
staticTheme(null)(req, null, function (reqArg, res, next2) {
|
|
|
|
/*jshint unused:false */
|
|
|
|
sandbox.restore();
|
2016-02-08 00:27:01 +03:00
|
|
|
next.called.should.be.false();
|
2016-01-23 23:34:11 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-06-29 23:44:01 +03:00
|
|
|
|
|
|
|
it('should not call next if file is on whitelist', function (done) {
|
|
|
|
var req = {
|
|
|
|
path: 'manifest.json',
|
|
|
|
app: {
|
|
|
|
get: function () { return 'casper'; }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
activeThemeStub,
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
activeThemeStub = sandbox.spy(req.app, 'get');
|
|
|
|
|
|
|
|
staticTheme(null)(req, null, function (reqArg, res, next2) {
|
|
|
|
/*jshint unused:false */
|
|
|
|
sandbox.restore();
|
|
|
|
next.called.should.be.false();
|
|
|
|
activeThemeStub.called.should.be.true();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-07-15 19:01:23 +03:00
|
|
|
});
|