import { describe, it, expect } from "vitest"; import { normalizeTeamName, findMatchingTeamName } from "../normalize-team-name"; describe("normalizeTeamName", () => { it("lowercases and trims", () => { expect(normalizeTeamName(" Boston Celtics ")).toBe("boston celtics"); }); it("collapses multiple spaces", () => { expect(normalizeTeamName("Los Angeles Lakers")).toBe("los angeles lakers"); }); it("is idempotent", () => { const name = "oklahoma city thunder"; expect(normalizeTeamName(name)).toBe(name); }); it("folds accents so diacritics don't block a match", () => { expect(normalizeTeamName("Stéfanos Tsitsipás")).toBe("stefanos tsitsipas"); expect(normalizeTeamName("Félix Auger-Aliassime")).toBe("felix auger-aliassime"); }); }); describe("findMatchingTeamName", () => { const participants = [ "Boston Celtics", "Los Angeles Lakers", "Oklahoma City Thunder", "Golden State Warriors", "Toronto Raptors", ]; it("returns exact case-insensitive match", () => { expect(findMatchingTeamName("Boston Celtics", participants)).toBe("Boston Celtics"); expect(findMatchingTeamName("boston celtics", participants)).toBe("Boston Celtics"); expect(findMatchingTeamName("TORONTO RAPTORS", participants)).toBe("Toronto Raptors"); }); it("matches partial city+team via substring (e.g. API returns city only)", () => { // "Golden State" is a substring of "Golden State Warriors" expect(findMatchingTeamName("Golden State", participants)).toBe("Golden State Warriors"); // "Oklahoma City" is a substring of "Oklahoma City Thunder" expect(findMatchingTeamName("Oklahoma City", participants)).toBe("Oklahoma City Thunder"); }); it("matches across accents (API has them, our list doesn't)", () => { expect(findMatchingTeamName("Stéfanos Tsitsipás", ["Stefanos Tsitsipas"])).toBe( "Stefanos Tsitsipas", ); }); it("returns null for unmatched name", () => { expect(findMatchingTeamName("Phoenix Suns", participants)).toBeNull(); }); it("returns null for empty participants list", () => { expect(findMatchingTeamName("Boston Celtics", [])).toBeNull(); }); });