test(curriculum): challenge schema validator for lang
This commit is contained in:
		@@ -1,10 +1,7 @@
 | 
				
			|||||||
const Joi = require('joi');
 | 
					const Joi = require('joi');
 | 
				
			||||||
Joi.objectId = require('joi-objectid')(Joi);
 | 
					Joi.objectId = require('joi-objectid')(Joi);
 | 
				
			||||||
const path = require('path');
 | 
					 | 
				
			||||||
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const { LOCALE: lang = 'english' } = process.env;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function getSchemaForLang(lang) {
 | 
				
			||||||
  let schema = Joi.object().keys({
 | 
					  let schema = Joi.object().keys({
 | 
				
			||||||
    block: Joi.string(),
 | 
					    block: Joi.string(),
 | 
				
			||||||
    blockId: Joi.objectId(),
 | 
					    blockId: Joi.objectId(),
 | 
				
			||||||
@@ -22,8 +19,14 @@ let schema = Joi.object().keys({
 | 
				
			|||||||
        key: Joi.string(),
 | 
					        key: Joi.string(),
 | 
				
			||||||
        ext: Joi.string(),
 | 
					        ext: Joi.string(),
 | 
				
			||||||
        name: Joi.string(),
 | 
					        name: Joi.string(),
 | 
				
			||||||
      head: [Joi.array().items(Joi.string().allow('')), Joi.string().allow('')],
 | 
					        head: [
 | 
				
			||||||
      tail: [Joi.array().items(Joi.string().allow('')), Joi.string().allow('')],
 | 
					          Joi.array().items(Joi.string().allow('')),
 | 
				
			||||||
 | 
					          Joi.string().allow('')
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        tail: [
 | 
				
			||||||
 | 
					          Joi.array().items(Joi.string().allow('')),
 | 
				
			||||||
 | 
					          Joi.string().allow('')
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
        contents: [
 | 
					        contents: [
 | 
				
			||||||
          Joi.array().items(Joi.string().allow('')),
 | 
					          Joi.array().items(Joi.string().allow('')),
 | 
				
			||||||
          Joi.string().allow('')
 | 
					          Joi.string().allow('')
 | 
				
			||||||
@@ -78,7 +81,9 @@ if (lang !== 'english') {
 | 
				
			|||||||
      localeTitle: Joi.string().required()
 | 
					      localeTitle: Joi.string().required()
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  return schema;
 | 
				
			||||||
exports.validateChallenge = function validateChallenge(challenge) {
 | 
					}
 | 
				
			||||||
  return Joi.validate(challenge, schema);
 | 
					exports.challengeSchemaValidator = lang => {
 | 
				
			||||||
 | 
					  const schema = getSchemaForLang(lang);
 | 
				
			||||||
 | 
					  return challenge => Joi.validate(challenge, schema);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ const { getChallengesForLang } = require('../getChallenges');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const MongoIds = require('./utils/mongoIds');
 | 
					const MongoIds = require('./utils/mongoIds');
 | 
				
			||||||
const ChallengeTitles = require('./utils/challengeTitles');
 | 
					const ChallengeTitles = require('./utils/challengeTitles');
 | 
				
			||||||
const { validateChallenge } = require('../schema/challengeSchema');
 | 
					const { challengeSchemaValidator } = require('../schema/challengeSchema');
 | 
				
			||||||
const { challengeTypes } = require('../../client/utils/challengeTypes');
 | 
					const { challengeTypes } = require('../../client/utils/challengeTypes');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const { LOCALE: lang = 'english' } = process.env;
 | 
					const { LOCALE: lang = 'english' } = process.env;
 | 
				
			||||||
@@ -40,8 +40,9 @@ Mocha.Runner.prototype.fail = function(test, err) {
 | 
				
			|||||||
  return oldRunnerFail.call(this, test, err);
 | 
					  return oldRunnerFail.call(this, test, err);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let mongoIds = new MongoIds();
 | 
					const mongoIds = new MongoIds();
 | 
				
			||||||
let challengeTitles = new ChallengeTitles();
 | 
					const challengeTitles = new ChallengeTitles();
 | 
				
			||||||
 | 
					const validateChallenge = challengeSchemaValidator(lang);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const { JSDOM } = jsdom;
 | 
					const { JSDOM } = jsdom;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user