mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
621cfd9866
- moving this middleware because we're about to add a second piece of middleware - it's easier to see what we have when each middleware is in its own file rather than in one big middleware.js file
65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
|
|
// Thing we are testing
|
|
const redirectAdminUrls = require('../../../../../core/server/web/admin/middleware/redirect-admin-urls');
|
|
|
|
describe('Admin App', function () {
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
describe('middleware', function () {
|
|
describe('redirectAdminUrls', function () {
|
|
let req;
|
|
let res;
|
|
let next;
|
|
// Input: req.originalUrl
|
|
// Output: either next or res.redirect are called
|
|
beforeEach(function () {
|
|
req = {};
|
|
res = {};
|
|
next = sinon.stub();
|
|
res.redirect = sinon.stub();
|
|
});
|
|
|
|
it('should redirect a url which starts with ghost', function () {
|
|
req.originalUrl = '/ghost/x';
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
next.called.should.be.false();
|
|
res.redirect.called.should.be.true();
|
|
res.redirect.calledWith('/ghost/#/x').should.be.true();
|
|
});
|
|
|
|
it('should not redirect /ghost/ on its owh', function () {
|
|
req.originalUrl = '/ghost/';
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
next.called.should.be.true();
|
|
res.redirect.called.should.be.false();
|
|
});
|
|
|
|
it('should not redirect url that has no slash', function () {
|
|
req.originalUrl = 'ghost/x';
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
next.called.should.be.true();
|
|
res.redirect.called.should.be.false();
|
|
});
|
|
|
|
it('should not redirect url that starts with something other than /ghost/', function () {
|
|
req.originalUrl = 'x/ghost/x';
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
next.called.should.be.true();
|
|
res.redirect.called.should.be.false();
|
|
});
|
|
});
|
|
});
|
|
});
|