From c0b1ddfd3e8cbc40bfa9df99c31e712037e00d11 Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 29 Nov 2021 17:30:53 +0400 Subject: [PATCH] Added subdirectory coverage to DynamiRedirectsManager suites refs https://github.com/TryGhost/Toolbox/issues/139 - These unit tests come directly from equivalent regression tests in Ghost repository - https://github.com/TryGhost/Ghost/blob/fedbfb3c67ec99e7ec6085f04589e4ef9956834d/test/regression/site/redirects.test.js - This changeset covers subdirectory use in incoming request --- .../test/DynamicRedirectManager.test.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ghost/express-dynamic-redirects/test/DynamicRedirectManager.test.js b/ghost/express-dynamic-redirects/test/DynamicRedirectManager.test.js index 4cd613297a..f8d908db41 100644 --- a/ghost/express-dynamic-redirects/test/DynamicRedirectManager.test.js +++ b/ghost/express-dynamic-redirects/test/DynamicRedirectManager.test.js @@ -314,4 +314,34 @@ describe('DynamicRedirectManager', function () { }); }); }); + + describe('with subdirectory configuration', function () { + let manager; + + beforeEach(function () { + manager = new DynamicRedirectManager({ + permanentMaxAge: 100, + getSubdirectoryURL: (pathname) => { + return urlJoin('', pathname); + } + }); + }); + + it('should include the subdirectory', function () { + const from = '/my-old-blog-post/'; + const to = '/revamped-url/'; + + manager.addRedirect(from , to, {permanent: true}); + + req.url = '/blog/my-old-blog-post/'; + + manager.handleRequest(req, res, function next() { + should.fail(true, 'next should NOT have been called'); + }); + + should.equal(headers['Cache-Control'], 'public, max-age=100'); + should.equal(status, 301); + should.equal(location, '/blog/revamped-url/'); + }); + }); });