From 91e3630f3647e6bdfc24eba8b2ec4c1d29866ab7 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Thu, 25 Jun 2020 17:36:10 +1200 Subject: [PATCH] Updated settings API v3 tests to check for correct types returned for specific keys refs https://github.com/TryGhost/Ghost/issues/10318 refs 476fca6e5b4b58d40a9340fc6dcfc31f4c7c0be2 - Symetric change to one done in referenced commit which maps fields for API v2 --- .../serializers/output/utils/extra-attrs.js | 5 ++ .../utils/settings-type-group-mapper.js | 20 +++++ .../utils/settings-type-group-mapper.js | 4 +- .../api/canary/admin/settings_spec.js | 82 +++++++++---------- 4 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 core/server/api/canary/utils/serializers/output/utils/settings-type-group-mapper.js diff --git a/core/server/api/canary/utils/serializers/output/utils/extra-attrs.js b/core/server/api/canary/utils/serializers/output/utils/extra-attrs.js index 4efba610aa..536c679de9 100644 --- a/core/server/api/canary/utils/serializers/output/utils/extra-attrs.js +++ b/core/server/api/canary/utils/serializers/output/utils/extra-attrs.js @@ -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') { diff --git a/core/server/api/canary/utils/serializers/output/utils/settings-type-group-mapper.js b/core/server/api/canary/utils/serializers/output/utils/settings-type-group-mapper.js new file mode 100644 index 0000000000..f0ae576bc3 --- /dev/null +++ b/core/server/api/canary/utils/serializers/output/utils/settings-type-group-mapper.js @@ -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; diff --git a/core/server/api/v2/utils/serializers/output/utils/settings-type-group-mapper.js b/core/server/api/v2/utils/serializers/output/utils/settings-type-group-mapper.js index b59e39c818..f0ae576bc3 100644 --- a/core/server/api/v2/utils/serializers/output/utils/settings-type-group-mapper.js +++ b/core/server/api/v2/utils/serializers/output/utils/settings-type-group-mapper.js @@ -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) => { diff --git a/test/regression/api/canary/admin/settings_spec.js b/test/regression/api/canary/admin/settings_spec.js index de8407904b..e7714f1d14 100644 --- a/test/regression/api/canary/admin/settings_spec.js +++ b/test/regression/api/canary/admin/settings_spec.js @@ -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'); });