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.