Address code review feedback on draft window implementation
- sports-data-sync: use unambiguous past placeholder dates for synced seasons, with a comment explaining the intent - sports-season model: remove redundant top-level lte/gte imports (callback form already supplies them) - _journal.json: add missing trailing newline - sports-season test: mock ~/database/schema instead of stubbing all drizzle builder functions, matching the established pattern in the codebase - admin list: compute today once in component body instead of per-row https://claude.ai/code/session_01LHYgpyimF8v8odUB6kj8Qc
This commit is contained in:
parent
6dbda8465f
commit
7a9dd3b874
5 changed files with 21 additions and 18 deletions
|
|
@ -4,6 +4,19 @@ vi.mock("~/database/context", () => ({
|
||||||
database: vi.fn(),
|
database: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Mock the schema so the schema module doesn't execute drizzle builder calls,
|
||||||
|
// following the same pattern as scoring-event-dashboard.test.ts.
|
||||||
|
vi.mock("~/database/schema", () => ({
|
||||||
|
sportsSeasons: {
|
||||||
|
id: "ss.id",
|
||||||
|
sportId: "ss.sport_id",
|
||||||
|
name: "ss.name",
|
||||||
|
year: "ss.year",
|
||||||
|
draftOn: "ss.draft_on",
|
||||||
|
draftOff: "ss.draft_off",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("drizzle-orm", () => ({
|
vi.mock("drizzle-orm", () => ({
|
||||||
eq: (col: unknown, val: unknown) => ({ type: "eq", col, val }),
|
eq: (col: unknown, val: unknown) => ({ type: "eq", col, val }),
|
||||||
sql: (strings: TemplateStringsArray, ...values: unknown[]) => ({ type: "sql", strings, values }),
|
sql: (strings: TemplateStringsArray, ...values: unknown[]) => ({ type: "sql", strings, values }),
|
||||||
|
|
@ -12,19 +25,6 @@ vi.mock("drizzle-orm", () => ({
|
||||||
and: (...args: unknown[]) => ({ type: "and", args }),
|
and: (...args: unknown[]) => ({ type: "and", args }),
|
||||||
desc: (col: unknown) => ({ type: "desc", col }),
|
desc: (col: unknown) => ({ type: "desc", col }),
|
||||||
asc: (col: unknown) => ({ type: "asc", col }),
|
asc: (col: unknown) => ({ type: "asc", col }),
|
||||||
relations: () => ({}),
|
|
||||||
pgTable: () => ({}),
|
|
||||||
pgEnum: (_name: string, values: string[]) => values,
|
|
||||||
boolean: () => ({ notNull: () => ({ default: () => ({}) }) }),
|
|
||||||
integer: () => ({ notNull: () => ({}), default: () => ({}) }),
|
|
||||||
varchar: () => ({ notNull: () => ({}) }),
|
|
||||||
uuid: () => ({ primaryKey: () => ({}), notNull: () => ({ references: () => ({}) }) }),
|
|
||||||
timestamp: () => ({ defaultNow: () => ({ notNull: () => ({}) }) }),
|
|
||||||
decimal: () => ({ notNull: () => ({ default: () => ({}) }), precision: () => ({}) }),
|
|
||||||
date: () => ({ notNull: () => ({}) }),
|
|
||||||
text: () => ({}),
|
|
||||||
index: () => ({}),
|
|
||||||
uniqueIndex: () => ({}),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { findAllSportsSeasons, findDraftableSportsSeasons } from "../sports-season";
|
import { findAllSportsSeasons, findDraftableSportsSeasons } from "../sports-season";
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { eq, sql, lte, gte } from "drizzle-orm";
|
import { eq, sql } from "drizzle-orm";
|
||||||
import { database } from "~/database/context";
|
import { database } from "~/database/context";
|
||||||
import * as schema from "~/database/schema";
|
import * as schema from "~/database/schema";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ export async function loader() {
|
||||||
|
|
||||||
export default function AdminSportsSeasons({ loaderData }: Route.ComponentProps) {
|
export default function AdminSportsSeasons({ loaderData }: Route.ComponentProps) {
|
||||||
const { sportsSeasons } = loaderData;
|
const { sportsSeasons } = loaderData;
|
||||||
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-8">
|
<div className="p-8">
|
||||||
|
|
@ -115,7 +116,6 @@ export default function AdminSportsSeasons({ loaderData }: Route.ComponentProps)
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{(() => {
|
{(() => {
|
||||||
const today = new Date().toISOString().slice(0, 10);
|
|
||||||
const active = season.draftOn <= today && today <= season.draftOff;
|
const active = season.draftOn <= today && today <= season.draftOff;
|
||||||
return (
|
return (
|
||||||
<div className="space-y-0.5">
|
<div className="space-y-0.5">
|
||||||
|
|
|
||||||
|
|
@ -336,8 +336,11 @@ export async function importSportsDataFromJSON(
|
||||||
| "playoffs"
|
| "playoffs"
|
||||||
| "regular_season"
|
| "regular_season"
|
||||||
| "majors",
|
| "majors",
|
||||||
draftOn: "2099-12-31",
|
// Placeholder: season is not draftable until an admin sets real dates.
|
||||||
draftOff: "2099-12-31",
|
// A narrow past window is used so the season never accidentally appears
|
||||||
|
// in league creation without an intentional update.
|
||||||
|
draftOn: "2000-01-01",
|
||||||
|
draftOff: "2000-01-02",
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
sportsSeasonIdMap.set(seasonKey, created_.id);
|
sportsSeasonIdMap.set(seasonKey, created_.id);
|
||||||
|
|
|
||||||
|
|
@ -493,4 +493,4 @@
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue