mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-27 18:20:40 +00:00
df46e4ee22
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.
38 lines
1.3 KiB
JavaScript
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();
|
|
});
|
|
});
|