mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Converted settings e2e test to use test-framework
refs https://github.com/TryGhost/Toolbox/issues/215 - The conversion should serve as a reference test. It was also a massive LoC drop when converting, felt almost criminal not to do it!
This commit is contained in:
parent
9f0545b133
commit
1309a8144f
2 changed files with 101 additions and 101 deletions
92
test/e2e-api/content/__snapshots__/settings.test.js.snap
Normal file
92
test/e2e-api/content/__snapshots__/settings.test.js.snap
Normal file
|
@ -0,0 +1,92 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Settings Content API Can request settings 1: [body] 1`] = `
|
||||
Object {
|
||||
"meta": Object {},
|
||||
"settings": Object {
|
||||
"accent_color": "#FF1A75",
|
||||
"codeinjection_foot": null,
|
||||
"codeinjection_head": null,
|
||||
"cover_image": "https://static.ghost.org/v4.0.0/images/publication-cover.jpg",
|
||||
"description": "Thoughts, stories and ideas",
|
||||
"facebook": "ghost",
|
||||
"icon": null,
|
||||
"lang": "en",
|
||||
"locale": "en",
|
||||
"logo": null,
|
||||
"members_support_address": "noreply",
|
||||
"meta_description": null,
|
||||
"meta_title": null,
|
||||
"navigation": Array [
|
||||
Object {
|
||||
"label": "Home",
|
||||
"url": "/",
|
||||
},
|
||||
Object {
|
||||
"label": "About",
|
||||
"url": "/about/",
|
||||
},
|
||||
Object {
|
||||
"label": "Collection",
|
||||
"url": "/tag/getting-started/",
|
||||
},
|
||||
Object {
|
||||
"label": "Author",
|
||||
"url": "/author/ghost/",
|
||||
},
|
||||
Object {
|
||||
"label": "Portal",
|
||||
"url": "/portal/",
|
||||
},
|
||||
],
|
||||
"og_description": null,
|
||||
"og_image": null,
|
||||
"og_title": null,
|
||||
"secondary_navigation": Array [
|
||||
Object {
|
||||
"label": "Data & privacy",
|
||||
"url": "/privacy/",
|
||||
},
|
||||
Object {
|
||||
"label": "Contact",
|
||||
"url": "/contact/",
|
||||
},
|
||||
Object {
|
||||
"label": "Contribute →",
|
||||
"url": "/contribute/",
|
||||
},
|
||||
],
|
||||
"timezone": "Etc/UTC",
|
||||
"title": "Ghost",
|
||||
"twitter": "@ghost",
|
||||
"twitter_description": null,
|
||||
"twitter_image": null,
|
||||
"twitter_title": null,
|
||||
"url": "http://127.0.0.1:2369/",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Settings Content API Can request settings 1: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "*",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "942",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": "W/\\"3ae-FBGPtlUjSvGtTGLOj2sW5Rbn33s\\"",
|
||||
"vary": "Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Settings Content API Can request settings 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "*",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "942",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": "W/\\"3ae-FBGPtlUjSvGtTGLOj2sW5Rbn33s\\"",
|
||||
"vary": "Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
|
@ -1,110 +1,18 @@
|
|||
const should = require('should');
|
||||
const supertest = require('supertest');
|
||||
const _ = require('lodash');
|
||||
const testUtils = require('../../utils');
|
||||
const config = require('../../../core/shared/config');
|
||||
const localUtils = require('./utils');
|
||||
|
||||
// Values to test against
|
||||
const publicSettings = require('../../../core/shared/settings-cache/public');
|
||||
const defaultSettings = require('../../../core/server/data/schema').defaultSettings;
|
||||
|
||||
const defaultSettingsKeys = [
|
||||
'title',
|
||||
'description',
|
||||
'logo',
|
||||
'icon',
|
||||
'accent_color',
|
||||
'cover_image',
|
||||
'facebook',
|
||||
'twitter',
|
||||
'lang',
|
||||
'locale',
|
||||
'timezone',
|
||||
'codeinjection_head',
|
||||
'codeinjection_foot',
|
||||
'navigation',
|
||||
'secondary_navigation',
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
'og_image',
|
||||
'og_title',
|
||||
'og_description',
|
||||
'twitter_image',
|
||||
'twitter_title',
|
||||
'twitter_description',
|
||||
'members_support_address',
|
||||
'url'
|
||||
];
|
||||
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
||||
|
||||
describe('Settings Content API', function () {
|
||||
let request;
|
||||
let agent;
|
||||
|
||||
before(async function () {
|
||||
await localUtils.startGhost();
|
||||
request = supertest.agent(config.get('url'));
|
||||
await testUtils.initFixtures('api_keys');
|
||||
agent = await agentProvider.getContentAPIAgent();
|
||||
await fixtureManager.init('api_keys');
|
||||
agent.authenticate();
|
||||
});
|
||||
|
||||
it('Can request settings', async function () {
|
||||
const key = localUtils.getValidKey();
|
||||
const res = await request.get(localUtils.API.getApiQuery(`settings/?key=${key}`))
|
||||
.set('Origin', testUtils.API.getURL())
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
|
||||
res.headers.vary.should.eql('Accept-Encoding');
|
||||
should.exist(res.headers['access-control-allow-origin']);
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
|
||||
const jsonResponse = res.body;
|
||||
should.exist(jsonResponse.settings);
|
||||
should.exist(jsonResponse.meta);
|
||||
|
||||
jsonResponse.settings.should.be.an.Object();
|
||||
const settings = jsonResponse.settings;
|
||||
|
||||
// Verify we have the right keys for settings
|
||||
const publicProperties = _.filter(_.values(publicSettings), (o) => {
|
||||
return (o !== 'brand');
|
||||
});
|
||||
|
||||
const flattenedPublicSettings = [];
|
||||
_.each(defaultSettings, function each(_settings) {
|
||||
_.each(_settings, function eachSetting(setting) {
|
||||
const flags = setting.flags || '';
|
||||
if (setting.group === 'site' || (flags.includes('PUBLIC'))) {
|
||||
flattenedPublicSettings.push(setting);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
settings.should.have.properties(publicProperties);
|
||||
|
||||
// The length below should only change when public settings have been removed or added
|
||||
Object.keys(settings).length.should.equal(25);
|
||||
Object.keys(settings).should.deepEqual(defaultSettingsKeys);
|
||||
|
||||
// Verify that we are returning the defaults for each value
|
||||
_.forEach(settings, (value, settingsKey) => {
|
||||
// `url` does not come from the settings cache
|
||||
if (settingsKey === 'url') {
|
||||
should(value).eql(`${config.get('url')}/`);
|
||||
return;
|
||||
}
|
||||
|
||||
let defaultKey = publicSettings[settingsKey];
|
||||
let defaultValue = _.find(flattenedPublicSettings, setting => setting.key === defaultKey).defaultValue;
|
||||
|
||||
// Convert empty strings to null
|
||||
defaultValue = defaultValue || null;
|
||||
|
||||
if (defaultKey === 'navigation' || defaultKey === 'secondary_navigation') {
|
||||
defaultValue = JSON.parse(defaultValue);
|
||||
}
|
||||
|
||||
should(value).eql(defaultValue);
|
||||
});
|
||||
await agent.get('settings/')
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot()
|
||||
.matchBodySnapshot();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue