Fix leaderboard update bug (#3217)

* Fix leaderboard update bug

* Add test for sanitize string
This commit is contained in:
Bruce Berrios 2022-06-24 05:16:53 -04:00 committed by GitHub
parent 9231250afd
commit b0b39c7dc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View file

@ -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);
});
});
});

View file

@ -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;