mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
22e13acd65
- All var declarations are now const or let as per ES6 - All comma-separated lists / chained declarations are now one declaration per line - This is for clarity/readability but also made running the var-to-const/let switch smoother - ESLint rules updated to match How this was done: - npm install -g jscodeshift - git clone https://github.com/cpojer/js-codemod.git - git clone git@github.com:TryGhost/Ghost.git shallow-ghost - cd shallow-ghost - jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2 - jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2 - yarn - yarn test - yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode - grunt test-regression - sorted!
64 lines
2 KiB
JavaScript
64 lines
2 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
|
|
// Thing we are testing
|
|
const redirectAdminUrls = require('../../../../core/server/web/admin/middleware')[0];
|
|
|
|
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();
|
|
});
|
|
});
|
|
});
|
|
});
|