fix: leaderboard consistency being null (#5055)

This commit is contained in:
Christian Fehmer 2024-02-14 23:28:51 +01:00 committed by GitHub
parent 29fce99ba3
commit a72aa04c53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 7 deletions

View file

@ -103,6 +103,28 @@ describe("LeaderboardsDal", () => {
expect(lb[0]).not.toHaveProperty("discordAvatar");
});
it("should remove consistency from results if null", async () => {
//GIVEN
const stats = pb(100, 90, 2);
//@ts-ignore
stats["consistency"] = undefined;
await createUser(lbBests(stats));
//WHEN
//WHEN
await LeaderboardsDal.update("time", "15", "english");
const lb = (await LeaderboardsDal.get(
"time",
"15",
"english",
0
)) as SharedTypes.LeaderboardEntry[];
//THEN
expect(lb[0]).not.toHaveProperty("consistency");
});
it("should update public speedHistogram for time english 15", async () => {
//GIVEN
const rank1 = await createUser(lbBests(pb(10), pb(60)));

View file

@ -131,6 +131,9 @@ export async function update(
[`${key}.discordAvatar`]: {
$ifNull: ["$discordAvatar", "$$REMOVE"],
},
[`${key}.consistency`]: {
$ifNull: [`$${key}.consistency`, "$$REMOVE"],
},
[`${key}.rank`]: {
$function: {
body: "function() {try {row_number+= 1;} catch (e) {row_number= 1;}return row_number;}",

View file

@ -214,9 +214,7 @@ function updateFooter(lb: LbKey): void {
<div class="sub">${entry.acc.toFixed(2)}%</div></td>
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.raw).toFixed(2)}<br>
<div class="sub">${
entry.consistency === undefined || entry.consistency === "-"
? "-"
: entry.consistency.toFixed(2) + "%"
entry.consistency === undefined ? "-" : entry.consistency.toFixed(2) + "%"
}</div></td>
<td class="alignRight">${format(date, "dd MMM yyyy")}<br>
<div class='sub'>${format(date, "HH:mm")}</div></td>
@ -341,9 +339,7 @@ async function fillTable(lb: LbKey): Promise<void> {
<div class="sub">${entry.acc.toFixed(2)}%</div></td>
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.raw).toFixed(2)}<br>
<div class="sub">${
entry.consistency === undefined || entry.consistency === "-"
? "-"
: entry.consistency.toFixed(2) + "%"
entry.consistency === undefined ? "-" : entry.consistency.toFixed(2) + "%"
}</div></td>
<td class="alignRight">${format(date, "dd MMM yyyy")}<br>
<div class='sub'>${format(date, "HH:mm")}</div></td>

View file

@ -445,7 +445,7 @@ declare namespace SharedTypes {
acc: number;
timestamp: number;
raw: number;
consistency: number | "-";
consistency?: number;
uid: string;
name: string;
discordId?: string;