mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-28 10:20:35 +00:00
a2f67a7758
Code fixes: - trading/handlers + stats-handler: guard ctx.from?.id to prevent cross-user state corruption when channel posts or inline queries lack a sender - trading/prices + trading/symbols: encodeURIComponent on ticker before interpolating into TCBS API URLs - trading/stats-handler: parallelize per-stock price fetches with Promise.allSettled so N-stock portfolios don't stack serial latency - loldle/handlers: guard target champion lookup against champions.json refresh drift — start a fresh round or fall back to the stored id - wordle + loldle: explicitly initialize giveup:false in startFreshGame for stable state shape - wordle/lookup: fix stale JSDoc that claimed null return - biome: ignore auto-generated champions.json / champions-data.js / words-data.js - Apply formatter to src/index.js, loldle/handlers.js imports, and loldle/compare.test.js (previously red) Docs refresh: - README: 105+ tests -> 200+; wordle/loldle described as real modules - architecture: module tree updated, test count 105 -> 200, runtime ~500ms -> ~2s, stub list narrowed to misc only - codebase-summary: module table rewritten (wordle/loldle now Complete with real command lists and KV schema); test coverage table updated - loldle/README: full rewrite matching the current implementation (was describing the original stub) - New docs/development-roadmap.md tracking upcoming features (daily-mode for wordle + loldle, crypto/gold/forex trading, shared picker util, handler-level tests, coverage reporting, staging env) Tests: 200/200 passing. Lint: clean.
85 lines
2.3 KiB
JavaScript
85 lines
2.3 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import { CLASSIC_ATTRIBUTES, compareChampions } from "../../../src/modules/loldle/compare.js";
|
|
|
|
const aatrox = {
|
|
id: "Aatrox",
|
|
gender: "male",
|
|
genre: "Fighter",
|
|
attackType: "close",
|
|
resource: "Blood Well",
|
|
region: "runeterra",
|
|
lane: "top",
|
|
releaseDate: 2013,
|
|
};
|
|
|
|
const ahri = {
|
|
id: "Ahri",
|
|
gender: "female",
|
|
genre: "Mage,Assassin",
|
|
attackType: "range",
|
|
resource: "Mana",
|
|
region: "ionia",
|
|
lane: "mid",
|
|
releaseDate: 2011,
|
|
};
|
|
|
|
const akali = {
|
|
id: "Akali",
|
|
gender: "female",
|
|
genre: "Assassin",
|
|
attackType: "close",
|
|
resource: "Energy",
|
|
region: "ionia",
|
|
lane: "mid,top",
|
|
releaseDate: 2010,
|
|
};
|
|
|
|
function byKey(results, key) {
|
|
return results.find((r) => r.key === key);
|
|
}
|
|
|
|
describe("compareChampions", () => {
|
|
it("all correct when guess === target", () => {
|
|
const r = compareChampions(aatrox, aatrox);
|
|
for (const row of r) expect(row.result).toBe("correct");
|
|
});
|
|
|
|
it("exact mismatch is wrong", () => {
|
|
const r = compareChampions(aatrox, ahri);
|
|
expect(byKey(r, "gender").result).toBe("wrong");
|
|
expect(byKey(r, "attackType").result).toBe("wrong");
|
|
expect(byKey(r, "resource").result).toBe("wrong");
|
|
expect(byKey(r, "region").result).toBe("wrong");
|
|
});
|
|
|
|
it("multi-value partial overlap is partial", () => {
|
|
const r = compareChampions(akali, ahri);
|
|
expect(byKey(r, "genre").result).toBe("partial");
|
|
expect(byKey(r, "lane").result).toBe("partial");
|
|
});
|
|
|
|
it("multi-value identical sets are correct even if order/case differ", () => {
|
|
const r = compareChampions({ ...akali, genre: "assassin" }, { ...akali, genre: "Assassin" });
|
|
expect(byKey(r, "genre").result).toBe("correct");
|
|
});
|
|
|
|
it("year direction hints up when guess < target", () => {
|
|
const r = compareChampions(akali, aatrox); // 2010 vs 2013
|
|
const y = byKey(r, "releaseDate");
|
|
expect(y.result).toBe("wrong");
|
|
expect(y.direction).toBe("up");
|
|
});
|
|
|
|
it("year direction hints down when guess > target", () => {
|
|
const r = compareChampions(aatrox, akali); // 2013 vs 2010
|
|
const y = byKey(r, "releaseDate");
|
|
expect(y.result).toBe("wrong");
|
|
expect(y.direction).toBe("down");
|
|
});
|
|
|
|
it("returns 7 attributes in declared order", () => {
|
|
const r = compareChampions(aatrox, ahri);
|
|
expect(r.map((x) => x.key)).toEqual(CLASSIC_ATTRIBUTES.map((a) => a.key));
|
|
});
|
|
});
|