Skip to content

Commit

Permalink
Smush the leaderboard (#28)
Browse files Browse the repository at this point in the history
* Smush leaderboard

* Update tests
  • Loading branch information
enkoder authored Jul 15, 2024
1 parent f473df0 commit 29164fa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 2 additions & 0 deletions api/src/models/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export class Results {
"tournaments.players_count as players_count",
"tournaments.format as format",
])
// Only fetch results for non-disabled users
.where("users.disabled", "=", 0)
.select((eb) => [
eb.fn
.agg<number>("rank")
Expand Down
7 changes: 2 additions & 5 deletions api/src/tests/leaderboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ describe("leaderboard", () => {
const rows = (await response.json()) as LeaderboardRowComponentType[];

expect(rows[0].rank).toEqual(1);
expect(rows[0].user_id).toEqual(0);
expect(rows[0].user_name).toEqual(null);

expect(rows[1].rank).toEqual(2);
expect(rows[1].user_id).toEqual(u1.id);
expect(rows[0].user_id).toEqual(1);
expect(rows.length).toEqual(1);
});
});
8 changes: 2 additions & 6 deletions api/src/tests/tournaments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ describe("tournaments", () => {
expect(data[0].rank_cut).toBe(1);
expect(data[0].rank_swiss).toBe(1);

// Disabled user
expect(data[1].user_id).toBe(0);
expect(data[1].user_name).toBe(null);
expect(data[1].points_earned).toBe(50);
expect(data[1].rank_cut).toBe(2);
expect(data[1].rank_swiss).toBe(2);
// Disabled user should not be in this list
expect(data.length).toBe(1);
});
});

0 comments on commit 29164fa

Please sign in to comment.