2026-03-21 09:44:05 -07:00
|
|
|
import { describe, it, expect } from "vitest";
|
2026-03-21 00:12:01 -07:00
|
|
|
import { findMatchingTeamName } from "~/lib/normalize-team-name";
|
|
|
|
|
|
|
|
|
|
// Pure unit tests for the name-matching logic used by syncStandings.
|
|
|
|
|
// The full orchestrator requires DB context; those are covered by integration tests.
|
|
|
|
|
|
|
|
|
|
describe("findMatchingTeamName (sync name-matching logic)", () => {
|
|
|
|
|
const participants = [
|
|
|
|
|
"Boston Celtics",
|
|
|
|
|
"Los Angeles Lakers",
|
|
|
|
|
"Golden State Warriors",
|
|
|
|
|
"Oklahoma City Thunder",
|
|
|
|
|
"San Antonio Spurs",
|
|
|
|
|
"New York Knicks",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
it("matches exact names", () => {
|
|
|
|
|
expect(findMatchingTeamName("Boston Celtics", participants)).toBe("Boston Celtics");
|
|
|
|
|
expect(findMatchingTeamName("New York Knicks", participants)).toBe("New York Knicks");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("is case-insensitive", () => {
|
|
|
|
|
expect(findMatchingTeamName("golden state warriors", participants)).toBe(
|
|
|
|
|
"Golden State Warriors"
|
|
|
|
|
);
|
|
|
|
|
expect(findMatchingTeamName("SAN ANTONIO SPURS", participants)).toBe("San Antonio Spurs");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("matches partial city+team via substring", () => {
|
|
|
|
|
expect(findMatchingTeamName("Golden State", participants)).toBe("Golden State Warriors");
|
|
|
|
|
expect(findMatchingTeamName("Oklahoma City", participants)).toBe("Oklahoma City Thunder");
|
|
|
|
|
// "New York" is a substring of "New York Knicks"
|
|
|
|
|
expect(findMatchingTeamName("New York", participants)).toBe("New York Knicks");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns null for truly unmatched names", () => {
|
|
|
|
|
expect(findMatchingTeamName("Phoenix Suns", participants)).toBeNull();
|
|
|
|
|
expect(findMatchingTeamName("Charlotte Hornets", participants)).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns null for empty string", () => {
|
|
|
|
|
expect(findMatchingTeamName("", participants)).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles extra whitespace gracefully", () => {
|
|
|
|
|
expect(findMatchingTeamName(" Boston Celtics ", participants)).toBe("Boston Celtics");
|
|
|
|
|
});
|
|
|
|
|
});
|