Files
miti99bot/tests/modules/loldle/lookup.test.js
T
tiennm99 df46e4ee22 refactor(loldle): consume loldle.net's raw schema directly
Drop the in-scraper normalization step — champions.json now mirrors the
exact shape emitted by loldle.net's JS bundle. Records use _id,
championId, championName, arrays for positions/species/regions/
range_type, "Male"/"Female"/"Other" gender strings, and a full
YYYY-MM-DD release_date.

Comparison is schema-aware: multi-value keys accept arrays directly,
the year axis parses YYYY out of the ISO date, and exact compares stay
case-insensitive.
2026-04-22 13:29:55 +07:00

38 lines
1.3 KiB
JavaScript

import { describe, expect, it } from "vitest";
import { findChampion } from "../../../src/modules/loldle/lookup.js";
const champions = [
{ championName: "Aatrox" },
{ championName: "Ahri" },
{ championName: "Kha'Zix" },
{ championName: "Miss Fortune" },
];
describe("findChampion", () => {
it("matches championName (case-insensitive)", () => {
expect(findChampion(champions, "aatrox").championName).toBe("Aatrox");
expect(findChampion(champions, "AATROX").championName).toBe("Aatrox");
});
it("normalizes punctuation and spaces", () => {
expect(findChampion(champions, "kha'zix").championName).toBe("Kha'Zix");
expect(findChampion(champions, "khazix").championName).toBe("Kha'Zix");
expect(findChampion(champions, "miss fortune").championName).toBe("Miss Fortune");
expect(findChampion(champions, "MissFortune").championName).toBe("Miss Fortune");
});
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").championName).toBe("Aatrox");
});
it("prefix match returns null on ambiguity", () => {
const ambig = [...champions, { championName: "Aatrox Prime" }];
expect(findChampion(ambig, "aa")).toBeNull();
});
});