diff --git a/types/Dojo/ExerciseResultsFile.ts b/types/Dojo/ExerciseResultsFile.ts index 9cb95b71cd46f753a9672b949998f24c1c2c967c..9f70eff8ab23cafc0c4a1ba26b8c97c3efd6271b 100644 --- a/types/Dojo/ExerciseResultsFile.ts +++ b/types/Dojo/ExerciseResultsFile.ts @@ -1,14 +1,39 @@ -interface ExerciseResultsFile { - success?: boolean; +import Icon from '../Icon'; +import { z } from 'zod'; - containerExitCode?: number; - successfulTests?: number; - failedTests?: number; +const ExerciseResultsFile = z.object({ + success: z.boolean().optional(), - successfulTestsList?: Array<string>; - failedTestsList?: Array<string>; -} + containerExitCode: z.number().optional(), + + successfulTests: z.number().optional(), + failedTests : z.number().optional(), + + successfulTestsList: z.array(z.string()).optional(), + failedTestsList : z.array(z.string()).optional(), + + otherInformations: z.array(z.object({ + name : z.string(), + description : z.string().optional(), + icon : z.enum(Object.keys(Icon) as [ firstKey: string, ...otherKeys: Array<string> ]).optional().transform(value => value ? (Icon as { [index: string]: string })[value] : undefined), + itemsOrInformations: z.union([ z.array(z.string()), z.string() ]) + })) + .optional() + }).strict().transform(value => { + if ( value.successfulTests === undefined && value.successfulTestsList !== undefined ) { + value.successfulTests = value.successfulTestsList.length; + } + + if ( value.failedTests === undefined && value.failedTestsList !== undefined ) { + value.failedTests = value.failedTestsList.length; + } + + return value; +}); + + +type ExerciseResultsFile = z.infer<typeof ExerciseResultsFile>; export default ExerciseResultsFile; \ No newline at end of file