Ghost/core/test/unit/middleware/static-theme_spec.js
Hannah Wolfe 390d5fcea2 Remove unnecessary API lookup for activeTheme
- the active theme is already managed and kept up to date as a property
of the express app
- this can be accessed via `req.app` inside of middleware
2015-09-29 22:54:55 +02:00

69 lines
1.8 KiB
JavaScript

/*globals describe, it, beforeEach */
/*jshint expr:true*/
var sinon = require('sinon'),
should = require('should'),
express = require('express'),
staticTheme = require('../../../server/middleware/static-theme');
should.equal(true, true);
describe('staticTheme', function () {
var next;
beforeEach(function () {
next = sinon.spy();
});
it('should call next if hbs file type', function () {
var req = {
url: 'mytemplate.hbs'
};
staticTheme(null)(req, null, next);
next.called.should.be.true;
});
it('should call next if md file type', function () {
var req = {
url: 'README.md'
};
staticTheme(null)(req, null, next);
next.called.should.be.true;
});
it('should call next if json file type', function () {
var req = {
url: 'sample.json'
};
staticTheme(null)(req, null, next);
next.called.should.be.true;
});
it('should call express.static if valid file type', function (done) {
var req = {
url: 'myvalidfile.css',
app: {
get: function () { return 'casper'; }
}
},
activeThemeStub,
sandbox = sinon.sandbox.create(),
expressStatic = sinon.spy(express, 'static');
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;
expressStatic.called.should.be.true;
expressStatic.args[0][1].maxAge.should.exist;
done();
});
});
});