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-03-30 18:26:47 +03:00
|
|
|
const config = require('../../../core/server/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');
|
|
|
|
const defaultSettings = require('../../../core/server/data/schema').defaultSettings.blog;
|
2019-01-03 18:23:22 +03:00
|
|
|
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
let request;
|
|
|
|
|
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) => {
|
2019-12-17 13:45:31 +03:00
|
|
|
return (o !== 'ghost_head' && o !== 'ghost_foot' && o !== 'brand');
|
2019-09-23 13:59:00 +03:00
|
|
|
});
|
|
|
|
publicProperties.push('codeinjection_head', 'codeinjection_foot');
|
|
|
|
settings.should.have.properties(publicProperties);
|
2019-12-04 07:12:02 +03:00
|
|
|
Object.keys(settings).length.should.equal(22);
|
2019-01-03 18:23:22 +03:00
|
|
|
|
|
|
|
// Verify that we are returning the defaults for each value
|
|
|
|
_.forEach(settings, (value, key) => {
|
2019-01-15 15:03:17 +03:00
|
|
|
/**
|
|
|
|
* @TODO:
|
|
|
|
* This test is coupled with the settings cache and the model schema.
|
|
|
|
* This test should compare against the API result using the test utility.
|
|
|
|
* The settings cache should only cache model responses and should not know about
|
|
|
|
* API or theme formats.
|
|
|
|
*
|
|
|
|
* This is just a hack to be able to alias ghost_head & ghost_foot quickly.
|
|
|
|
*/
|
|
|
|
if (['codeinjection_head', 'codeinjection_foot'].includes(key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-24 13:12:07 +03:00
|
|
|
// `url` does not come from the settings cache
|
|
|
|
if (key === 'url') {
|
|
|
|
should(value).eql(`${config.get('url')}/`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-05 14:40:43 +03:00
|
|
|
let defaultKey = _.findKey(publicSettings, v => v === key);
|
|
|
|
let defaultValue = _.find(defaultSettings, 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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|