mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 07:16:17 +08:00
fix: leaderboard consistency being null (#5055)
This commit is contained in:
parent
29fce99ba3
commit
a72aa04c53
|
@ -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)));
|
||||
|
|
|
@ -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;}",
|
||||
|
|
|
@ -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>
|
||||
|
|
2
shared-types/types.d.ts
vendored
2
shared-types/types.d.ts
vendored
|
@ -445,7 +445,7 @@ declare namespace SharedTypes {
|
|||
acc: number;
|
||||
timestamp: number;
|
||||
raw: number;
|
||||
consistency: number | "-";
|
||||
consistency?: number;
|
||||
uid: string;
|
||||
name: string;
|
||||
discordId?: string;
|
||||
|
|
Loading…
Reference in a new issue