Added external URL coverage to DynamiRedirectsManager suites
refs https://github.com/TryGhost/Toolbox/issues/139
- These unit tests come directly from equivalent regression tests in Ghost repository - fedbfb3c67/test/regression/site/redirects.test.js
- This changeset covers redirects to external URLs
This commit is contained in:
parent
a6d86c85b6
commit
0daed36366
@ -257,5 +257,61 @@ describe('DynamicRedirectManager', function () {
|
||||
should.equal(location, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('External url redirect', function () {
|
||||
it('with trailing slash', function () {
|
||||
const from = '/external-url';
|
||||
const to = 'https://ghost.org';
|
||||
|
||||
manager.addRedirect(from , to);
|
||||
|
||||
req.url = '/external-url/';
|
||||
|
||||
manager.handleRequest(req, res, function next() {
|
||||
should.fail(true, 'next should NOT have been called');
|
||||
});
|
||||
|
||||
// NOTE: max-age is "0" because it's not a permanent redirect
|
||||
should.equal(headers['Cache-Control'], 'public, max-age=0');
|
||||
should.equal(status, 302);
|
||||
should.equal(location, 'https://ghost.org/');
|
||||
});
|
||||
|
||||
it('without trailing slash', function () {
|
||||
const from = '/external-url';
|
||||
const to = 'https://ghost.org';
|
||||
|
||||
manager.addRedirect(from , to);
|
||||
|
||||
req.url = '/external-url';
|
||||
|
||||
manager.handleRequest(req, res, function next() {
|
||||
should.fail(true, 'next should NOT have been called');
|
||||
});
|
||||
|
||||
// NOTE: max-age is "0" because it's not a permanent redirect
|
||||
should.equal(headers['Cache-Control'], 'public, max-age=0');
|
||||
should.equal(status, 302);
|
||||
should.equal(location, 'https://ghost.org/');
|
||||
});
|
||||
|
||||
it('with capturing group', function () {
|
||||
const from = '/external-url/(.*)';
|
||||
const to = 'https://ghost.org/$1';
|
||||
|
||||
manager.addRedirect(from , to);
|
||||
|
||||
req.url = '/external-url/docs';
|
||||
|
||||
manager.handleRequest(req, res, function next() {
|
||||
should.fail(true, 'next should NOT have been called');
|
||||
});
|
||||
|
||||
// NOTE: max-age is "0" because it's not a permanent redirect
|
||||
should.equal(headers['Cache-Control'], 'public, max-age=0');
|
||||
should.equal(status, 302);
|
||||
should.equal(location, 'https://ghost.org/docs');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user