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
|
|
|
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
let request;
|
|
|
|
|
2020-06-23 14:39:05 +03:00
|
|
|
const defaultSettingsKeys = [
|
|
|
|
'title',
|
|
|
|
'description',
|
|
|
|
'logo',
|
|
|
|
'icon',
|
|
|
|
'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 () {
|
2019-01-03 18:23:22 +03:00
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
}).then(function () {
|
|
|
|
return testUtils.initFixtures('api_keys');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can request settings', function () {
|
2019-01-03 18:23:22 +03:00
|
|
|
const key = localUtils.getValidKey();
|
|
|
|
return 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)
|
|
|
|
.then((res) => {
|
|
|
|
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
|
2019-09-23 13:59:00 +03:00
|
|
|
const publicProperties = _.filter(_.values(publicSettings), (o) => {
|
2020-06-23 14:39:05 +03:00
|
|
|
return (o !== 'brand');
|
2019-09-23 13:59:00 +03:00
|
|
|
});
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2020-08-27 17:57:50 +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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-23 14:39:05 +03:00
|
|
|
// settings.should.have.properties(publicProperties);
|
|
|
|
// Object.keys(settings).length.should.equal(22);
|
|
|
|
Object.keys(settings).should.deepEqual(defaultSettingsKeys);
|
2019-01-03 18:23:22 +03:00
|
|
|
// Verify that we are returning the defaults for each value
|
2020-10-19 07:45:26 +03:00
|
|
|
_.forEach(settings, (value, settingsKey) => {
|
2019-07-24 13:12:07 +03:00
|
|
|
// `url` does not come from the settings cache
|
2020-10-19 07:45:26 +03:00
|
|
|
if (settingsKey === 'url') {
|
2019-07-24 13:12:07 +03:00
|
|
|
should(value).eql(`${config.get('url')}/`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
let defaultKey = _.findKey(publicSettings, v => v === settingsKey);
|
2020-08-27 17:57:50 +03:00
|
|
|
let defaultValue = _.find(flattenedPublicSettings, setting => setting.key === defaultKey).defaultValue;
|
2019-01-03 18:23:22 +03:00
|
|
|
|
2019-01-07 16:35:51 +03:00
|
|
|
// Convert empty strings to null
|
|
|
|
defaultValue = defaultValue || null;
|
|
|
|
|
2019-12-04 07:12:02 +03:00
|
|
|
if (defaultKey === 'navigation' || defaultKey === 'secondary_navigation') {
|
2019-01-03 18:23:22 +03:00
|
|
|
defaultValue = JSON.parse(defaultValue);
|
|
|
|
}
|
|
|
|
|
2019-01-07 16:35:51 +03:00
|
|
|
should(value).eql(defaultValue);
|
2019-01-03 18:23:22 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|