mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-24 06:48:02 +08:00
Fix leaderboard update bug (#3217)
* Fix leaderboard update bug * Add test for sanitize string
This commit is contained in:
parent
9231250afd
commit
b0b39c7dc5
2 changed files with 39 additions and 2 deletions
|
|
@ -168,4 +168,41 @@ describe("Misc Utils", () => {
|
|||
expect(misc.flattenObjectDeep(obj)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it("sanitizeString", () => {
|
||||
const testCases = [
|
||||
{
|
||||
input: "h̶̼͔̭͈̏́̀́͋͜ͅe̵̺̞̦̫̫͔̋́̅̅̃̀͝͝ļ̶̬̯͚͇̺͍̞̫̟͖͋̓͛̆̒̓͜ĺ̴̗̘͇̬̆͂͌̈͊͝͝ỡ̴̡̦̩̠̞̐̃͆̚͠͝",
|
||||
expected: "hello",
|
||||
},
|
||||
{
|
||||
input: "hello",
|
||||
expected: "hello",
|
||||
},
|
||||
{
|
||||
input: "hel lo",
|
||||
expected: "hel lo",
|
||||
},
|
||||
{
|
||||
input: " hel lo ",
|
||||
expected: "hel lo",
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
input: " \n\n\n",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
expected: undefined,
|
||||
},
|
||||
];
|
||||
|
||||
testCases.forEach(({ input, expected }) => {
|
||||
expect(misc.sanitizeString(input)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ export async function update(
|
|||
const str = `lbPersonalBests.${mode}.${mode2}.${language}`;
|
||||
const start1 = performance.now();
|
||||
const lb = await db
|
||||
.collection<MonkeyTypes.LeaderboardEntry>("users")
|
||||
.collection<MonkeyTypes.User>("users")
|
||||
.aggregate<MonkeyTypes.LeaderboardEntry>(
|
||||
[
|
||||
{
|
||||
|
|
@ -120,7 +120,7 @@ export async function update(
|
|||
}
|
||||
|
||||
// extract selected badge
|
||||
if (lbEntry.badges) {
|
||||
if (lbEntry.badges?.length) {
|
||||
lbEntry.badgeId = lbEntry.badges.filter(
|
||||
(badge) => badge.selected === true
|
||||
)[0].id;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue