mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added coverage for route settings class
refs 3150c87935
- Adds basic coverage for a bug that was fixed in referenced commit.
Next time it should be easier to add more tests to the suite as there's
already an example starter to work your way from.
This commit is contained in:
parent
0322c47a58
commit
42cd78e05e
1 changed files with 47 additions and 0 deletions
47
test/unit/server/services/settings/route-settings.test.js
Normal file
47
test/unit/server/services/settings/route-settings.test.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
const sinon = require('sinon');
|
||||
const should = require('should');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const bridge = require('../../../../../core/bridge');
|
||||
const RouteSettings = require('../../../../../core/server/services/route-settings/route-settings');
|
||||
|
||||
describe('UNIT > Settings Service DefaultSettingsManager:', function () {
|
||||
beforeEach(function () {
|
||||
sinon.stub(fs, 'readFile');
|
||||
sinon.stub(fs, 'readFileSync');
|
||||
sinon.stub(fs, 'copy');
|
||||
sinon.stub(bridge, 'reloadFrontend');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
describe('setFromFilePath', function () {
|
||||
it('catches parsing error when setFromFilePath', async function () {
|
||||
const routesSettingsPath = path.join(__dirname, '../../../../utils/fixtures/settings/routes.yaml');
|
||||
const backupFilePath = path.join(__dirname, '../../../../utils/fixtures/settings/routes-backup.yaml');
|
||||
const incomingSettingsPath = path.join(__dirname, '../../../../utils/fixtures/settings/routes-incoming.yaml');
|
||||
|
||||
fs.readFile.withArgs(routesSettingsPath, 'utf8').resolves('content');
|
||||
fs.copy.withArgs(backupFilePath, routesSettingsPath).resolves();
|
||||
fs.copy.withArgs(incomingSettingsPath, routesSettingsPath).resolves();
|
||||
|
||||
// simulate a parsing error during frontend reload
|
||||
bridge.reloadFrontend.throws(new Error('YAMLException: bad indentation of a mapping entry'));
|
||||
|
||||
const defaultSettingsManager = new RouteSettings({
|
||||
settingsLoader: {},
|
||||
settingsPath: routesSettingsPath,
|
||||
backupPath: backupFilePath
|
||||
});
|
||||
|
||||
try {
|
||||
await defaultSettingsManager.setFromFilePath(incomingSettingsPath);
|
||||
should.fail('should.fail');
|
||||
} catch (error) {
|
||||
error.message.should.match(/YAMLException: bad indentation of a mapping entry/);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue