From 99c20f92b4079709d6eebdb9a4677ebbebc00dc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me>
Date: Wed, 9 Aug 2023 19:18:54 +0200
Subject: [PATCH] ExerciceHelper => Add possibility to pass file or string to
 result file validation

---
 helpers/ExerciceHelper.ts | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/helpers/ExerciceHelper.ts b/helpers/ExerciceHelper.ts
index c6ff93b..190a9bc 100644
--- a/helpers/ExerciceHelper.ts
+++ b/helpers/ExerciceHelper.ts
@@ -5,9 +5,7 @@ import JSON5                               from 'json5';
 
 
 class ExerciceHelper {
-    validateResultFile(resultsFilePath: string): {
-        results: ExerciceResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject<string, Record<string, any>, unknown> | string> | null | undefined
-    } {
+    validateResultFile(resultsFilePathOrStr: string, isFile: boolean = true): { results: ExerciceResultsFile | undefined, isValid: boolean, errors: Array<ErrorObject<string, Record<string, any>, unknown> | string> | null | undefined } {
         const ajv = new Ajv();
 
         const schema: JTDSchemaType<ExerciceResultsFile> = {
@@ -35,7 +33,7 @@ class ExerciceHelper {
         const validator = ajv.compile(schema);
 
         try {
-            const results = JSON5.parse(fs.readFileSync(resultsFilePath, 'utf8'));
+            const results = JSON5.parse(isFile ? fs.readFileSync(resultsFilePathOrStr, 'utf8') : resultsFilePathOrStr);
             const isValid = validator(results);
 
             return {
-- 
GitLab