0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Hardened frontend tests checking API engine

refs 0f59537b96
refs https://github.com/TryGhost/Team/issues/221
refs 303046bc0a

- When the referenced changes were introduced they did not take into account upcoming engine versions and provided little guidance about what other areas might need to be checked and changed
- The last referenced commit shows an approximate scale of changes that might be beened when frontend engine defaults are modified in the future
This commit is contained in:
Naz 2021-02-24 18:55:12 +13:00
parent 11b2876c33
commit e63e4bb193
2 changed files with 59 additions and 32 deletions

View file

@ -6,18 +6,20 @@ const testUtils = require('../../utils');
const configUtils = require('../../utils/configUtils'); const configUtils = require('../../utils/configUtils');
const models = require('../../../core/server/models'); const models = require('../../../core/server/models');
const {events} = require('../../../core/server/lib/common'); const {events} = require('../../../core/server/lib/common');
const themes = require('../../../core/frontend/services/themes');
const UrlService = rewire('../../../core/frontend/services/url/UrlService'); const UrlService = rewire('../../../core/frontend/services/url/UrlService');
/**
* @NOTE
*
* If this test fails for you, you are probably modifying supported theme engines
* and thus should check if the there is a configuration added for the new API version
*
*/
describe('Integration: services/url/UrlService', function () { describe('Integration: services/url/UrlService', function () {
let urlService; let urlService;
before(function () { before(function () {
models.init(); models.init();
sinon.stub(themes, 'getActive').returns({
engine: () => 'v2'
});
}); });
before(testUtils.teardownDb); before(testUtils.teardownDb);

View file

@ -2,7 +2,20 @@ const should = require('should');
const sinon = require('sinon'); const sinon = require('sinon');
const themeEngines = require('../../../../../core/frontend/services/themes/engines'); const themeEngines = require('../../../../../core/frontend/services/themes/engines');
/**
* @NOTE
*
* If this test fails for you, you are probably modifying supported theme engines.
*
* When you make a change, please test that:
*
* 1. Please check that uploading a theme with newly added/modified engine version works
* 2. Check other places that potentially need updates (e.g.: frontends resource cache config, )
* 3. Add the a protective test for when next verstion (v6?) is planned it has to be changed again
*/
describe('Themes: engines', function () { describe('Themes: engines', function () {
const DEFAULT_ENGINE_VERSION = 'v4';
afterEach(function () { afterEach(function () {
sinon.restore(); sinon.restore();
}); });
@ -10,11 +23,47 @@ describe('Themes: engines', function () {
it('no engines', function () { it('no engines', function () {
const engines = themeEngines.create(); const engines = themeEngines.create();
engines.should.eql({ engines.should.eql({
'ghost-api': 'v4' 'ghost-api': DEFAULT_ENGINE_VERSION
}); });
}); });
describe('ghost-api', function () { describe('ghost-api', function () {
it('unknown version falls back to default version', function () {
const engines = themeEngines.create({
engines: {
'ghost-api': 'v100'
}
});
engines.should.eql({
'ghost-api': DEFAULT_ENGINE_VERSION
});
});
it('deprecated and not supported version falls back to default version', function () {
const engines = themeEngines.create({
engines: {
'ghost-api': '^0.1'
}
});
engines.should.eql({
'ghost-api': DEFAULT_ENGINE_VERSION
});
});
it('not supported upcoming version falls back to default version', function () {
const engines = themeEngines.create({
engines: {
'ghost-api': 'v5'
}
});
engines.should.eql({
'ghost-api': DEFAULT_ENGINE_VERSION
});
});
it('v2', function () { it('v2', function () {
const engines = themeEngines.create({ const engines = themeEngines.create({
engines: { engines: {
@ -27,30 +76,6 @@ describe('Themes: engines', function () {
}); });
}); });
it('v10', function () {
const engines = themeEngines.create({
engines: {
'ghost-api': 'v10'
}
});
engines.should.eql({
'ghost-api': 'v4'
});
});
it('^0.1', function () {
const engines = themeEngines.create({
engines: {
'ghost-api': '^0.1'
}
});
engines.should.eql({
'ghost-api': 'v4'
});
});
it('^2', function () { it('^2', function () {
const engines = themeEngines.create({ const engines = themeEngines.create({
engines: { engines: {
@ -131,7 +156,7 @@ describe('Themes: engines', function () {
}); });
engines.should.eql({ engines.should.eql({
'ghost-api': 'v4' 'ghost-api': DEFAULT_ENGINE_VERSION
}); });
}); });
@ -143,7 +168,7 @@ describe('Themes: engines', function () {
}); });
engines.should.eql({ engines.should.eql({
'ghost-api': 'v4' 'ghost-api': DEFAULT_ENGINE_VERSION
}); });
}); });
}); });