From e6f3c396ae4c622f345c6ede7822d5f509e598bd Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Tue, 26 May 2026 22:34:26 -0700 Subject: [PATCH] Fix test mocks for group stage upcoming events changes Add groupStageMatches, tournamentGroups, and seasonParticipants to the schema mock, add db.select mock for the group stage query, and wire default empty results into all bracket-path beforeEach hooks. Co-Authored-By: Claude Sonnet 4.6 --- .../__tests__/upcoming-calendar.test.ts | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/app/models/__tests__/upcoming-calendar.test.ts b/app/models/__tests__/upcoming-calendar.test.ts index 609ea7a..80c1e7d 100644 --- a/app/models/__tests__/upcoming-calendar.test.ts +++ b/app/models/__tests__/upcoming-calendar.test.ts @@ -13,8 +13,10 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; const mockDb = { query: { scoringEvents: { findMany: vi.fn() }, + seasonParticipants: { findMany: vi.fn() }, }, selectDistinct: vi.fn(), + select: vi.fn(), }; vi.mock("~/database/context", () => ({ @@ -22,11 +24,24 @@ vi.mock("~/database/context", () => ({ })); vi.mock("~/database/schema", () => ({ - scoringEvents: { sportsSeasonId: "se.sports_season_id", isComplete: "se.is_complete", eventDate: "se.event_date", eventType: "se.event_type" }, + scoringEvents: { sportsSeasonId: "se.sports_season_id", isComplete: "se.is_complete", eventDate: "se.event_date", eventType: "se.event_type", name: "se.name" }, playoffMatches: { id: "pm.id", scoringEventId: "pm.scoring_event_id", participant1Id: "pm.participant1_id", participant2Id: "pm.participant2_id", round: "pm.round", matchNumber: "pm.match_number", isComplete: "pm.is_complete" }, playoffMatchGames: { playoffMatchId: "pmg.playoff_match_id", scheduledAt: "pmg.scheduled_at", gameNumber: "pmg.game_number" }, + groupStageMatches: { id: "gsm.id", tournamentGroupId: "gsm.tournament_group_id", participant1Id: "gsm.participant1_id", participant2Id: "gsm.participant2_id", scheduledAt: "gsm.scheduled_at", isComplete: "gsm.is_complete" }, + tournamentGroups: { id: "tg.id", groupName: "tg.group_name", scoringEventId: "tg.scoring_event_id" }, + seasonParticipants: { id: "sp.id" }, })); +// Chain helper for the group stage db.select() query (resolves at orderBy). +function makeGroupStageSelectChain(rows: unknown[]) { + return { + from: vi.fn().mockReturnThis(), + innerJoin: vi.fn().mockReturnThis(), + where: vi.fn().mockReturnThis(), + orderBy: vi.fn().mockResolvedValue(rows), + }; +} + vi.mock("drizzle-orm", () => ({ eq: (col: unknown, val: unknown) => ({ type: "eq", col, val }), and: (...args: unknown[]) => ({ type: "and", args }), @@ -70,8 +85,11 @@ function makeScoringEvent(overrides: Partial<{ describe("getUpcomingEventsForDraftedParticipants — all-compete sports", () => { beforeEach(() => { vi.clearAllMocks(); - // selectDistinct won't be called for all-compete - mockDb.selectDistinct.mockReturnValue({ from: vi.fn().mockReturnThis(), innerJoin: vi.fn().mockReturnThis(), where: vi.fn().mockReturnThis(), orderBy: vi.fn().mockResolvedValue([]) }); + // selectDistinct won't be called for all-compete; default for the "unknown + // pattern" test which falls through to the bracket path. + mockDb.selectDistinct.mockReturnValue({ from: vi.fn().mockReturnThis(), innerJoin: vi.fn().mockReturnThis(), leftJoin: vi.fn().mockReturnThis(), where: vi.fn().mockReturnThis(), orderBy: vi.fn().mockResolvedValue([]) }); + mockDb.select.mockReturnValue(makeGroupStageSelectChain([])); + mockDb.query.seasonParticipants.findMany.mockResolvedValue([]); }); it("returns [] when draftedParticipants is empty", async () => { @@ -169,6 +187,9 @@ describe("getUpcomingEventsForDraftedParticipants — bracket sports", () => { // Default for the second selectDistinct call (max-game-number lookup). // Individual tests override the first call with mockReturnValueOnce. mockDb.selectDistinct.mockReturnValue(makeMaxGameChain([])); + // Default: no group stage matches (db.select used by the group stage query). + mockDb.select.mockReturnValue(makeGroupStageSelectChain([])); + mockDb.query.seasonParticipants.findMany.mockResolvedValue([]); }); it("returns [] when draftedParticipants is empty", async () => { @@ -624,7 +645,12 @@ describe("getUpcomingEventsForDraftedParticipants — bracket misc", () => { }; } - beforeEach(() => vi.clearAllMocks()); + beforeEach(() => { + vi.clearAllMocks(); + // Default: no group stage matches. + mockDb.select.mockReturnValue(makeGroupStageSelectChain([])); + mockDb.query.seasonParticipants.findMany.mockResolvedValue([]); + }); it("excludes scored (isComplete) matches by passing the filter to the DB query", async () => { // The DB mock returns rows only for matches the WHERE clause matches.