fix(tests): update mock query keys after participants table rename
Change mock db.query.participants to db.query.seasonParticipants in test
files to match the schema rename from commit 66145a9. This fixes
"Cannot read properties of undefined (reading 'findFirst'/'findMany')"
errors that occurred when production code queries db.query.seasonParticipants
but test mocks only defined the old participants key.
Files updated:
- app/services/simulations/__tests__/world-cup-simulator.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.timer-mode.test.ts
- app/routes/api/__tests__/draft.make-pick.timer-mode.test.ts
- server/__tests__/timer-autodraft.test.ts
- app/models/__tests__/team-score-events.test.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
9097717d60
commit
b5b60a6093
6 changed files with 19 additions and 19 deletions
|
|
@ -64,7 +64,7 @@ function makeDb(opts: MakeDbOpts = {}) {
|
||||||
teamScoreEvents: {
|
teamScoreEvents: {
|
||||||
findMany: vi.fn().mockResolvedValue(scoreEventRows),
|
findMany: vi.fn().mockResolvedValue(scoreEventRows),
|
||||||
},
|
},
|
||||||
participants: {
|
seasonParticipants: {
|
||||||
findMany: vi.fn().mockResolvedValue(participantRows),
|
findMany: vi.fn().mockResolvedValue(participantRows),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -268,7 +268,7 @@ describe("getRecentTeamScoreEvents", () => {
|
||||||
it("does not query participants when rows array is empty", async () => {
|
it("does not query participants when rows array is empty", async () => {
|
||||||
const { db } = makeDb({ scoreEventRows: [] });
|
const { db } = makeDb({ scoreEventRows: [] });
|
||||||
await getRecentTeamScoreEvents("season-1", 10, db);
|
await getRecentTeamScoreEvents("season-1", 10, db);
|
||||||
expect(db.query.participants.findMany).not.toHaveBeenCalled();
|
expect(db.query.seasonParticipants.findMany).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns mapped entries with resolved participant names", async () => {
|
it("returns mapped entries with resolved participant names", async () => {
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ describe("draft.force-manual-pick action", () => {
|
||||||
seasons: { findFirst: vi.fn() },
|
seasons: { findFirst: vi.fn() },
|
||||||
commissioners: { findFirst: vi.fn() },
|
commissioners: { findFirst: vi.fn() },
|
||||||
draftPicks: { findFirst: vi.fn() },
|
draftPicks: { findFirst: vi.fn() },
|
||||||
participants: { findFirst: vi.fn() },
|
seasonParticipants: { findFirst: vi.fn() },
|
||||||
draftSlots: { findMany: vi.fn() },
|
draftSlots: { findMany: vi.fn() },
|
||||||
draftTimers: { findFirst: vi.fn() },
|
draftTimers: { findFirst: vi.fn() },
|
||||||
},
|
},
|
||||||
|
|
@ -178,7 +178,7 @@ describe("draft.force-manual-pick action", () => {
|
||||||
userId: COMMISSIONER_ID,
|
userId: COMMISSIONER_ID,
|
||||||
});
|
});
|
||||||
mockDb.query.draftPicks.findFirst.mockResolvedValue(null);
|
mockDb.query.draftPicks.findFirst.mockResolvedValue(null);
|
||||||
mockDb.query.participants.findFirst.mockResolvedValue(mockParticipant);
|
mockDb.query.seasonParticipants.findFirst.mockResolvedValue(mockParticipant);
|
||||||
mockDb.query.draftSlots.findMany.mockResolvedValue(mockDraftSlots);
|
mockDb.query.draftSlots.findMany.mockResolvedValue(mockDraftSlots);
|
||||||
mockDb.query.draftTimers.findFirst.mockResolvedValue({
|
mockDb.query.draftTimers.findFirst.mockResolvedValue({
|
||||||
id: "timer-1",
|
id: "timer-1",
|
||||||
|
|
@ -277,7 +277,7 @@ describe("draft.force-manual-pick action", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns 404 when the participant does not exist", async () => {
|
it("returns 404 when the participant does not exist", async () => {
|
||||||
mockDb.query.participants.findFirst.mockResolvedValue(null);
|
mockDb.query.seasonParticipants.findFirst.mockResolvedValue(null);
|
||||||
|
|
||||||
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
|
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ describe("draft.force-manual-pick action — timer mode behavior", () => {
|
||||||
findFirst: vi.fn().mockResolvedValue({ id: "c-1", userId: COMMISSIONER_ID }),
|
findFirst: vi.fn().mockResolvedValue({ id: "c-1", userId: COMMISSIONER_ID }),
|
||||||
},
|
},
|
||||||
draftPicks: { findFirst: vi.fn().mockResolvedValue(null) },
|
draftPicks: { findFirst: vi.fn().mockResolvedValue(null) },
|
||||||
participants: { findFirst: vi.fn().mockResolvedValue(mockParticipant) },
|
seasonParticipants: { findFirst: vi.fn().mockResolvedValue(mockParticipant) },
|
||||||
draftSlots: { findMany: vi.fn().mockResolvedValue(mockDraftSlots) },
|
draftSlots: { findMany: vi.fn().mockResolvedValue(mockDraftSlots) },
|
||||||
draftTimers: {
|
draftTimers: {
|
||||||
findFirst: vi.fn().mockResolvedValue({ id: "timer-1", seasonId: SEASON_ID, teamId: TEAM_ID, timeRemaining: 75 }),
|
findFirst: vi.fn().mockResolvedValue({ id: "timer-1", seasonId: SEASON_ID, teamId: TEAM_ID, timeRemaining: 75 }),
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ describe("draft.make-pick action — timer mode behavior", () => {
|
||||||
seasons: { findFirst: vi.fn() },
|
seasons: { findFirst: vi.fn() },
|
||||||
commissioners: { findFirst: vi.fn().mockResolvedValue(null) },
|
commissioners: { findFirst: vi.fn().mockResolvedValue(null) },
|
||||||
draftPicks: { findFirst: vi.fn().mockResolvedValue(null) },
|
draftPicks: { findFirst: vi.fn().mockResolvedValue(null) },
|
||||||
participants: { findFirst: vi.fn().mockResolvedValue(mockParticipant) },
|
seasonParticipants: { findFirst: vi.fn().mockResolvedValue(mockParticipant) },
|
||||||
draftSlots: { findMany: vi.fn().mockResolvedValue(mockDraftSlots) },
|
draftSlots: { findMany: vi.fn().mockResolvedValue(mockDraftSlots) },
|
||||||
draftTimers: { findFirst: vi.fn().mockResolvedValue({ id: "timer-1", timeRemaining: 75 }) },
|
draftTimers: { findFirst: vi.fn().mockResolvedValue({ id: "timer-1", timeRemaining: 75 }) },
|
||||||
draftQueue: { findMany: vi.fn().mockResolvedValue([]) },
|
draftQueue: { findMany: vi.fn().mockResolvedValue([]) },
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ import { database } from "~/database/context";
|
||||||
|
|
||||||
const mockDb = {
|
const mockDb = {
|
||||||
query: {
|
query: {
|
||||||
participants: { findMany: vi.fn() },
|
seasonParticipants: { findMany: vi.fn() },
|
||||||
scoringEvents: { findFirst: vi.fn() },
|
scoringEvents: { findFirst: vi.fn() },
|
||||||
tournamentGroups: { findMany: vi.fn() },
|
tournamentGroups: { findMany: vi.fn() },
|
||||||
playoffMatches: { findMany: vi.fn() },
|
playoffMatches: { findMany: vi.fn() },
|
||||||
|
|
@ -98,7 +98,7 @@ const mockDb = {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.mocked(database).mockReturnValue(mockDb as never);
|
vi.mocked(database).mockReturnValue(mockDb as never);
|
||||||
mockDb.query.participants.findMany.mockReset();
|
mockDb.query.seasonParticipants.findMany.mockReset();
|
||||||
mockDb.query.scoringEvents.findFirst.mockReset();
|
mockDb.query.scoringEvents.findFirst.mockReset();
|
||||||
mockDb.query.tournamentGroups.findMany.mockReset();
|
mockDb.query.tournamentGroups.findMany.mockReset();
|
||||||
mockDb.query.playoffMatches.findMany.mockReset();
|
mockDb.query.playoffMatches.findMany.mockReset();
|
||||||
|
|
@ -109,7 +109,7 @@ beforeEach(() => {
|
||||||
|
|
||||||
describe("WorldCupSimulator", () => {
|
describe("WorldCupSimulator", () => {
|
||||||
it("throws when no participants are found", async () => {
|
it("throws when no participants are found", async () => {
|
||||||
mockDb.query.participants.findMany.mockResolvedValue([]);
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
||||||
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
||||||
|
|
@ -120,7 +120,7 @@ describe("WorldCupSimulator", () => {
|
||||||
|
|
||||||
it("returns one result per participant", async () => {
|
it("returns one result per participant", async () => {
|
||||||
const participants = makeParticipants(48);
|
const participants = makeParticipants(48);
|
||||||
mockDb.query.participants.findMany.mockResolvedValue(participants);
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue(participants);
|
||||||
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
||||||
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
||||||
|
|
@ -136,7 +136,7 @@ describe("WorldCupSimulator", () => {
|
||||||
|
|
||||||
it("column sums for champion, runner-up, 3rd, 4th are each ≈1.0", async () => {
|
it("column sums for champion, runner-up, 3rd, 4th are each ≈1.0", async () => {
|
||||||
const participants = makeParticipants(48);
|
const participants = makeParticipants(48);
|
||||||
mockDb.query.participants.findMany.mockResolvedValue(participants);
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue(participants);
|
||||||
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
||||||
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
||||||
|
|
@ -157,7 +157,7 @@ describe("WorldCupSimulator", () => {
|
||||||
|
|
||||||
it("probabilities are all non-negative", async () => {
|
it("probabilities are all non-negative", async () => {
|
||||||
const participants = makeParticipants(48);
|
const participants = makeParticipants(48);
|
||||||
mockDb.query.participants.findMany.mockResolvedValue(participants);
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue(participants);
|
||||||
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
||||||
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
||||||
|
|
@ -178,7 +178,7 @@ describe("WorldCupSimulator", () => {
|
||||||
it("SF losers land in 3rd or 4th, never 1st or 2nd", async () => {
|
it("SF losers land in 3rd or 4th, never 1st or 2nd", async () => {
|
||||||
// Set up 8 participants (small bracket, 2 groups of 4)
|
// Set up 8 participants (small bracket, 2 groups of 4)
|
||||||
const participants = makeParticipants(8);
|
const participants = makeParticipants(8);
|
||||||
mockDb.query.participants.findMany.mockResolvedValue(participants);
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue(participants);
|
||||||
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
||||||
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
||||||
|
|
@ -200,7 +200,7 @@ describe("WorldCupSimulator", () => {
|
||||||
|
|
||||||
it("a team with pre-completed group stage result is fixed in simulation", async () => {
|
it("a team with pre-completed group stage result is fixed in simulation", async () => {
|
||||||
const participants = makeParticipants(48);
|
const participants = makeParticipants(48);
|
||||||
mockDb.query.participants.findMany.mockResolvedValue(participants);
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue(participants);
|
||||||
mockDb.query.scoringEvents.findFirst.mockResolvedValue({ id: "event-1" });
|
mockDb.query.scoringEvents.findFirst.mockResolvedValue({ id: "event-1" });
|
||||||
|
|
||||||
// One group fully complete: p0 wins everything, p3 loses everything
|
// One group fully complete: p0 wins everything, p3 loses everything
|
||||||
|
|
@ -254,7 +254,7 @@ describe("WorldCupSimulator", () => {
|
||||||
|
|
||||||
it("probFifth through probEighth are equal for each participant (QF losers split evenly)", async () => {
|
it("probFifth through probEighth are equal for each participant (QF losers split evenly)", async () => {
|
||||||
const participants = makeParticipants(48);
|
const participants = makeParticipants(48);
|
||||||
mockDb.query.participants.findMany.mockResolvedValue(participants);
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue(participants);
|
||||||
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
mockDb.query.scoringEvents.findFirst.mockResolvedValue(null);
|
||||||
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
mockDb.query.tournamentGroups.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
mockDb.query.playoffMatches.findMany.mockResolvedValue([]);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ beforeEach(() => {
|
||||||
autodraftSettings: { findFirst: vi.fn() },
|
autodraftSettings: { findFirst: vi.fn() },
|
||||||
draftPicks: { findMany: vi.fn(), findFirst: vi.fn() },
|
draftPicks: { findMany: vi.fn(), findFirst: vi.fn() },
|
||||||
draftQueue: { findMany: vi.fn() },
|
draftQueue: { findMany: vi.fn() },
|
||||||
participants: { findMany: vi.fn() },
|
seasonParticipants: { findMany: vi.fn() },
|
||||||
seasonTemplateSports: { findMany: vi.fn() },
|
seasonTemplateSports: { findMany: vi.fn() },
|
||||||
},
|
},
|
||||||
update: vi.fn().mockReturnThis(),
|
update: vi.fn().mockReturnThis(),
|
||||||
|
|
@ -146,7 +146,7 @@ describe('Timer Autodraft Integration', () => {
|
||||||
|
|
||||||
it('should fall back to highest EV when queue is empty and queueOnly is OFF', async () => {
|
it('should fall back to highest EV when queue is empty and queueOnly is OFF', async () => {
|
||||||
mockDb.query.draftQueue.findMany.mockResolvedValue([]);
|
mockDb.query.draftQueue.findMany.mockResolvedValue([]);
|
||||||
mockDb.query.participants.findMany.mockResolvedValue([
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue([
|
||||||
{ id: 'participant-high-ev', name: 'High EV Participant', expectedValue: 1000 },
|
{ id: 'participant-high-ev', name: 'High EV Participant', expectedValue: 1000 },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ describe('Timer Autodraft Integration', () => {
|
||||||
expect(queueItems.length).toBe(0);
|
expect(queueItems.length).toBe(0);
|
||||||
|
|
||||||
const queueOnly = false;
|
const queueOnly = false;
|
||||||
const availableParticipants = await mockDb.query.participants.findMany();
|
const availableParticipants = await mockDb.query.seasonParticipants.findMany();
|
||||||
const selectedParticipant = queueOnly ? null : availableParticipants[0];
|
const selectedParticipant = queueOnly ? null : availableParticipants[0];
|
||||||
expect(selectedParticipant).not.toBeNull();
|
expect(selectedParticipant).not.toBeNull();
|
||||||
expect(selectedParticipant?.expectedValue).toBe(1000);
|
expect(selectedParticipant?.expectedValue).toBe(1000);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue