0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05: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) => { module.exports.forSettings = (attrs, frame) => {
const _ = require('lodash'); const _ = require('lodash');
const mapGroupToType = require('./settings-type-group-mapper');
// @TODO: https://github.com/TryGhost/Ghost/issues/10106 // @TODO: https://github.com/TryGhost/Ghost/issues/10106
// @NOTE: Admin & Content API return a different format, needs two mappers // @NOTE: Admin & Content API return a different format, needs two mappers
if (_.isArray(attrs)) { if (_.isArray(attrs)) {
attrs.forEach((attr) => {
attr.type = mapGroupToType(attr.group);
});
// CASE: read single setting // CASE: read single setting
if (frame.original.params && frame.original.params.key) { if (frame.original.params && frame.original.params.key) {
if (frame.original.params.key === 'ghost_head') { 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', amp: 'blog',
labs: 'blog', labs: 'blog',
slack: 'blog', slack: 'blog',
site: 'blog',
unsplash: 'blog', unsplash: 'blog',
views: 'blog', views: 'blog',
theme: 'theme', theme: 'theme',
members: 'members', members: 'members',
private: 'private', private: 'private',
portal: 'portal', portal: 'portal',
email: 'bulk_email', email: 'bulk_email'
site: 'site'
}; };
const mapGroupToType = (group) => { 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. // 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. // Have put a list as is here for the lack of better place for it.
const defaultSettingsKeys = [ const defaultSettingsKeyTypes = [
'title', {key: 'title',type: 'blog'},
'description', {key: 'description',type: 'blog'},
'logo', {key: 'logo',type: 'blog'},
'cover_image', {key: 'cover_image',type: 'blog'},
'icon', {key: 'icon',type: 'blog'},
'lang', {key: 'lang',type: 'blog'},
'timezone', {key: 'timezone',type: 'blog'},
'codeinjection_head', {key: 'codeinjection_head',type: 'blog'},
'codeinjection_foot', {key: 'codeinjection_foot',type: 'blog'},
'facebook', {key: 'facebook',type: 'blog'},
'twitter', {key: 'twitter',type: 'blog'},
'navigation', {key: 'navigation',type: 'blog'},
'secondary_navigation', {key: 'secondary_navigation',type: 'blog'},
'meta_title', {key: 'meta_title',type: 'blog'},
'meta_description', {key: 'meta_description',type: 'blog'},
'og_image', {key: 'og_image',type: 'blog'},
'og_title', {key: 'og_title',type: 'blog'},
'og_description', {key: 'og_description',type: 'blog'},
'twitter_image', {key: 'twitter_image',type: 'blog'},
'twitter_title', {key: 'twitter_title',type: 'blog'},
'twitter_description', {key: 'twitter_description',type: 'blog'},
'active_theme', {key: 'active_theme',type: 'theme'},
'is_private', {key: 'is_private',type: 'private'},
'password', {key: 'password',type: 'private'},
'public_hash', {key: 'public_hash',type: 'private'},
'default_content_visibility', {key: 'default_content_visibility',type: 'members'},
'members_subscription_settings', {key: 'members_subscription_settings',type: 'members'},
'stripe_connect_integration', {key: 'stripe_connect_integration',type: 'members'},
'portal_name', {key: 'portal_name',type: 'portal'},
'portal_button', {key: 'portal_button',type: 'portal'},
'portal_plans', {key: 'portal_plans',type: 'portal'},
'bulk_email_settings', {key: 'bulk_email_settings',type: 'bulk_email'},
'amp', {key: 'amp',type: 'blog'},
'labs', {key: 'labs',type: 'blog'},
'slack', {key: 'slack',type: 'blog'},
'unsplash', {key: 'unsplash',type: 'blog'},
'shared_views', {key: 'shared_views',type: 'blog'},
'active_timezone', {key: 'active_timezone',type: 'blog'},
'default_locale' {key: 'default_locale',type: 'blog'}
]; ];
describe('Settings API (canary)', function () { describe('Settings API (canary)', function () {
@ -83,7 +83,7 @@ describe('Settings API (canary)', function () {
const settings = jsonResponse.settings; const settings = jsonResponse.settings;
Object.keys(settings).length.should.equal(39); 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'); localUtils.API.checkResponse(jsonResponse, 'settings');
}); });