0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/test/unit/services/routing/middlewares/page-param_spec.js
Hannah Wolfe 22e13acd65 Updated var declarations to const/let and no lists
- 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!
2020-04-29 16:51:13 +01:00

78 lines
2.4 KiB
JavaScript

const should = require('should');
const sinon = require('sinon');
const common = require('../../../../../core/server/lib/common');
const urlUtils = require('../../../../../core/server/lib/url-utils');
const middlewares = require('../../../../../core/frontend/services/routing/middlewares');
describe('UNIT: services/routing/middlewares/page-param', function () {
let req;
let res;
let next;
beforeEach(function () {
req = sinon.stub();
req.params = {};
res = sinon.stub();
next = sinon.stub();
sinon.stub(urlUtils, 'redirect301');
});
afterEach(function () {
sinon.restore();
});
it('success', function () {
req.originalUrl = 'http://localhost:2368/blog/page/2/';
req.url = '/blog/page/2/';
middlewares.pageParam(req, res, next, 2);
urlUtils.redirect301.called.should.be.false();
next.calledOnce.should.be.true();
req.params.page.should.eql(2);
});
it('redirect for /page/1/', function () {
req.originalUrl = 'http://localhost:2368/blog/page/1/';
req.url = '/blog/page/1/';
middlewares.pageParam(req, res, next, 1);
urlUtils.redirect301.calledOnce.should.be.true();
next.called.should.be.false();
});
it('404 for /page/0/', function () {
req.originalUrl = 'http://localhost:2368/blog/page/0/';
req.url = '/blog/page/0/';
middlewares.pageParam(req, res, next, 0);
urlUtils.redirect301.called.should.be.false();
next.calledOnce.should.be.true();
(next.args[0][0] instanceof common.errors.NotFoundError).should.be.true();
});
it('404 for /page/something/', function () {
req.originalUrl = 'http://localhost:2368/blog/page/something/';
req.url = '/blog/page/something/';
middlewares.pageParam(req, res, next, 'something');
urlUtils.redirect301.called.should.be.false();
next.calledOnce.should.be.true();
(next.args[0][0] instanceof common.errors.NotFoundError).should.be.true();
});
it('redirect for /rss/page/1/', function () {
req.originalUrl = 'http://localhost:2368/blog/rss/page/1/';
req.url = '/blog/rss/page/1/';
middlewares.pageParam(req, res, next, 1);
urlUtils.redirect301.calledOnce.should.be.true();
next.called.should.be.false();
});
});