mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-05-03 14:21:41 +00:00
bd5626534b
Ship two new loldle-family modules mirroring loldle.net's non-classic modes. Text-only MVP (ability/splash phases stay deferred). - loldle-emoji: 5 guesses, emoji-sequence clue. Pool derived algorithmically from classic's champions.json metadata (species/region/resource mapping table) since loldle.net's bundle has no static emoji pool. - loldle-quote: 6 guesses, lore-blurb clue. Pool seeded from Data Dragon champion title + first lore sentence; champion name redacted to ___. - scripts/fetch-ddragon-data.js: single generator for both JSONs. - src/util/normalize-name.js: shared lookup helper; loldle/lookup.js refactored to import it. 35 new tests (484 total passing). Lint clean.
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { createStore } from "../../../src/db/create-store.js";
|
|
import {
|
|
clearGame,
|
|
loadGame,
|
|
loadStats,
|
|
recordResult,
|
|
saveGame,
|
|
} from "../../../src/modules/loldle-emoji/state.js";
|
|
import { makeFakeKv } from "../../fakes/fake-kv-namespace.js";
|
|
|
|
describe("loldle-emoji state", () => {
|
|
let db;
|
|
|
|
beforeEach(() => {
|
|
db = createStore("loldle-emoji", { KV: makeFakeKv() });
|
|
});
|
|
|
|
it("round-trips a game", async () => {
|
|
const state = { target: "Ahri", guesses: ["Akali"], startedAt: 1234 };
|
|
await saveGame(db, 42, state);
|
|
expect(await loadGame(db, 42)).toEqual(state);
|
|
});
|
|
|
|
it("clearGame removes the round", async () => {
|
|
await saveGame(db, 42, { target: "Ahri", guesses: [], startedAt: null });
|
|
await clearGame(db, 42);
|
|
expect(await loadGame(db, 42)).toBeNull();
|
|
});
|
|
|
|
it("loadStats returns zeros when absent", async () => {
|
|
expect(await loadStats(db, 42)).toEqual({
|
|
played: 0,
|
|
wins: 0,
|
|
streak: 0,
|
|
bestStreak: 0,
|
|
});
|
|
});
|
|
|
|
it("recordResult(true) increments wins+streak and updates bestStreak", async () => {
|
|
let s = await recordResult(db, 42, true);
|
|
expect(s).toMatchObject({ played: 1, wins: 1, streak: 1, bestStreak: 1 });
|
|
s = await recordResult(db, 42, true);
|
|
expect(s).toMatchObject({ played: 2, wins: 2, streak: 2, bestStreak: 2 });
|
|
});
|
|
|
|
it("recordResult(false) resets streak", async () => {
|
|
await recordResult(db, 42, true);
|
|
await recordResult(db, 42, true);
|
|
const s = await recordResult(db, 42, false);
|
|
expect(s).toMatchObject({ played: 3, wins: 2, streak: 0, bestStreak: 2 });
|
|
});
|
|
|
|
it("isolates stats per subject", async () => {
|
|
await recordResult(db, 1, true);
|
|
await recordResult(db, 2, false);
|
|
expect((await loadStats(db, 1)).wins).toBe(1);
|
|
expect((await loadStats(db, 2)).wins).toBe(0);
|
|
});
|
|
});
|