Players get a fast TTL-backed homepage (local profile / Cloudflare D1) with dense UI polish; login unlocks /home without blocking on every OpenDota refresh. Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
/** Node smoke tests for Worker stats helpers (no wrangler). */
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
aggregateFromRows,
|
|
careerFromOpenDota,
|
|
kda,
|
|
mergeAvailability,
|
|
winrate,
|
|
} from "./src/stats.js";
|
|
|
|
assert.equal(kda(10, 0, 5), 15);
|
|
assert.equal(winrate(0, 0), null);
|
|
assert.equal(winrate(1, 1), 50);
|
|
|
|
const emptyCareer = careerFromOpenDota({ win: 0, lose: 0 }, []);
|
|
assert.equal(emptyCareer, null);
|
|
|
|
const career = careerFromOpenDota(
|
|
{ win: 2, lose: 1 },
|
|
[
|
|
{ field: "kills", sum: 30, n: 3 },
|
|
{ field: "deaths", sum: 6, n: 3 },
|
|
{ field: "assists", sum: 15, n: 3 },
|
|
]
|
|
);
|
|
assert.equal(career.games, 3);
|
|
assert.equal(career.winrate, 66.7);
|
|
assert.ok(career.kda > 0);
|
|
|
|
const recent = aggregateFromRows(
|
|
[
|
|
{ match_id: 1, won: true, kills: 5, deaths: 1, assists: 3, gpm: 500 },
|
|
{ match_id: 1, won: true, kills: 5, deaths: 1, assists: 3, gpm: 500 }, // duplicate row ok in unit
|
|
{ match_id: 2, won: false, kills: 0, deaths: 0, assists: 2, gpm: 400 },
|
|
],
|
|
20
|
|
);
|
|
assert.equal(recent.sample, 3);
|
|
assert.equal(recent.wins, 2);
|
|
|
|
const syncing = mergeAvailability({
|
|
opendotaRecentN: 0,
|
|
career: null,
|
|
steamHistoryStatus: 1,
|
|
fetchedAt: "2026-07-31T00:00:00Z",
|
|
});
|
|
assert.equal(syncing.status, "syncing");
|
|
assert.match(syncing.note, /OpenDota/);
|
|
|
|
const priv = mergeAvailability({
|
|
opendotaRecentN: 0,
|
|
career: null,
|
|
steamHistoryStatus: 15,
|
|
fetchedAt: "2026-07-31T00:00:00Z",
|
|
});
|
|
assert.equal(priv.status, "private");
|
|
|
|
console.log("stats.js ok");
|