0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Removed use of 'routes' parameter in route settings loader

refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- The only allowed route settings name is 'routes.yaml', which removes a need to parameterize the function as the location is permanent anyway
- Simplifying the function in any possible way before extracting the common bits into an external lib
This commit is contained in:
Naz 2021-09-27 12:48:48 +02:00 committed by naz
parent ba964c549f
commit 7a91917424
4 changed files with 10 additions and 12 deletions

View file

@ -18,7 +18,7 @@ module.exports = {
},
getCurrentHash: async () => {
const data = await SettingsLoader.loadSettings('routes');
const data = await SettingsLoader.loadSettings();
return calculateHash(JSON.stringify(data));
}

View file

@ -28,11 +28,10 @@ const getSettingFilePath = (setting) => {
* Functionally same as loadSettingsSync with exception of loading
* settings asynchronously. This method is used at new places to read settings
* to prevent blocking the eventloop
*
* @param {String} setting the requested settings as defined in setting knownSettings
* @returns {Promise<Object>} settingsFile
*/
const loadSettings = async (setting) => {
const loadSettings = async () => {
const setting = 'routes';
const {fileName, contentPath, filePath} = getSettingFilePath(setting);
try {
@ -61,11 +60,10 @@ const loadSettings = async (setting) => {
* Reads the desired settings YAML file and passes the
* file to the YAML parser which then returns a JSON object.
* NOTE: loading happens synchronously
*
* @param {String} setting the requested settings as defined in setting knownSettings
* @returns {Object} settingsFile
*/
module.exports.loadSettingsSync = function loadSettingsSync(setting) {
module.exports.loadSettingsSync = function loadSettingsSync() {
const setting = 'routes';
const {fileName, contentPath, filePath} = getSettingFilePath(setting);
try {

View file

@ -152,7 +152,7 @@ module.exports.init = init;
* @returns {Object} routes.yaml in JSON format
*/
module.exports.loadRouteSettingsSync = () => {
return SettingsLoader.loadSettingsSync('routes');
return SettingsLoader.loadSettingsSync();
};
module.exports.api = {

View file

@ -61,7 +61,7 @@ describe('UNIT > Settings Service loader:', function () {
it('can find yaml settings file and returns a settings object', function () {
const fsReadFileSpy = sinon.spy(fs, 'readFileSync');
const expectedSettingsFile = path.join(__dirname, '../../../utils/fixtures/settings/goodroutes.yaml');
const expectedSettingsFile = path.join(__dirname, '../../../utils/fixtures/settings/routes.yaml');
yamlParserStub.returns(yamlStubFile);
validateStub.returns({routes: {}, collections: {}, taxonomies: {}});
@ -69,7 +69,7 @@ describe('UNIT > Settings Service loader:', function () {
loadSettings.__set__('yamlParser', yamlParserStub);
loadSettings.__set__('validate', validateStub);
const setting = loadSettings.loadSettingsSync('goodroutes');
const setting = loadSettings.loadSettingsSync();
should.exist(setting);
setting.should.be.an.Object().with.properties('routes', 'collections', 'taxonomies');
@ -87,7 +87,7 @@ describe('UNIT > Settings Service loader:', function () {
loadSettings.__set__('yamlParser', yamlParserStub);
try {
loadSettings.loadSettingsSync('goodroutes');
loadSettings.loadSettingsSync();
done(new Error('Loader should fail'));
} catch (err) {
should.exist(err);
@ -116,7 +116,7 @@ describe('UNIT > Settings Service loader:', function () {
loadSettings.__set__('yamlParser', yamlParserStub);
try {
loadSettings.loadSettingsSync('routes');
loadSettings.loadSettingsSync();
done(new Error('Loader should fail'));
} catch (err) {
err.message.should.match(/Error trying to load YAML setting for routes from/);