mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 15:12:58 +03:00
a2a2a7c7be
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings - The module is a tiny path resolver for settings used in Ghost. A first obvious place it's used is for routes.yaml settings files. With a little bit of tweaking it should also be adopted by redirects services
58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
// Switch these lines once there are useful utils
|
|
// const testUtils = require('./utils');
|
|
require('./utils');
|
|
const should = require('should');
|
|
const SettingsPathManager = require('../');
|
|
|
|
describe('Settings Path Manager', function () {
|
|
it('throws when paths parameter is not provided', function () {
|
|
try {
|
|
const settingsPathManager = new SettingsPathManager({
|
|
paths: [],
|
|
type: 'routes'
|
|
});
|
|
|
|
should.fail(settingsPathManager, 'Should have errored');
|
|
} catch (err) {
|
|
should.exist(err);
|
|
err.message.should.match(/paths values/g);
|
|
}
|
|
});
|
|
|
|
describe('getDefaultFilePath', function () {
|
|
it('returns default file path based on routes configuration', function (){
|
|
const settingsPathManager = new SettingsPathManager({
|
|
paths: ['/content/settings', '/content/data'],
|
|
type: 'routes'
|
|
});
|
|
|
|
const path = settingsPathManager.getDefaultFilePath();
|
|
|
|
path.should.equal('/content/settings/routes.yaml');
|
|
});
|
|
|
|
it('returns default file path based on redirects configuration', function (){
|
|
const settingsPathManager = new SettingsPathManager({
|
|
paths: ['/content/data', '/content/settings'],
|
|
type: 'redirects'
|
|
});
|
|
|
|
const path = settingsPathManager.getDefaultFilePath();
|
|
|
|
path.should.equal('/content/data/redirects.yaml');
|
|
});
|
|
|
|
it('returns default file path based on redirects configuration with json extension', function (){
|
|
const settingsPathManager = new SettingsPathManager({
|
|
paths: ['/content/data', '/content/settings'],
|
|
type: 'redirects',
|
|
extensions: ['json', 'yaml']
|
|
});
|
|
|
|
const path = settingsPathManager.getDefaultFilePath();
|
|
|
|
path.should.equal('/content/data/redirects.json');
|
|
});
|
|
});
|
|
});
|