Files
miti99bot/tests/modules/loldle/lookup.test.js
T
tiennm99 1e01437766 feat(loldle): port classic-mode game from loldle repo
Adds loldle module with classic-mode champion guessing. Ports comparison
logic from tiennm99/loldle (lib/classic-mode.js) and bundles champion
data from tiennm99/loldle-data. Adds GH Actions workflow that re-syncs
champions.json on cross-repo dispatch from loldle-data.

- Three public commands: /loldle, /loldle_giveup, /loldle_stats
- Per-user daily state + streak stats in KV (3-day TTL on games)
- champions-data.js wrapper sidesteps Node 24 / esbuild disagreement on
  JSON import attributes; generator script + npm run build:loldle-data
- register script now tolerates missing .env.deploy (env-file-if-exists)
  so Workers Builds can inject env vars directly
- fix(scripts): escape stray */ in migrate.js docstring that broke node
- 16 new unit tests (compare, daily, lookup); dispatcher test updated
  for the new command set
2026-04-20 17:10:08 +07:00

37 lines
1.2 KiB
JavaScript

import { describe, expect, it } from "vitest";
import { findChampion } from "../../../src/modules/loldle/lookup.js";
const champions = [
{ id: "Aatrox", name: "Aatrox" },
{ id: "Ahri", name: "Ahri" },
{ id: "KhaZix", name: "Kha'Zix" },
{ id: "MissFortune", name: "Miss Fortune" },
];
describe("findChampion", () => {
it("matches by exact id (case-insensitive)", () => {
expect(findChampion(champions, "aatrox").id).toBe("Aatrox");
expect(findChampion(champions, "AATROX").id).toBe("Aatrox");
});
it("normalizes punctuation and spaces", () => {
expect(findChampion(champions, "kha'zix").id).toBe("KhaZix");
expect(findChampion(champions, "miss fortune").id).toBe("MissFortune");
expect(findChampion(champions, "MissFortune").id).toBe("MissFortune");
});
it("returns null for non-matching input", () => {
expect(findChampion(champions, "zzz")).toBeNull();
expect(findChampion(champions, "")).toBeNull();
});
it("falls back to unique prefix match", () => {
expect(findChampion(champions, "aat").id).toBe("Aatrox");
});
it("prefix match returns null on ambiguity", () => {
const ambig = [...champions, { id: "Aatrox2", name: "Aatrox 2" }];
expect(findChampion(ambig, "aa")).toBeNull();
});
});