diff --git a/app/lib/tournament-identity.ts b/app/lib/tournament-identity.ts index 0292908..1cce590 100644 --- a/app/lib/tournament-identity.ts +++ b/app/lib/tournament-identity.ts @@ -33,7 +33,7 @@ export function extractTournamentIdentity(ev: ScoringEventIdentityInput): Tourna cleanName = trimmed.replace(YEAR_SUFFIX, "").trim(); } - if (year === null && ev.eventDate != null) { + if (year === null && ev.eventDate !== null && ev.eventDate !== undefined) { const iso = ev.eventDate instanceof Date ? ev.eventDate.toISOString() : String(ev.eventDate); diff --git a/app/routes/admin.sports-seasons.$id.events.$eventId.server.ts b/app/routes/admin.sports-seasons.$id.events.$eventId.server.ts index d05de6f..7e9f0e2 100644 --- a/app/routes/admin.sports-seasons.$id.events.$eventId.server.ts +++ b/app/routes/admin.sports-seasons.$id.events.$eventId.server.ts @@ -16,7 +16,7 @@ import { type CreateEventResultData, type UpdateEventResultData, } from "~/models/event-result"; -import { filterNewResults, findParticipantsWithoutResults } from "./admin.sports-seasons.$id.events.$eventId.helpers"; +import { findParticipantsWithoutResults } from "./admin.sports-seasons.$id.events.$eventId.helpers"; import { findParticipantResultsBySportsSeasonId } from "~/models/participant-result"; import { upsertParticipantSeasonResult, diff --git a/app/services/__tests__/sync-tournament-results.test.ts b/app/services/__tests__/sync-tournament-results.test.ts index 98eae90..60dd323 100644 --- a/app/services/__tests__/sync-tournament-results.test.ts +++ b/app/services/__tests__/sync-tournament-results.test.ts @@ -1,4 +1,5 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; +import type * as DrizzleOrm from "drizzle-orm"; vi.mock("~/database/context", () => ({ database: vi.fn(), @@ -78,6 +79,18 @@ interface FakeDbState { * The service passes schema.tournamentResults etc., so we capture the real * schema module and compare by ref. */ + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function tableName(table: any): string { + // drizzle-orm PgTable exposes the table name under a symbol. Try a few. + const sym = Object.getOwnPropertySymbols(table).find( + (s) => s.toString() === "Symbol(drizzle:Name)" + ); + if (sym) return table[sym]; + // Fallback for our shim: read `.tableName` property if set. + return table.tableName; +} + function makeFakeDb(state: FakeDbState) { // We mirror the shape in a lazy way: each predicate function is stored on the // call so we can match rows. In practice the service only filters by simple @@ -90,9 +103,6 @@ function makeFakeDb(state: FakeDbState) { // eslint-disable-next-line @typescript-eslint/no-explicit-any function rowsFor(table: any): any[] { // Table objects are drizzle PgTable objects; we identify them by name. - // drizzle PgTables expose `[Symbol.for("drizzle:Name")]` but simpler: we - // just check a known property. Schema tables have `._.name`. - // Fallback: we compare string representation. const name = tableName(table); switch (name) { case "tournament_results": @@ -108,17 +118,6 @@ function makeFakeDb(state: FakeDbState) { } } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - function tableName(table: any): string { - // drizzle-orm PgTable exposes the table name under a symbol. Try a few. - const sym = Object.getOwnPropertySymbols(table).find( - (s) => s.toString() === "Symbol(drizzle:Name)" - ); - if (sym) return table[sym]; - // Fallback for our shim: read `.tableName` property if set. - return table.tableName; - } - const db = { // ---------- select ---------- select: vi.fn().mockImplementation(() => { @@ -208,7 +207,7 @@ function makeFakeDb(state: FakeDbState) { // --------------------------------------------------------------------------- vi.mock("drizzle-orm", async () => { - const actual = await vi.importActual("drizzle-orm"); + const actual = await vi.importActual("drizzle-orm"); return { ...actual, // eslint-disable-next-line @typescript-eslint/no-explicit-any