From 8a78e2b4621dc5974e5af8f11dcb4834ff7d1db5 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sat, 17 Sep 2022 22:18:50 +0200 Subject: [PATCH] added bailed out test too short validation --- backend/src/utils/validation.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/src/utils/validation.ts b/backend/src/utils/validation.ts index 543f228b8..ec123ae47 100644 --- a/backend/src/utils/validation.ts +++ b/backend/src/utils/validation.ts @@ -56,18 +56,24 @@ export function isTagPresetNameValid(name: string): boolean { } export function isTestTooShort(result: MonkeyTypes.CompletedEvent): boolean { - const { mode, mode2, customText, testDuration } = result; + const { mode, mode2, customText, testDuration, bailedOut } = result; if (mode === "time") { const setTimeTooShort = mode2 > 0 && mode2 < 15; const infiniteTimeTooShort = mode2 === 0 && testDuration < 15; - return setTimeTooShort || infiniteTimeTooShort; + const bailedOutTooShort = bailedOut + ? bailedOut && testDuration < 15 + : false; + return setTimeTooShort || infiniteTimeTooShort || bailedOutTooShort; } if (mode === "words") { const setWordTooShort = mode2 > 0 && mode2 < 10; const infiniteWordTooShort = mode2 === 0 && testDuration < 15; - return setWordTooShort || infiniteWordTooShort; + const bailedOutTooShort = bailedOut + ? bailedOut && testDuration < 15 + : false; + return setWordTooShort || infiniteWordTooShort || bailedOutTooShort; } if (mode === "custom") { @@ -77,7 +83,15 @@ export function isTestTooShort(result: MonkeyTypes.CompletedEvent): boolean { !isWordRandom && !isTimeRandom && _.isNumber(textLen) && textLen < 10; const randomWordsTooShort = isWordRandom && !isTimeRandom && word < 10; const randomTimeTooShort = !isWordRandom && isTimeRandom && time < 15; - return setTextTooShort || randomWordsTooShort || randomTimeTooShort; + const bailedOutTooShort = bailedOut + ? bailedOut && testDuration < 15 + : false; + return ( + setTextTooShort || + randomWordsTooShort || + randomTimeTooShort || + bailedOutTooShort + ); } if (mode === "zen") {