mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed newsletter schema column validation (#14456)
refs https://github.com/TryGhost/Team/issues/1500 - newsletter schema columns were using incorrect syntax for `isIn` validations - adds schema test to make sure schema `isIn` validations are in correct format
This commit is contained in:
parent
e5172facd6
commit
cb76b738ce
3 changed files with 29 additions and 8 deletions
|
@ -7,7 +7,7 @@ module.exports = recreateTable('newsletters', {
|
||||||
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||||
sender_name: {type: 'string', maxlength: 191, nullable: false},
|
sender_name: {type: 'string', maxlength: 191, nullable: false},
|
||||||
sender_email: {type: 'string', maxlength: 191, nullable: true},
|
sender_email: {type: 'string', maxlength: 191, nullable: true},
|
||||||
sender_reply_to: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'newsletter', validations: {isIn: ['newsletter', 'support']}},
|
sender_reply_to: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'newsletter', validations: {isIn: [['newsletter', 'support']]}},
|
||||||
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
|
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
|
||||||
visibility: {
|
visibility: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -20,10 +20,10 @@ module.exports = recreateTable('newsletters', {
|
||||||
header_image: {type: 'string', maxlength: 2000, nullable: true},
|
header_image: {type: 'string', maxlength: 2000, nullable: true},
|
||||||
show_header_icon: {type: 'bool', nullable: false, defaultTo: true},
|
show_header_icon: {type: 'bool', nullable: false, defaultTo: true},
|
||||||
show_header_title: {type: 'bool', nullable: false, defaultTo: true},
|
show_header_title: {type: 'bool', nullable: false, defaultTo: true},
|
||||||
title_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: ['serif', 'sans_serif']}},
|
title_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: [['serif', 'sans_serif']]}},
|
||||||
title_alignment: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'center', validations: {isIn: ['center', 'left']}},
|
title_alignment: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'center', validations: {isIn: [['center', 'left']]}},
|
||||||
show_feature_image: {type: 'bool', nullable: false, defaultTo: true},
|
show_feature_image: {type: 'bool', nullable: false, defaultTo: true},
|
||||||
body_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: ['serif', 'sans_serif']}},
|
body_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: [['serif', 'sans_serif']]}},
|
||||||
footer_content: {type: 'text', maxlength: 1000000000, nullable: true},
|
footer_content: {type: 'text', maxlength: 1000000000, nullable: true},
|
||||||
show_badge: {type: 'bool', nullable: false, defaultTo: true}
|
show_badge: {type: 'bool', nullable: false, defaultTo: true}
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@ module.exports = {
|
||||||
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||||
sender_name: {type: 'string', maxlength: 191, nullable: false},
|
sender_name: {type: 'string', maxlength: 191, nullable: false},
|
||||||
sender_email: {type: 'string', maxlength: 191, nullable: true},
|
sender_email: {type: 'string', maxlength: 191, nullable: true},
|
||||||
sender_reply_to: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'newsletter', validations: {isIn: ['newsletter', 'support']}},
|
sender_reply_to: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'newsletter', validations: {isIn: [['newsletter', 'support']]}},
|
||||||
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
|
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
|
||||||
visibility: {
|
visibility: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -28,10 +28,10 @@ module.exports = {
|
||||||
header_image: {type: 'string', maxlength: 2000, nullable: true},
|
header_image: {type: 'string', maxlength: 2000, nullable: true},
|
||||||
show_header_icon: {type: 'bool', nullable: false, defaultTo: true},
|
show_header_icon: {type: 'bool', nullable: false, defaultTo: true},
|
||||||
show_header_title: {type: 'bool', nullable: false, defaultTo: true},
|
show_header_title: {type: 'bool', nullable: false, defaultTo: true},
|
||||||
title_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: ['serif', 'sans_serif']}},
|
title_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: [['serif', 'sans_serif']]}},
|
||||||
title_alignment: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'center', validations: {isIn: ['center', 'left']}},
|
title_alignment: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'center', validations: {isIn: [['center', 'left']]}},
|
||||||
show_feature_image: {type: 'bool', nullable: false, defaultTo: true},
|
show_feature_image: {type: 'bool', nullable: false, defaultTo: true},
|
||||||
body_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: ['serif', 'sans_serif']}},
|
body_font_category: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'sans_serif', validations: {isIn: [['serif', 'sans_serif']]}},
|
||||||
footer_content: {type: 'text', maxlength: 1000000000, nullable: true},
|
footer_content: {type: 'text', maxlength: 1000000000, nullable: true},
|
||||||
show_badge: {type: 'bool', nullable: false, defaultTo: true}
|
show_badge: {type: 'bool', nullable: false, defaultTo: true}
|
||||||
},
|
},
|
||||||
|
|
21
test/unit/server/data/schema/schema.test.js
Normal file
21
test/unit/server/data/schema/schema.test.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
const should = require('should');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
const schema = require('../../../../../core/server/data/schema/schema');
|
||||||
|
|
||||||
|
describe('schema validations', function () {
|
||||||
|
it('has correct isIn validation structure', async function () {
|
||||||
|
const tablesOnlyValidation = _.cloneDeep(schema);
|
||||||
|
|
||||||
|
_.each(tablesOnlyValidation, function (table) {
|
||||||
|
_.each(table, function (column) {
|
||||||
|
const columnIsInValidation = _.get(column, 'validations.isIn');
|
||||||
|
// Check column's isIn validation is in correct format
|
||||||
|
if (columnIsInValidation) {
|
||||||
|
should(columnIsInValidation).be.Array().with.length(1);
|
||||||
|
should(columnIsInValidation[0]).be.Array();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue