mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-03 12:29:46 +08:00
added quote length validation
This commit is contained in:
parent
65f2f369bf
commit
a4ff6cbaab
1 changed files with 24 additions and 0 deletions
|
@ -344,6 +344,8 @@ function validateQuotes() {
|
|||
let quoteFilesErrors;
|
||||
let quoteIdsAllGood = true;
|
||||
let quoteIdsErrors;
|
||||
let quoteLengthsAllGood = true;
|
||||
let quoteLengthErrors = [];
|
||||
const quotesFiles = fs.readdirSync("./static/quotes/");
|
||||
quotesFiles.forEach((quotefilename) => {
|
||||
quotefilename = quotefilename.split(".")[0];
|
||||
|
@ -375,6 +377,22 @@ function validateQuotes() {
|
|||
quoteIdsAllGood = false;
|
||||
quoteIdsErrors = quoteIdsValidator.errors;
|
||||
}
|
||||
const incorrectQuoteLength = quoteData.quotes
|
||||
.filter((quote) => quote.text.length !== quote.length)
|
||||
.map((quote) => quote.id);
|
||||
if (incorrectQuoteLength.length !== 0) {
|
||||
console.log(
|
||||
`Quote ${quotefilename} ID(s) ${incorrectQuoteLength.join(
|
||||
","
|
||||
)} length fields are \u001b[31mincorrect\u001b[0m`
|
||||
);
|
||||
quoteFilesAllGood = false;
|
||||
incorrectQuoteLength.map((id) => {
|
||||
quoteLengthErrors.push(
|
||||
`${quotefilename} ${id} length field is incorrect`
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (quoteFilesAllGood) {
|
||||
console.log(`Quote file JSON schemas are \u001b[32mvalid\u001b[0m`);
|
||||
|
@ -388,6 +406,12 @@ function validateQuotes() {
|
|||
console.log(`Quote IDs are \u001b[31mnot unique\u001b[0m`);
|
||||
return reject(new Error(quoteIdsErrors));
|
||||
}
|
||||
if (quoteLengthsAllGood) {
|
||||
console.log(`Quote length fields are \u001b[32mcorrect\u001b[0m`);
|
||||
} else {
|
||||
console.log(`Quote length fields are \u001b[31mincorrect\u001b[0m`);
|
||||
return reject(new Error(quoteLengthErrors));
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue