Fix World Cup group stage display and upcoming events #55
1 changed files with 30 additions and 4 deletions
|
|
@ -13,8 +13,10 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
const mockDb = {
|
const mockDb = {
|
||||||
query: {
|
query: {
|
||||||
scoringEvents: { findMany: vi.fn() },
|
scoringEvents: { findMany: vi.fn() },
|
||||||
|
seasonParticipants: { findMany: vi.fn() },
|
||||||
},
|
},
|
||||||
selectDistinct: vi.fn(),
|
selectDistinct: vi.fn(),
|
||||||
|
select: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mock("~/database/context", () => ({
|
vi.mock("~/database/context", () => ({
|
||||||
|
|
@ -22,11 +24,24 @@ vi.mock("~/database/context", () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("~/database/schema", () => ({
|
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" },
|
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" },
|
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", () => ({
|
vi.mock("drizzle-orm", () => ({
|
||||||
eq: (col: unknown, val: unknown) => ({ type: "eq", col, val }),
|
eq: (col: unknown, val: unknown) => ({ type: "eq", col, val }),
|
||||||
and: (...args: unknown[]) => ({ type: "and", args }),
|
and: (...args: unknown[]) => ({ type: "and", args }),
|
||||||
|
|
@ -70,8 +85,11 @@ function makeScoringEvent(overrides: Partial<{
|
||||||
describe("getUpcomingEventsForDraftedParticipants — all-compete sports", () => {
|
describe("getUpcomingEventsForDraftedParticipants — all-compete sports", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
// selectDistinct won't be called for all-compete
|
// selectDistinct won't be called for all-compete; default for the "unknown
|
||||||
mockDb.selectDistinct.mockReturnValue({ from: vi.fn().mockReturnThis(), innerJoin: vi.fn().mockReturnThis(), where: vi.fn().mockReturnThis(), orderBy: vi.fn().mockResolvedValue([]) });
|
// 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 () => {
|
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).
|
// Default for the second selectDistinct call (max-game-number lookup).
|
||||||
// Individual tests override the first call with mockReturnValueOnce.
|
// Individual tests override the first call with mockReturnValueOnce.
|
||||||
mockDb.selectDistinct.mockReturnValue(makeMaxGameChain([]));
|
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 () => {
|
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 () => {
|
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.
|
// The DB mock returns rows only for matches the WHERE clause matches.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue