2019-01-03 18:23:22 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const _ = require('lodash');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2019-01-03 18:23:22 +03:00
|
|
|
const localUtils = require('./utils');
|
|
|
|
|
|
|
|
// Values to test against
|
2020-03-30 18:26:47 +03:00
|
|
|
const publicSettings = require('../../../core/server/services/settings/public');
|
2020-08-27 17:57:50 +03:00
|
|
|
const defaultSettings = require('../../../core/server/data/schema').defaultSettings;
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-06-23 14:39:05 +03:00
|
|
|
const defaultSettingsKeys = [
|
|
|
|
'title',
|
|
|
|
'description',
|
|
|
|
'logo',
|
|
|
|
'icon',
|
2020-11-03 12:06:21 +03:00
|
|
|
'accent_color',
|
2020-06-23 14:39:05 +03:00
|
|
|
'cover_image',
|
|
|
|
'facebook',
|
|
|
|
'twitter',
|
|
|
|
'lang',
|
|
|
|
'timezone',
|
|
|
|
'codeinjection_head',
|
|
|
|
'codeinjection_foot',
|
|
|
|
'navigation',
|
|
|
|
'secondary_navigation',
|
|
|
|
'meta_title',
|
|
|
|
'meta_description',
|
|
|
|
'og_image',
|
|
|
|
'og_title',
|
|
|
|
'og_description',
|
|
|
|
'twitter_image',
|
|
|
|
'twitter_title',
|
|
|
|
'twitter_description',
|
2020-08-27 17:57:50 +03:00
|
|
|
'members_support_address',
|
2020-06-23 14:39:05 +03:00
|
|
|
'url'
|
|
|
|
];
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
describe('Settings Content API', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
let request;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
await testUtils.startGhost();
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
await testUtils.initFixtures('api_keys');
|
2019-01-03 18:23:22 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request settings', async function () {
|
2019-01-03 18:23:22 +03:00
|
|
|
const key = localUtils.getValidKey();
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request.get(localUtils.API.getApiQuery(`settings/?key=${key}`))
|
2019-01-03 18:23:22 +03:00
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
res.headers.vary.should.eql('Accept-Encoding');
|
|
|
|
should.exist(res.headers['access-control-allow-origin']);
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
should.exist(jsonResponse.meta);
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
jsonResponse.settings.should.be.an.Object();
|
|
|
|
const settings = jsonResponse.settings;
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
// Verify we have the right keys for settings
|
|
|
|
const publicProperties = _.filter(_.values(publicSettings), (o) => {
|
|
|
|
return (o !== 'brand');
|
|
|
|
});
|
2020-08-27 17:57:50 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-07-24 13:12:07 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
// settings.should.have.properties(publicProperties);
|
|
|
|
// Object.keys(settings).length.should.equal(22);
|
|
|
|
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;
|
|
|
|
}
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
let defaultKey = _.findKey(publicSettings, v => v === settingsKey);
|
|
|
|
let defaultValue = _.find(flattenedPublicSettings, setting => setting.key === defaultKey).defaultValue;
|
2019-01-07 16:35:51 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
// Convert empty strings to null
|
|
|
|
defaultValue = defaultValue || null;
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
if (defaultKey === 'navigation' || defaultKey === 'secondary_navigation') {
|
|
|
|
defaultValue = JSON.parse(defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
should(value).eql(defaultValue);
|
|
|
|
});
|
2019-01-03 18:23:22 +03:00
|
|
|
});
|
|
|
|
});
|