diff --git a/helpers/Dojo/SharedExerciseHelper.ts b/helpers/Dojo/SharedExerciseHelper.ts index e99fe0a302e41a28df5cafab292974b2fdb96b43..97ccf7c9a39682ba8b14fa65b54a89d9898ebf3c 100644 --- a/helpers/Dojo/SharedExerciseHelper.ts +++ b/helpers/Dojo/SharedExerciseHelper.ts @@ -1,67 +1,4 @@ -import Ajv, { ErrorObject, JTDSchemaType } from 'ajv/dist/jtd'; -import fs from 'fs'; -import ExerciseResultsFile from '../../types/Dojo/ExerciseResultsFile'; -import JSON5 from 'json5'; - - -class SharedExerciseHelper { - validateResultFile(resultsFilePathOrStr: string, isFile: boolean = true): { results: ExerciseResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject | string> | null | undefined } { - const ajv = new Ajv(); - - const schema: JTDSchemaType<ExerciseResultsFile> = { - properties : {}, - optionalProperties : { - success: { type: 'boolean' }, - - containerExitCode: { type: 'uint32' }, - - successfulTests: { type: 'uint32' }, - failedTests : { type: 'uint32' }, - - successfulTestsList: { - elements: { - type: 'string' - } - }, - failedTestsList : { - elements: { - type: 'string' - } - } - }, - additionalProperties: false - }; - - const validator = ajv.compile(schema); - - try { - const results = JSON5.parse(isFile ? fs.readFileSync(resultsFilePathOrStr, 'utf8') : resultsFilePathOrStr); - const isValid = validator(results); - - if ( isValid ) { - if ( results.successfulTests === undefined && results.successfulTestsList !== undefined ) { - results.successfulTests = results.successfulTestsList.length; - } - - if ( results.failedTests === undefined && results.failedTestsList !== undefined ) { - results.failedTests = results.failedTestsList.length; - } - } - - return { - results: isValid ? results : results as ExerciseResultsFile, - isValid: isValid, - errors : validator.errors - }; - } catch ( error ) { - return { - results: undefined, - isValid: false, - errors : [ `JSON5 invalid : ${ JSON.stringify(error) }` ] - }; - } - } -} +class SharedExerciseHelper {} export default new SharedExerciseHelper(); \ No newline at end of file