Fix RouterContextProvider type errors in action test files

Cast context argument to RouterContextProvider in test helpers so
ActionFunctionArgs strict typing is satisfied without weakening the
production action signatures back to any.

https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
This commit is contained in:
Claude 2026-02-23 02:53:37 +00:00
parent c036cf6e28
commit bf5cd62cb5
No known key found for this signature in database
2 changed files with 33 additions and 27 deletions

View file

@ -1,6 +1,9 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import type { RouterContextProvider } from "react-router";
import { action } from "~/routes/api/draft.force-manual-pick";
const ctx = {} as unknown as RouterContextProvider;
vi.mock("~/database/context");
vi.mock("~/server/socket", () => ({
getSocketIO: vi.fn(),
@ -183,7 +186,7 @@ describe("draft.force-manual-pick action", () => {
const { getAuth } = await import("@clerk/react-router/server");
vi.mocked(getAuth).mockResolvedValue({ userId: null } as any);
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(401);
});
@ -191,7 +194,7 @@ describe("draft.force-manual-pick action", () => {
it("returns 403 when authenticated user is not a commissioner", async () => {
mockDb.query.commissioners.findFirst.mockResolvedValue(null);
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(403);
const data = await response.json();
@ -206,7 +209,7 @@ describe("draft.force-manual-pick action", () => {
const response = await action({
request: makeRequest({ seasonId: SEASON_ID }), // missing teamId, participantId, pickNumber
params: {},
context: {},
context: ctx,
});
expect(response.status).toBe(400);
@ -215,7 +218,7 @@ describe("draft.force-manual-pick action", () => {
it("returns 404 when the season does not exist", async () => {
mockDb.query.seasons.findFirst.mockResolvedValue(null);
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(404);
});
@ -223,7 +226,7 @@ describe("draft.force-manual-pick action", () => {
it("returns 400 when the draft is not active", async () => {
mockDb.query.seasons.findFirst.mockResolvedValue({ ...mockSeason, status: "pre_draft" });
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(400);
const data = await response.json();
@ -236,7 +239,7 @@ describe("draft.force-manual-pick action", () => {
participantId: "other-participant",
});
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(400);
const data = await response.json();
@ -253,7 +256,7 @@ describe("draft.force-manual-pick action", () => {
participantId: PARTICIPANT_ID,
});
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(400);
const data = await response.json();
@ -263,7 +266,7 @@ describe("draft.force-manual-pick action", () => {
it("returns 404 when the participant does not exist", async () => {
mockDb.query.participants.findFirst.mockResolvedValue(null);
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(404);
});
@ -275,7 +278,7 @@ describe("draft.force-manual-pick action", () => {
ineligibleReasons: { [SPORT_ID]: "Sport limit reached" },
} as any);
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(400);
const data = await response.json();
@ -287,7 +290,7 @@ describe("draft.force-manual-pick action", () => {
describe("successful pick", () => {
it("returns 200 with pick data and next pick number", async () => {
const response = await action({ request: defaultPickRequest(), params: {}, context: {} });
const response = await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(response.status).toBe(200);
const data = await response.json();
@ -307,7 +310,7 @@ describe("draft.force-manual-pick action", () => {
pickNumber: "6",
}),
params: {},
context: {},
context: ctx,
});
const data = await response.json();
@ -315,7 +318,7 @@ describe("draft.force-manual-pick action", () => {
});
it("emits pick-made to the correct draft room", async () => {
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(mockSocketIO.to).toHaveBeenCalledWith(`draft-${SEASON_ID}`);
expect(mockSocketIO.emit).toHaveBeenCalledWith(
@ -325,7 +328,7 @@ describe("draft.force-manual-pick action", () => {
});
it("removes the participant from all team queues in the season", async () => {
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(mockDb.delete).toHaveBeenCalled();
expect(mockSocketIO.emit).toHaveBeenCalledWith("participant-removed-from-queues", {
@ -351,7 +354,7 @@ describe("draft.force-manual-pick action", () => {
timeRemaining: 75,
});
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(mockDb.set).toHaveBeenCalledWith(
expect.objectContaining({ timeRemaining: 105 })
@ -366,7 +369,7 @@ describe("draft.force-manual-pick action", () => {
timeRemaining: 75,
});
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(mockSocketIO.emit).toHaveBeenCalledWith("timer-update", {
seasonId: SEASON_ID,
@ -379,7 +382,7 @@ describe("draft.force-manual-pick action", () => {
it("creates a new timer for the picking team if they have no existing timer", async () => {
mockDb.query.draftTimers.findFirst.mockResolvedValue(null);
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
// insert should be called for: (1) draft pick, (2) new timer (0 + 30 = 30s)
expect(mockDb.insert).toHaveBeenCalledTimes(2);
@ -394,7 +397,7 @@ describe("draft.force-manual-pick action", () => {
timeRemaining: 100,
});
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
// 100 + 30 = 130, not 120 (which would be a reset to initialTime)
expect(mockDb.set).toHaveBeenCalledWith(
@ -414,7 +417,7 @@ describe("draft.force-manual-pick action", () => {
// once to get the picking team's current balance, and
// once to find (and then reset) the next team's timer.
// After the fix it should be called exactly once.
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(mockDb.query.draftTimers.findFirst).toHaveBeenCalledTimes(1);
});
@ -422,7 +425,7 @@ describe("draft.force-manual-pick action", () => {
it("REGRESSION: does not emit a timer-update for the next team", async () => {
// Before the fix, a timer-update was emitted for the next team with
// timeRemaining: draftInitialTime (120s), overwriting their actual bank.
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
const nextTeamTimerEmits = mockSocketIO.emit.mock.calls.filter(
([event, payload]: [string, any]) =>
@ -435,7 +438,7 @@ describe("draft.force-manual-pick action", () => {
// Verify that db.update is called exactly twice (timer increment + season
// pick number), not three times (which would include resetting the next
// team's timer).
await action({ request: defaultPickRequest(), params: {}, context: {} });
await action({ request: defaultPickRequest(), params: {}, context: ctx });
expect(mockDb.update).toHaveBeenCalledTimes(2);
});

View file

@ -1,6 +1,9 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import type { RouterContextProvider } from "react-router";
import { action } from "~/routes/api/autodraft.update";
const ctx = {} as unknown as RouterContextProvider;
// Mock dependencies
vi.mock("~/database/context");
vi.mock("~/server/socket", () => ({
@ -94,7 +97,7 @@ describe("Autodraft Settings API", () => {
const response = await action({
request,
params: {},
context: {},
context: ctx,
});
const data = await response.json();
@ -163,7 +166,7 @@ describe("Autodraft Settings API", () => {
const response = await action({
request,
params: {},
context: {},
context: ctx,
});
const data = await response.json();
@ -206,7 +209,7 @@ describe("Autodraft Settings API", () => {
const response = await action({
request,
params: {},
context: {},
context: ctx,
});
expect(response.status).toBe(403);
@ -227,7 +230,7 @@ describe("Autodraft Settings API", () => {
const response = await action({
request,
params: {},
context: {},
context: ctx,
});
expect(response.status).toBe(400);
@ -274,7 +277,7 @@ describe("Autodraft Settings API", () => {
const response1 = await action({
request: request1,
params: {},
context: {},
context: ctx,
});
const data1 = await response1.json();
@ -306,7 +309,7 @@ describe("Autodraft Settings API", () => {
const response2 = await action({
request: request2,
params: {},
context: {},
context: ctx,
});
const data2 = await response2.json();
@ -355,7 +358,7 @@ describe("Autodraft Settings API", () => {
await action({
request,
params: {},
context: {},
context: ctx,
});
expect(mockSocketIO.to).toHaveBeenCalledWith(`draft-${seasonId}`);