mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
6161f94910
refs: https://github.com/TryGhost/Toolbox/issues/595 We're rolling out new rules around the node assert library, the first of which is enforcing the use of assert/strict. This means we don't need to use the strict version of methods, as the standard version will work that way by default. This caught some gotchas in our existing usage of assert where the lack of strict mode had unexpected results: - Url matching needs to be done on `url.href` seeaa58b354a4
- Null and undefined are not the same thing, there were a few cases of this being confused - Particularly questionable changes in [PostExporter tests](c1a468744b
) tracked [here](https://github.com/TryGhost/Team/issues/3505). - A typo seeeaac9c293a
Moving forward, using assert strict should help us to catch unexpected behaviour, particularly around nulls and undefineds during implementation.
47 lines
1.9 KiB
JavaScript
47 lines
1.9 KiB
JavaScript
const assert = require('assert/strict');
|
|
const path = require('path');
|
|
|
|
const glob = require('glob');
|
|
|
|
const models = require('../../../core/server/models');
|
|
|
|
describe('API', function () {
|
|
describe('Cache Invalidation', function () {
|
|
before(async function () {
|
|
// Initialise models - Utilised by various endpoints to reference static fields (i.e models.Post.allowedFormats) when required in
|
|
models.init();
|
|
});
|
|
|
|
it('Controller actions explicitly declare cacheInvalidate header', async function () {
|
|
const controllersRootPath = path.join(__dirname, '../../../core/server/api/endpoints');
|
|
const controllerPaths = glob.sync('*.js', {
|
|
cwd: controllersRootPath,
|
|
ignore: [
|
|
'index.js',
|
|
'identities.js' // The identities controller can not be required directly due to requiring other parts of Ghost to have been initialised first
|
|
],
|
|
realpath: true
|
|
});
|
|
|
|
assert.ok(controllerPaths.length > 0, `No controllers found in ${controllersRootPath}`);
|
|
|
|
controllerPaths.forEach((controllerPath) => {
|
|
const controllerConfig = require(controllerPath);
|
|
const ignoreKeys = ['docName'];
|
|
|
|
Object.keys(controllerConfig).forEach((key) => {
|
|
if (ignoreKeys.includes(key) || typeof controllerConfig[key] === 'function') {
|
|
return;
|
|
}
|
|
|
|
assert.notEqual(
|
|
controllerConfig[key].headers?.cacheInvalidate,
|
|
undefined,
|
|
`"${key}" action in controller: ${controllerPath} is missing cacheInvalidate header - This needs to be explicitly defined`
|
|
);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|