brackt/app/services/standings-sync/__tests__/sync.test.ts

49 lines
1.9 KiB
TypeScript
Raw Normal View History

import { describe, it, expect, vi, beforeEach } from "vitest";
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");
});
});