diff options
author | Christian Fehmer <[email protected]> | 2024-02-14 23:28:51 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-14 23:28:51 +0100 |
commit | a72aa04c53df019d5936b17023ff5034ffe31e50 (patch) | |
tree | a88635c296681d0ec707e6c0bbe4d544e1e83c01 | |
parent | 29fce99ba3e8915fdeeb576533ada7c98094ece4 (diff) | |
download | monkeytype-a72aa04c53df019d5936b17023ff5034ffe31e50.tar.gz monkeytype-a72aa04c53df019d5936b17023ff5034ffe31e50.zip |
fix: leaderboard consistency being null (#5055)
-rw-r--r-- | backend/__tests__/dal/leaderboards.spec.ts | 22 | ||||
-rw-r--r-- | backend/src/dal/leaderboards.ts | 3 | ||||
-rw-r--r-- | frontend/src/ts/elements/leaderboards.ts | 8 | ||||
-rw-r--r-- | shared-types/types.d.ts | 2 |
4 files changed, 28 insertions, 7 deletions
diff --git a/backend/__tests__/dal/leaderboards.spec.ts b/backend/__tests__/dal/leaderboards.spec.ts index b5dbdae43..a49ea06f7 100644 --- a/backend/__tests__/dal/leaderboards.spec.ts +++ b/backend/__tests__/dal/leaderboards.spec.ts @@ -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))); diff --git a/backend/src/dal/leaderboards.ts b/backend/src/dal/leaderboards.ts index 47d148926..81669f98c 100644 --- a/backend/src/dal/leaderboards.ts +++ b/backend/src/dal/leaderboards.ts @@ -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;}", diff --git a/frontend/src/ts/elements/leaderboards.ts b/frontend/src/ts/elements/leaderboards.ts index 5fe917aa1..b37b9b8f4 100644 --- a/frontend/src/ts/elements/leaderboards.ts +++ b/frontend/src/ts/elements/leaderboards.ts @@ -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> diff --git a/shared-types/types.d.ts b/shared-types/types.d.ts index 6447d7a73..f54e0e662 100644 --- a/shared-types/types.d.ts +++ b/shared-types/types.d.ts @@ -445,7 +445,7 @@ declare namespace SharedTypes { acc: number; timestamp: number; raw: number; - consistency: number | "-"; + consistency?: number; uid: string; name: string; discordId?: string; |