brackt/app/lib/__tests__/normalize-team-name.test.ts

49 lines
1.7 KiB
TypeScript
Raw Normal View History

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);
});
});
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("returns null for unmatched name", () => {
expect(findMatchingTeamName("Phoenix Suns", participants)).toBeNull();
});
it("returns null for empty participants list", () => {
expect(findMatchingTeamName("Boston Celtics", [])).toBeNull();
});
});