mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
7bcccc71dc
refs #9178 - move express apps to one place (called `web`) - requires https://github.com/TryGhost/Ghost-Admin/pull/923 - any further improvements are not part of this PR - this PR just moves the files and ensures the paths are up-to-date
64 lines
2 KiB
JavaScript
64 lines
2 KiB
JavaScript
var should = require('should'), // jshint ignore:line
|
|
sinon = require('sinon'),
|
|
|
|
// Thing we are testing
|
|
redirectAdminUrls = require('../../server/web/admin/middleware')[0],
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
describe('Admin App', function () {
|
|
afterEach(function () {
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe('middleware', function () {
|
|
describe('redirectAdminUrls', function () {
|
|
var req, res, next;
|
|
// Input: req.originalUrl
|
|
// Output: either next or res.redirect are called
|
|
beforeEach(function () {
|
|
req = {};
|
|
res = {};
|
|
next = sandbox.stub();
|
|
res.redirect = sandbox.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();
|
|
});
|
|
});
|
|
});
|
|
});
|