mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
closes #6448 -upgraded should.js to the latest version (8.2.1) -Changed the tests so that they comply with the breaking changes introduced in the new version of should.js -Installs the package should-http so should.be.json() can be used -Installs the package should-sinon so that should.be.calledOnce() can be used
88 lines
2.4 KiB
JavaScript
88 lines
2.4 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();
|
|
should.exist(expressStatic.args[0][1].maxAge);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should not error if active theme is missing', function (done) {
|
|
var req = {
|
|
url: 'myvalidfile.css',
|
|
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();
|
|
next.called.should.be.false();
|
|
done();
|
|
});
|
|
});
|
|
});
|