Added edge case unit tests to DynamiRedirectsManager suites
refs https://github.com/TryGhost/Toolbox/issues/139 - These changes bring the module to 100% test coverage. No need to cover any more unless there are specific bugs uncovere!
This commit is contained in:
parent
c0b1ddfd3e
commit
c25c409e60
@ -95,6 +95,40 @@ describe('DynamicRedirectManager', function () {
|
||||
should.equal(location, null);
|
||||
});
|
||||
|
||||
it('Throws an error if unexpected internal component throws unknown error', function () {
|
||||
// override internal behavior to throw an unknown error
|
||||
manager.setupRedirect = () => {
|
||||
throw new Error('Unknown error');
|
||||
};
|
||||
|
||||
const from = '/match-me';
|
||||
const to = '/redirect-fails';
|
||||
|
||||
try {
|
||||
manager.addRedirect(from , to);
|
||||
should.fail(false, 'Should have thrown an error');
|
||||
} catch (e) {
|
||||
e.message.should.equal('Unknown error');
|
||||
}
|
||||
});
|
||||
|
||||
it('removes all redirects', function () {
|
||||
const from = '/redirect-me';
|
||||
const to = '/redirected';
|
||||
|
||||
manager.addRedirect(from , to);
|
||||
|
||||
req.url = '/redirect-me';
|
||||
|
||||
manager.removeAllRedirects();
|
||||
manager.redirectIds.should.be.empty();
|
||||
manager.redirects.should.be.empty();
|
||||
|
||||
manager.handleRequest(req, res, function next() {
|
||||
should.ok(true, 'next should have been called');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Substitution regex redirects', function () {
|
||||
it('Works with substitution redirect case and no trailing slash', function (){
|
||||
const from = '^/post/[0-9]+/([a-z0-9\\-]+)';
|
||||
|
Loading…
Reference in New Issue
Block a user