2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Updated settings API v3 tests to check for correct types returned for specific keys

refs https://github.com/TryGhost/Ghost/issues/10318
refs 476fca6e5b

- Symetric change to one done in referenced commit which maps fields for API v2
This commit is contained in:
Nazar Gargol 2020-06-25 17:36:10 +12:00
parent 476fca6e5b
commit 91e3630f36
4 changed files with 68 additions and 43 deletions

View file

@ -34,10 +34,15 @@ module.exports.forPost = (frame, model, attrs) => {
module.exports.forSettings = (attrs, frame) => {
const _ = require('lodash');
const mapGroupToType = require('./settings-type-group-mapper');
// @TODO: https://github.com/TryGhost/Ghost/issues/10106
// @NOTE: Admin & Content API return a different format, needs two mappers
if (_.isArray(attrs)) {
attrs.forEach((attr) => {
attr.type = mapGroupToType(attr.group);
});
// CASE: read single setting
if (frame.original.params && frame.original.params.key) {
if (frame.original.params.key === 'ghost_head') {

View file

@ -0,0 +1,20 @@
const groupTypeMapping = {
core: 'core',
amp: 'blog',
labs: 'blog',
slack: 'blog',
site: 'blog',
unsplash: 'blog',
views: 'blog',
theme: 'theme',
members: 'members',
private: 'private',
portal: 'portal',
email: 'bulk_email'
};
const mapGroupToType = (group) => {
return groupTypeMapping[group];
};
module.exports = mapGroupToType;

View file

@ -3,14 +3,14 @@ const groupTypeMapping = {
amp: 'blog',
labs: 'blog',
slack: 'blog',
site: 'blog',
unsplash: 'blog',
views: 'blog',
theme: 'theme',
members: 'members',
private: 'private',
portal: 'portal',
email: 'bulk_email',
site: 'site'
email: 'bulk_email'
};
const mapGroupToType = (group) => {

View file

@ -8,46 +8,46 @@ const ghost = testUtils.startGhost;
// NOTE: in future iterations these fields should be fetched from a central module.
// Have put a list as is here for the lack of better place for it.
const defaultSettingsKeys = [
'title',
'description',
'logo',
'cover_image',
'icon',
'lang',
'timezone',
'codeinjection_head',
'codeinjection_foot',
'facebook',
'twitter',
'navigation',
'secondary_navigation',
'meta_title',
'meta_description',
'og_image',
'og_title',
'og_description',
'twitter_image',
'twitter_title',
'twitter_description',
'active_theme',
'is_private',
'password',
'public_hash',
'default_content_visibility',
'members_subscription_settings',
'stripe_connect_integration',
'portal_name',
'portal_button',
'portal_plans',
'bulk_email_settings',
'amp',
'labs',
'slack',
'unsplash',
'shared_views',
'active_timezone',
'default_locale'
const defaultSettingsKeyTypes = [
{key: 'title',type: 'blog'},
{key: 'description',type: 'blog'},
{key: 'logo',type: 'blog'},
{key: 'cover_image',type: 'blog'},
{key: 'icon',type: 'blog'},
{key: 'lang',type: 'blog'},
{key: 'timezone',type: 'blog'},
{key: 'codeinjection_head',type: 'blog'},
{key: 'codeinjection_foot',type: 'blog'},
{key: 'facebook',type: 'blog'},
{key: 'twitter',type: 'blog'},
{key: 'navigation',type: 'blog'},
{key: 'secondary_navigation',type: 'blog'},
{key: 'meta_title',type: 'blog'},
{key: 'meta_description',type: 'blog'},
{key: 'og_image',type: 'blog'},
{key: 'og_title',type: 'blog'},
{key: 'og_description',type: 'blog'},
{key: 'twitter_image',type: 'blog'},
{key: 'twitter_title',type: 'blog'},
{key: 'twitter_description',type: 'blog'},
{key: 'active_theme',type: 'theme'},
{key: 'is_private',type: 'private'},
{key: 'password',type: 'private'},
{key: 'public_hash',type: 'private'},
{key: 'default_content_visibility',type: 'members'},
{key: 'members_subscription_settings',type: 'members'},
{key: 'stripe_connect_integration',type: 'members'},
{key: 'portal_name',type: 'portal'},
{key: 'portal_button',type: 'portal'},
{key: 'portal_plans',type: 'portal'},
{key: 'bulk_email_settings',type: 'bulk_email'},
{key: 'amp',type: 'blog'},
{key: 'labs',type: 'blog'},
{key: 'slack',type: 'blog'},
{key: 'unsplash',type: 'blog'},
{key: 'shared_views',type: 'blog'},
{key: 'active_timezone',type: 'blog'},
{key: 'default_locale',type: 'blog'}
];
describe('Settings API (canary)', function () {
@ -83,7 +83,7 @@ describe('Settings API (canary)', function () {
const settings = jsonResponse.settings;
Object.keys(settings).length.should.equal(39);
settings.map(s => s.key).should.deepEqual(defaultSettingsKeys);
settings.map(s => ({key: s.key, type: s.type})).should.deepEqual(defaultSettingsKeyTypes);
localUtils.API.checkResponse(jsonResponse, 'settings');
});