mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
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:
parent
82b83743a7
commit
7419ff2c4f
2 changed files with 14 additions and 3 deletions
|
@ -5,7 +5,7 @@ const versionMismatchHandler = (APIVersionCompatibilityService) => {
|
||||||
await APIVersionCompatibilityService.handleMismatch({
|
await APIVersionCompatibilityService.handleMismatch({
|
||||||
acceptVersion: req.headers['accept-version'],
|
acceptVersion: req.headers['accept-version'],
|
||||||
contentVersion: `v${res.locals.safeVersion}`,
|
contentVersion: `v${res.locals.safeVersion}`,
|
||||||
requestURL: req.originalURL,
|
requestURL: req.originalUrl,
|
||||||
userAgent: req.headers['user-agent']
|
userAgent: req.headers['user-agent']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,27 @@ describe('mw-api-version-mismatch', function () {
|
||||||
handleMismatch: sinon.stub().resolves()
|
handleMismatch: sinon.stub().resolves()
|
||||||
};
|
};
|
||||||
const req = {
|
const req = {
|
||||||
headers: {}
|
originalUrl: '/api/admin/posts/1',
|
||||||
|
headers: {
|
||||||
|
'accept-version': 'v3.28',
|
||||||
|
'user-agent': 'Zapier/2.1 GhostAdminSDK/3.28'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const res = {
|
const res = {
|
||||||
locals: {}
|
locals: {
|
||||||
|
safeVersion: '4.46'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
versionMismatchMW(APIVersionCompatibilityService)(new errors.RequestNotAcceptableError({
|
versionMismatchMW(APIVersionCompatibilityService)(new errors.RequestNotAcceptableError({
|
||||||
code: 'UPDATE_CLIENT'
|
code: 'UPDATE_CLIENT'
|
||||||
}), req, res, () => {
|
}), req, res, () => {
|
||||||
assert.equal(APIVersionCompatibilityService.handleMismatch.called, true);
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue