From 1c094e66f7a26da37e9730a0c4c55e50e6dec3c7 Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 8 Aug 2020 20:37:23 +0100 Subject: [PATCH] validation only checks if there is something to check --- functions/index.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/functions/index.js b/functions/index.js index 35f49a3e5..cc5023412 100644 --- a/functions/index.js +++ b/functions/index.js @@ -380,7 +380,6 @@ function validateResult(result) { return false; } let wpm = roundTo2((result.correctChars * (60 / result.testDuration)) / 5); - let raw = roundTo2((result.allChars * (60 / result.testDuration)) / 5); if ( wpm < result.wpm - result.wpm * 0.01 || wpm > result.wpm + result.wpm * 0.01 @@ -390,15 +389,17 @@ function validateResult(result) { ); return false; } - - if ( - raw < result.rawWpm - result.rawWpm * 0.01 || - raw > result.rawWpm + result.rawWpm * 0.01 - ) { - console.error( - `Could not validate result for ${result.uid}. ${raw} != ${result.rawWpm}` - ); - return false; + if (result.allChars != undefined) { + let raw = roundTo2((result.allChars * (60 / result.testDuration)) / 5); + if ( + raw < result.rawWpm - result.rawWpm * 0.01 || + raw > result.rawWpm + result.rawWpm * 0.01 + ) { + console.error( + `Could not validate result for ${result.uid}. ${raw} != ${result.rawWpm}` + ); + return false; + } } return true; }