diff --git a/helpers/Dojo/AssignmentValidator.ts b/helpers/Dojo/AssignmentValidator.ts index 5371665eb43108dbd73cac911c617394d06bd196..6ecec2ccefd9f71051d4334a9f5c20c51d35cce1 100644 --- a/helpers/Dojo/AssignmentValidator.ts +++ b/helpers/Dojo/AssignmentValidator.ts @@ -4,7 +4,6 @@ import SharedAssignmentHelper from '../../../shared/helpers/Dojo/SharedAssign import path from 'node:path'; import AssignmentCheckerError from '../../../shared/types/Dojo/AssignmentCheckerError'; import fs from 'fs-extra'; -import JSON5 from 'json5'; import ClientsSharedConfig from '../../config/ClientsSharedConfig'; import YAML from 'yaml'; import DojoDockerCompose from '../../types/Dojo/DojoDockerCompose'; @@ -133,16 +132,16 @@ class AssignmentValidator { this.newSubStep('ASSIGNMENT_FILE_SCHEMA_VALIDATION', 'Validating dojo_assignment.json file schema'); const validationResults = SharedAssignmentHelper.validateDescriptionFile(path.join(this.folderAssignment, ClientsSharedConfig.assignment.filename)); if ( !validationResults.isValid ) { - this.emitError(`dojo_assignment.json file schema is invalid.\nHere are the errors:\n${ JSON5.stringify(validationResults.errors) }`, 'dojo_assignment.json file is invalid', AssignmentCheckerError.ASSIGNMENT_FILE_SCHEMA_ERROR); + this.emitError(`dojo_assignment.json file schema is invalid.\nHere are the errors:\n${ validationResults.error }`, 'dojo_assignment.json file is invalid', AssignmentCheckerError.ASSIGNMENT_FILE_SCHEMA_ERROR); return; } - assignmentFile = validationResults.results!; + assignmentFile = validationResults.content!; this.endSubStep('dojo_assignment.json file schema is valid', false); // Immutable files validation (Check if exists and if the given type is correct) this.newSubStep('ASSIGNMENT_FILE_IMMUTABLES_VALIDATION', 'Validating immutable files'); - for ( const immutable of validationResults.results!.immutable ) { + for ( const immutable of validationResults.content!.immutable ) { const immutablePath = path.join(this.folderAssignment, immutable.path); if ( !fs.existsSync(immutablePath) ) { this.emitError(`Immutable path not found: ${ immutable.path }`, 'dojo_assignment.json file is invalid', AssignmentCheckerError.IMMUTABLE_PATH_NOT_FOUND); diff --git a/helpers/Dojo/ExerciseResultsSanitizerAndValidator.ts b/helpers/Dojo/ExerciseResultsSanitizerAndValidator.ts index 37217d4349ea0eea9421b50edc68fb41e4965e63..8a1ec41c241c1e3c757726723dd7509440689b12 100644 --- a/helpers/Dojo/ExerciseResultsSanitizerAndValidator.ts +++ b/helpers/Dojo/ExerciseResultsSanitizerAndValidator.ts @@ -2,12 +2,12 @@ import { TypedEmitter } from 'tiny-typed-emitter'; import ExerciseRunningEvents from '../../types/Dojo/ExerciseRunningEvents'; import ExerciseCheckerError from '../../../shared/types/Dojo/ExerciseCheckerError'; import path from 'node:path'; -import SharedExerciseHelper from '../../../shared/helpers/Dojo/SharedExerciseHelper'; import ClientsSharedConfig from '../../config/ClientsSharedConfig'; import Toolbox from '../../../shared/helpers/Toolbox'; import * as fs from 'fs-extra'; import ExerciseResultsFile from '../../../shared/types/Dojo/ExerciseResultsFile'; import JSON5 from 'json5'; +import Json5FileValidator from '../../../shared/helpers/Json5FileValidator'; class ExerciseResultsSanitizerAndValidator { @@ -37,13 +37,13 @@ class ExerciseResultsSanitizerAndValidator { // Results file schema validation { this.events.emit('step', 'VALIDATE_RESULTS_FILE', 'Validating results file schema'); - const validationResults = SharedExerciseHelper.validateResultFile(path); + const validationResults = Json5FileValidator.validateFile(ExerciseResultsFile, path); if ( !validationResults.isValid ) { - this.events.emit('endStep', 'VALIDATE_RESULTS_FILE', `Results file is not valid. Here are the errors :\n${ JSON.stringify(validationResults.errors) }`, true); + this.events.emit('endStep', 'VALIDATE_RESULTS_FILE', `Results file is not valid. Here are the errors :\n${ validationResults.error }`, true); this.events.emit('finished', false, ExerciseCheckerError.EXERCISE_RESULTS_FILE_SCHEMA_NOT_VALID); return false; } - this.exerciseResults = validationResults.results ?? {}; + this.exerciseResults = validationResults.content ?? {}; this.events.emit('endStep', 'VALIDATE_RESULTS_FILE', 'Results file is valid', false); }