Fixed requestURL value passed to the APIVersionCompatibilityService

refs https://github.com/TryGhost/Toolbox/issues/292

- There was a typo in the variable name - req.originalURL is NOT does not exist on express' reqest object
- Added tests to avoid similar mistake again
This commit is contained in:
Naz 2022-05-09 15:33:40 +08:00
parent 82b83743a7
commit 7419ff2c4f
2 changed files with 14 additions and 3 deletions

View File

@ -5,7 +5,7 @@ const versionMismatchHandler = (APIVersionCompatibilityService) => {
await APIVersionCompatibilityService.handleMismatch({
acceptVersion: req.headers['accept-version'],
contentVersion: `v${res.locals.safeVersion}`,
requestURL: req.originalURL,
requestURL: req.originalUrl,
userAgent: req.headers['user-agent']
});
}

View File

@ -10,16 +10,27 @@ describe('mw-api-version-mismatch', function () {
handleMismatch: sinon.stub().resolves()
};
const req = {
headers: {}
originalUrl: '/api/admin/posts/1',
headers: {
'accept-version': 'v3.28',
'user-agent': 'Zapier/2.1 GhostAdminSDK/3.28'
}
};
const res = {
locals: {}
locals: {
safeVersion: '4.46'
}
};
versionMismatchMW(APIVersionCompatibilityService)(new errors.RequestNotAcceptableError({
code: 'UPDATE_CLIENT'
}), req, res, () => {
assert.equal(APIVersionCompatibilityService.handleMismatch.called, true);
assert.equal(APIVersionCompatibilityService.handleMismatch.args[0][0].acceptVersion, 'v3.28');
assert.equal(APIVersionCompatibilityService.handleMismatch.args[0][0].contentVersion, 'v4.46');
assert.equal(APIVersionCompatibilityService.handleMismatch.args[0][0].requestURL, '/api/admin/posts/1');
assert.equal(APIVersionCompatibilityService.handleMismatch.args[0][0].userAgent, 'Zapier/2.1 GhostAdminSDK/3.28');
done();
});
});