From 653629f8db0379bd3f71fe26d09fbe2f757a8ce9 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Sat, 16 Nov 2024 11:14:35 +0100 Subject: [PATCH] fix: better meta validation errors (#57180) --- curriculum/schema/meta-schema.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/curriculum/schema/meta-schema.js b/curriculum/schema/meta-schema.js index 1ec986196538fe..4cd80951870d5b 100644 --- a/curriculum/schema/meta-schema.js +++ b/curriculum/schema/meta-schema.js @@ -1,5 +1,7 @@ const Joi = require('joi'); +const { SuperBlocks } = require('../../shared/config/curriculum'); + const slugRE = new RegExp('^[a-z0-9-]+$'); const slugWithSlashRE = new RegExp('^[a-z0-9-/]+$'); @@ -25,7 +27,10 @@ const schema = Joi.object() ), isUpcomingChange: Joi.boolean().required(), dashedName: Joi.string().regex(slugRE).required(), - superBlock: Joi.string().regex(slugWithSlashRE).required(), + superBlock: Joi.string() + .regex(slugWithSlashRE) + .valid(...Object.values(SuperBlocks)) + .required(), order: Joi.number().when('superBlock', { is: 'full-stack-developer', then: Joi.forbidden(), @@ -73,5 +78,5 @@ const schema = Joi.object() .unknown(false); exports.metaSchemaValidator = meta => { - return schema.validate(meta); + return schema.validate(meta, { abortEarly: false }); };