not saving short tests

This commit is contained in:
Miodec 2021-02-06 19:13:26 +00:00
parent 978d944897
commit 5f73c476f4
3 changed files with 69 additions and 16 deletions

View file

@ -872,15 +872,13 @@ exports.verifyUser = functions.https.onRequest(async (request, response) => {
(await db.collection("users").where("discordId", "==", did).get())
.docs.length > 0
) {
response
.status(200)
.send({
data: {
status: -1,
message:
"This Discord account is already paired to a different Monkeytype account",
},
});
response.status(200).send({
data: {
status: -1,
message:
"This Discord account is already paired to a different Monkeytype account",
},
});
return;
}
@ -1255,7 +1253,8 @@ exports.testCompleted = functions.https.onRequest(async (request, response) => {
function verifyValue(val) {
let errCount = 0;
if (Array.isArray(val)) {
if (val === null || val === undefined) {
} else if (Array.isArray(val)) {
//array
val.forEach((val2) => {
errCount += verifyValue(val2);
@ -1271,8 +1270,6 @@ exports.testCompleted = functions.https.onRequest(async (request, response) => {
return errCount;
}
let errCount = verifyValue(obj);
// console.log(errCount);
if (errCount > 0) {
console.error(
`error saving result for ${
@ -1293,6 +1290,27 @@ exports.testCompleted = functions.https.onRequest(async (request, response) => {
response.status(200).send({ data: { resultCode: -1 } });
return;
}
if (
(obj.mode === "time" && obj.mode2 < 15) ||
(obj.mode === "words" && obj.mode2 < 10) ||
(obj.mode === "custom" &&
!obj.customText.isWordRandom &&
!obj.customText.isTimeRandom &&
obj.customText.textLen < 10) ||
(obj.mode === "custom" &&
obj.customText.isWordRandom &&
!obj.customText.isTimeRandom &&
obj.customText.word < 10) ||
(obj.mode === "custom" &&
!obj.customText.isWordRandom &&
obj.customText.isTimeRandom &&
obj.customText.time < 15)
) {
response
.status(200)
.send({ data: { resultCode: -5, message: "Test too short" } });
return;
}
if (!validateResult(obj)) {
if (
obj.bailedOut &&

View file

@ -2123,6 +2123,23 @@ function showResult(difficultyFailed = false) {
Notifications.add("Test invalid - AFK detected", 0);
} else if (sameWordset) {
Notifications.add("Test invalid - repeated", 0);
} else if (
(config.mode === "time" && mode2 < 15) ||
(config.mode === "words" && mode2 < 10) ||
(config.mode === "custom" &&
!customText.isWordRandom &&
!customText.isTimeRandom &&
customText.text.length < 10) ||
(config.mode === "custom" &&
customText.isWordRandom &&
!customText.isTimeRandom &&
customText.word < 10) ||
(config.mode === "custom" &&
!customText.isWordRandom &&
customText.isTimeRandom &&
customText.time < 15)
) {
Notifications.add("Test too short", 0);
} else {
let activeTags = [];
let activeTagsIds = [];
@ -2154,6 +2171,16 @@ function showResult(difficultyFailed = false) {
quoteLength = randomQuote.group;
}
let cdata = null;
if (config.mode === "custom") {
cdata = {};
cdata.textLen = customText.text.length;
cdata.isWordRandom = customText.isWordRandom;
cdata.isTimeRandom = customText.isTimeRandom;
cdata.word = customText.word !== "" ? customText.word : null;
cdata.time = customText.time !== "" ? customText.time : null;
}
let completedEvent = {
wpm: stats.wpm,
rawWpm: stats.wpmRaw,
@ -2183,7 +2210,13 @@ function showResult(difficultyFailed = false) {
funbox: activeFunBox,
bailedOut: bailout,
chartData: chartData,
customText: cdata,
};
if (config.mode !== "custom") {
delete completedEvent.customText;
}
if (
config.difficulty == "normal" ||
((config.difficulty == "master" || config.difficulty == "expert") &&
@ -2379,6 +2412,8 @@ function showResult(difficultyFailed = false) {
"Result data does not make sense. Result not saved.",
-1
);
} else if (e.data.resultCode === -5) {
Notifications.add("Test too short. Result not saved.", -1);
} else if (e.data.resultCode === -999) {
console.error("internal error: " + e.data.message);
Notifications.add(

View file

@ -505,8 +505,8 @@
"textColor": "#575279"
},
{
"name": "copper",
"bgColor": "#442f29",
"textColor": "#e7e0de"
}
"name": "copper",
"bgColor": "#442f29",
"textColor": "#e7e0de"
}
]