mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 09:52:09 +03:00
254e0f0597
close #2757, refs #5286 - moves error formatting from api/index into errors lib - moves error handling from api/index into its own middleware - adds extra middleware for method not allowed which captures all unsupported routes
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
/*globals describe, beforeEach, afterEach, it*/
|
|
/*jshint expr:true*/
|
|
var should = require('should'),
|
|
sinon = require('sinon'),
|
|
decideIsAdmin = require('../../../server/middleware/decide-is-admin');
|
|
|
|
// To stop jshint complaining
|
|
should.equal(true, true);
|
|
|
|
describe('Middleware: decideIsAdmin', function () {
|
|
var sandbox,
|
|
res,
|
|
req,
|
|
next;
|
|
|
|
beforeEach(function () {
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
next = sinon.spy();
|
|
res = sinon.spy();
|
|
req = {};
|
|
});
|
|
|
|
afterEach(function () {
|
|
sandbox.restore();
|
|
});
|
|
|
|
it('sets the isAdmin flag if the url contains /ghost/.', function (done) {
|
|
var trueUrls = [
|
|
'/ghost/',
|
|
'/ghost/foo?bar=foo'
|
|
],
|
|
falseUrls = [
|
|
'/ghost',
|
|
'ghost/',
|
|
'/foobar/ghost',
|
|
'/things/ghost/foo'
|
|
];
|
|
|
|
trueUrls.forEach(function (url) {
|
|
res = sinon.spy();
|
|
next = sinon.spy();
|
|
req.url = url;
|
|
|
|
decideIsAdmin(req, res, next);
|
|
res.isAdmin.should.be.exactly(true);
|
|
next.calledOnce.should.be.exactly(true);
|
|
});
|
|
|
|
falseUrls.forEach(function (url) {
|
|
res = sinon.spy();
|
|
next = sinon.spy();
|
|
req.url = url;
|
|
|
|
decideIsAdmin(req, res, next);
|
|
res.isAdmin.should.be.exactly(false);
|
|
next.calledOnce.should.be.exactly(true);
|
|
});
|
|
|
|
done();
|
|
});
|
|
});
|