2025-10-21 23:22:17 -07:00
|
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
import type { RouterContextProvider } from "react-router";
|
2025-10-24 21:20:19 -07:00
|
|
|
import { action } from "~/routes/api/autodraft.update";
|
2025-10-21 23:22:17 -07:00
|
|
|
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
const ctx = {} as unknown as RouterContextProvider;
|
|
|
|
|
|
2025-10-21 23:22:17 -07:00
|
|
|
// Mock dependencies
|
2025-10-24 21:20:19 -07:00
|
|
|
vi.mock("~/database/context");
|
|
|
|
|
vi.mock("~/server/socket", () => ({
|
2025-10-21 23:22:17 -07:00
|
|
|
getSocketIO: vi.fn(),
|
|
|
|
|
}));
|
|
|
|
|
vi.mock("@clerk/react-router/server", () => ({
|
|
|
|
|
getAuth: vi.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe("Autodraft Settings API", () => {
|
|
|
|
|
let mockDb: any;
|
|
|
|
|
let mockSocketIO: any;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
|
|
|
|
|
// Mock Clerk auth
|
|
|
|
|
const { getAuth } = await import("@clerk/react-router/server");
|
|
|
|
|
vi.mocked(getAuth).mockResolvedValue({ userId: "user-789" } as any);
|
|
|
|
|
|
|
|
|
|
// Mock Socket.IO
|
|
|
|
|
mockSocketIO = {
|
|
|
|
|
to: vi.fn().mockReturnThis(),
|
|
|
|
|
emit: vi.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-24 21:20:19 -07:00
|
|
|
const socketModule = await import("~/server/socket");
|
2025-10-21 23:22:17 -07:00
|
|
|
vi.mocked(socketModule.getSocketIO).mockReturnValue(mockSocketIO);
|
|
|
|
|
|
|
|
|
|
// Mock database
|
|
|
|
|
mockDb = {
|
|
|
|
|
query: {
|
|
|
|
|
teams: {
|
|
|
|
|
findFirst: vi.fn(),
|
|
|
|
|
},
|
|
|
|
|
autodraftSettings: {
|
|
|
|
|
findFirst: vi.fn(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
update: vi.fn().mockReturnThis(),
|
|
|
|
|
set: vi.fn().mockReturnThis(),
|
|
|
|
|
where: vi.fn().mockReturnThis(),
|
|
|
|
|
returning: vi.fn(),
|
|
|
|
|
insert: vi.fn().mockReturnThis(),
|
|
|
|
|
values: vi.fn().mockReturnThis(),
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-24 21:20:19 -07:00
|
|
|
const { database } = await import("~/database/context");
|
2025-10-21 23:22:17 -07:00
|
|
|
vi.mocked(database).mockReturnValue(mockDb);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("Update Autodraft Settings", () => {
|
|
|
|
|
it("should create new autodraft settings when none exist", async () => {
|
|
|
|
|
const seasonId = "season-123";
|
|
|
|
|
const teamId = "team-456";
|
|
|
|
|
const userId = "user-789";
|
|
|
|
|
|
|
|
|
|
// Mock team ownership verification
|
|
|
|
|
mockDb.query.teams.findFirst.mockResolvedValue({
|
|
|
|
|
id: teamId,
|
|
|
|
|
ownerId: userId,
|
|
|
|
|
name: "Test Team",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Mock no existing settings
|
|
|
|
|
mockDb.query.autodraftSettings.findFirst.mockResolvedValue(null);
|
|
|
|
|
|
|
|
|
|
// Mock insert returning new settings
|
|
|
|
|
const newSettings = {
|
|
|
|
|
id: "settings-1",
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "next_pick",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: false,
|
2025-10-21 23:22:17 -07:00
|
|
|
createdAt: new Date(),
|
|
|
|
|
updatedAt: new Date(),
|
|
|
|
|
};
|
|
|
|
|
mockDb.returning.mockResolvedValue([newSettings]);
|
|
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("seasonId", seasonId);
|
|
|
|
|
formData.append("teamId", teamId);
|
|
|
|
|
formData.append("isEnabled", "true");
|
|
|
|
|
formData.append("mode", "next_pick");
|
2026-02-27 23:57:42 +00:00
|
|
|
formData.append("queueOnly", "false");
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const request = new Request("http://localhost/api/autodraft/update", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
body: formData,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await action({
|
|
|
|
|
request,
|
|
|
|
|
params: {},
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
context: ctx,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
|
|
expect(data.success).toBe(true);
|
|
|
|
|
expect(data.settings.id).toBe(newSettings.id);
|
2026-02-27 23:57:42 +00:00
|
|
|
expect(data.settings.isEnabled).toBe(true);
|
|
|
|
|
expect(data.settings.mode).toBe("next_pick");
|
2025-10-21 23:22:17 -07:00
|
|
|
expect(mockDb.insert).toHaveBeenCalled();
|
|
|
|
|
expect(mockSocketIO.to).toHaveBeenCalledWith(`draft-${seasonId}`);
|
|
|
|
|
expect(mockSocketIO.emit).toHaveBeenCalledWith("autodraft-updated", {
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "next_pick",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: false,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should update existing autodraft settings", async () => {
|
|
|
|
|
const seasonId = "season-123";
|
|
|
|
|
const teamId = "team-456";
|
|
|
|
|
const userId = "user-789";
|
|
|
|
|
|
|
|
|
|
mockDb.query.teams.findFirst.mockResolvedValue({
|
|
|
|
|
id: teamId,
|
|
|
|
|
ownerId: userId,
|
|
|
|
|
name: "Test Team",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const existingSettings = {
|
|
|
|
|
id: "settings-1",
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: false,
|
|
|
|
|
mode: "next_pick",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: false,
|
2025-10-21 23:22:17 -07:00
|
|
|
createdAt: new Date(),
|
|
|
|
|
updatedAt: new Date(),
|
|
|
|
|
};
|
2026-02-27 23:57:42 +00:00
|
|
|
mockDb.query.autodraftSettings.findFirst.mockResolvedValue(existingSettings);
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const updatedSettings = {
|
|
|
|
|
...existingSettings,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "while_on",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: false,
|
2025-10-21 23:22:17 -07:00
|
|
|
updatedAt: new Date(),
|
|
|
|
|
};
|
|
|
|
|
mockDb.returning.mockResolvedValue([updatedSettings]);
|
|
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("seasonId", seasonId);
|
|
|
|
|
formData.append("teamId", teamId);
|
|
|
|
|
formData.append("isEnabled", "true");
|
|
|
|
|
formData.append("mode", "while_on");
|
2026-02-27 23:57:42 +00:00
|
|
|
formData.append("queueOnly", "false");
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const request = new Request("http://localhost/api/autodraft/update", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
body: formData,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await action({
|
|
|
|
|
request,
|
|
|
|
|
params: {},
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
context: ctx,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
|
|
expect(data.success).toBe(true);
|
|
|
|
|
expect(data.settings.isEnabled).toBe(true);
|
|
|
|
|
expect(data.settings.mode).toBe("while_on");
|
|
|
|
|
expect(mockDb.update).toHaveBeenCalled();
|
|
|
|
|
expect(mockSocketIO.emit).toHaveBeenCalledWith("autodraft-updated", {
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "while_on",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: false,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should save queueOnly flag correctly", async () => {
|
|
|
|
|
const seasonId = "season-123";
|
|
|
|
|
const teamId = "team-456";
|
|
|
|
|
const userId = "user-789";
|
|
|
|
|
|
|
|
|
|
mockDb.query.teams.findFirst.mockResolvedValue({
|
|
|
|
|
id: teamId,
|
|
|
|
|
ownerId: userId,
|
|
|
|
|
name: "Test Team",
|
|
|
|
|
});
|
|
|
|
|
mockDb.query.autodraftSettings.findFirst.mockResolvedValue(null);
|
|
|
|
|
|
|
|
|
|
const newSettings = {
|
|
|
|
|
id: "settings-1",
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "next_pick",
|
|
|
|
|
queueOnly: true,
|
|
|
|
|
createdAt: new Date(),
|
|
|
|
|
updatedAt: new Date(),
|
|
|
|
|
};
|
|
|
|
|
mockDb.returning.mockResolvedValue([newSettings]);
|
|
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("seasonId", seasonId);
|
|
|
|
|
formData.append("teamId", teamId);
|
|
|
|
|
formData.append("isEnabled", "true");
|
|
|
|
|
formData.append("mode", "next_pick");
|
|
|
|
|
formData.append("queueOnly", "true");
|
|
|
|
|
|
|
|
|
|
const request = new Request("http://localhost/api/autodraft/update", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
body: formData,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await action({
|
|
|
|
|
request,
|
|
|
|
|
params: {},
|
|
|
|
|
context: ctx,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
|
|
expect(data.success).toBe(true);
|
|
|
|
|
expect(data.settings.queueOnly).toBe(true);
|
|
|
|
|
expect(mockSocketIO.emit).toHaveBeenCalledWith("autodraft-updated", {
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "next_pick",
|
|
|
|
|
queueOnly: true,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should reject unauthorized users", async () => {
|
|
|
|
|
const seasonId = "season-123";
|
|
|
|
|
const teamId = "team-456";
|
|
|
|
|
const differentUserId = "user-999";
|
|
|
|
|
|
|
|
|
|
mockDb.query.teams.findFirst.mockResolvedValue({
|
|
|
|
|
id: teamId,
|
|
|
|
|
ownerId: differentUserId,
|
|
|
|
|
name: "Test Team",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("seasonId", seasonId);
|
|
|
|
|
formData.append("teamId", teamId);
|
|
|
|
|
formData.append("isEnabled", "true");
|
|
|
|
|
formData.append("mode", "next_pick");
|
|
|
|
|
|
|
|
|
|
const request = new Request("http://localhost/api/autodraft/update", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
body: formData,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await action({
|
|
|
|
|
request,
|
|
|
|
|
params: {},
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
context: ctx,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(response.status).toBe(403);
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
expect(data.error).toBe("Unauthorized");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should require all fields", async () => {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("seasonId", "season-123");
|
|
|
|
|
// Missing teamId and mode
|
|
|
|
|
|
|
|
|
|
const request = new Request("http://localhost/api/autodraft/update", {
|
|
|
|
|
method: "POST",
|
|
|
|
|
body: formData,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await action({
|
|
|
|
|
request,
|
|
|
|
|
params: {},
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
context: ctx,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(response.status).toBe(400);
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
expect(data.error).toBe("Missing required fields");
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-27 23:57:42 +00:00
|
|
|
it("should handle all three autodraft states (Off, Next Pick, All Picks)", async () => {
|
2025-10-21 23:22:17 -07:00
|
|
|
const seasonId = "season-123";
|
|
|
|
|
const teamId = "team-456";
|
|
|
|
|
const userId = "user-789";
|
|
|
|
|
|
|
|
|
|
mockDb.query.teams.findFirst.mockResolvedValue({
|
|
|
|
|
id: teamId,
|
|
|
|
|
ownerId: userId,
|
|
|
|
|
name: "Test Team",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mockDb.query.autodraftSettings.findFirst.mockResolvedValue(null);
|
|
|
|
|
|
2026-02-27 23:57:42 +00:00
|
|
|
// State 1: Off (isEnabled=false)
|
|
|
|
|
const offSettings = {
|
2025-10-21 23:22:17 -07:00
|
|
|
id: "settings-1",
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId,
|
2026-02-27 23:57:42 +00:00
|
|
|
isEnabled: false,
|
2025-10-21 23:22:17 -07:00
|
|
|
mode: "next_pick",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: false,
|
2025-10-21 23:22:17 -07:00
|
|
|
createdAt: new Date(),
|
|
|
|
|
updatedAt: new Date(),
|
|
|
|
|
};
|
2026-02-27 23:57:42 +00:00
|
|
|
mockDb.returning.mockResolvedValueOnce([offSettings]);
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const formData1 = new FormData();
|
|
|
|
|
formData1.append("seasonId", seasonId);
|
|
|
|
|
formData1.append("teamId", teamId);
|
2026-02-27 23:57:42 +00:00
|
|
|
formData1.append("isEnabled", "false");
|
2025-10-21 23:22:17 -07:00
|
|
|
formData1.append("mode", "next_pick");
|
2026-02-27 23:57:42 +00:00
|
|
|
formData1.append("queueOnly", "false");
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const response1 = await action({
|
2026-02-27 23:57:42 +00:00
|
|
|
request: new Request("http://localhost/api/autodraft/update", { method: "POST", body: formData1 }),
|
2025-10-21 23:22:17 -07:00
|
|
|
params: {},
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
context: ctx,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
const data1 = await response1.json();
|
2026-02-27 23:57:42 +00:00
|
|
|
expect(data1.settings.isEnabled).toBe(false);
|
2025-10-21 23:22:17 -07:00
|
|
|
|
2026-02-27 23:57:42 +00:00
|
|
|
// State 2: Next Pick (isEnabled=true, mode=next_pick)
|
|
|
|
|
const nextPickSettings = { ...offSettings, id: "settings-2", isEnabled: true, mode: "next_pick" };
|
|
|
|
|
mockDb.returning.mockResolvedValueOnce([nextPickSettings]);
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const formData2 = new FormData();
|
|
|
|
|
formData2.append("seasonId", seasonId);
|
|
|
|
|
formData2.append("teamId", teamId);
|
|
|
|
|
formData2.append("isEnabled", "true");
|
2026-02-27 23:57:42 +00:00
|
|
|
formData2.append("mode", "next_pick");
|
|
|
|
|
formData2.append("queueOnly", "false");
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const response2 = await action({
|
2026-02-27 23:57:42 +00:00
|
|
|
request: new Request("http://localhost/api/autodraft/update", { method: "POST", body: formData2 }),
|
2025-10-21 23:22:17 -07:00
|
|
|
params: {},
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
context: ctx,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
const data2 = await response2.json();
|
2026-02-27 23:57:42 +00:00
|
|
|
expect(data2.settings.isEnabled).toBe(true);
|
|
|
|
|
expect(data2.settings.mode).toBe("next_pick");
|
|
|
|
|
|
|
|
|
|
// State 3: All Picks (isEnabled=true, mode=while_on)
|
|
|
|
|
const allPicksSettings = { ...offSettings, id: "settings-3", isEnabled: true, mode: "while_on" };
|
|
|
|
|
mockDb.returning.mockResolvedValueOnce([allPicksSettings]);
|
|
|
|
|
|
|
|
|
|
const formData3 = new FormData();
|
|
|
|
|
formData3.append("seasonId", seasonId);
|
|
|
|
|
formData3.append("teamId", teamId);
|
|
|
|
|
formData3.append("isEnabled", "true");
|
|
|
|
|
formData3.append("mode", "while_on");
|
|
|
|
|
formData3.append("queueOnly", "false");
|
|
|
|
|
|
|
|
|
|
const response3 = await action({
|
|
|
|
|
request: new Request("http://localhost/api/autodraft/update", { method: "POST", body: formData3 }),
|
|
|
|
|
params: {},
|
|
|
|
|
context: ctx,
|
|
|
|
|
});
|
|
|
|
|
const data3 = await response3.json();
|
|
|
|
|
expect(data3.settings.isEnabled).toBe(true);
|
|
|
|
|
expect(data3.settings.mode).toBe("while_on");
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
|
2026-02-27 23:57:42 +00:00
|
|
|
it("should emit socket event to correct room with queueOnly included", async () => {
|
2025-10-21 23:22:17 -07:00
|
|
|
const seasonId = "season-abc";
|
|
|
|
|
const teamId = "team-xyz";
|
|
|
|
|
const userId = "user-123";
|
|
|
|
|
|
|
|
|
|
const { getAuth } = await import("@clerk/react-router/server");
|
|
|
|
|
vi.mocked(getAuth).mockResolvedValue({ userId } as any);
|
|
|
|
|
|
|
|
|
|
mockDb.query.teams.findFirst.mockResolvedValue({
|
|
|
|
|
id: teamId,
|
|
|
|
|
ownerId: userId,
|
|
|
|
|
name: "Test Team",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mockDb.query.autodraftSettings.findFirst.mockResolvedValue(null);
|
|
|
|
|
|
2026-02-27 23:57:42 +00:00
|
|
|
mockDb.returning.mockResolvedValue([{
|
2025-10-21 23:22:17 -07:00
|
|
|
id: "settings-1",
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "next_pick",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: true,
|
2025-10-21 23:22:17 -07:00
|
|
|
createdAt: new Date(),
|
|
|
|
|
updatedAt: new Date(),
|
2026-02-27 23:57:42 +00:00
|
|
|
}]);
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("seasonId", seasonId);
|
|
|
|
|
formData.append("teamId", teamId);
|
|
|
|
|
formData.append("isEnabled", "true");
|
|
|
|
|
formData.append("mode", "next_pick");
|
2026-02-27 23:57:42 +00:00
|
|
|
formData.append("queueOnly", "true");
|
2025-10-21 23:22:17 -07:00
|
|
|
|
|
|
|
|
await action({
|
2026-02-27 23:57:42 +00:00
|
|
|
request: new Request("http://localhost/api/autodraft/update", { method: "POST", body: formData }),
|
2025-10-21 23:22:17 -07:00
|
|
|
params: {},
|
Claude/fix pick timer ghll n (#29)
* Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was
being reset to the initial time (2 minutes) instead of carrying
forward their existing time bank balance.
This aligns force-manual-pick with the behavior of regular user picks
and force-autopick: the picking team gets their increment added, and
the next team's timer is left untouched so their bank carries forward.
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add regression tests for draft.force-manual-pick timer behavior
18 tests across 5 describe blocks covering:
- Authorization (401/403)
- Input validation (missing fields, bad participant, ineligible sport)
- Successful pick (response shape, draft-complete detection, socket events)
- Timer behavior (increment added to picking team, new timer creation, additive not reset)
- Two regression tests confirming the next team's timer is never touched:
draftTimers.findFirst called exactly once, no timer-update emitted for
next team, db.update called exactly twice (not three times)
https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
* Add TypeScript types and improve draft validation (#28)
* Code review fixes: type safety, security hardening, and dead code removal
- Fix Socket.IO event types: draft-paused and draft-resumed were typed as
() => void but are emitted with { seasonId, paused } data payloads
- Fix draft.force-manual-pick: add missing season.status === "draft" guard
so commissioners cannot force picks outside an active draft; add duplicate
pick-number check so a slot cannot be assigned two picks (the previous
code only checked participant uniqueness, not slot uniqueness)
- Replace args: any with ActionFunctionArgs / Route.LoaderArgs across all
API routes and league loaders; replace (auth as any).userId casts with
proper const { userId } = await getAuth(args) destructuring
- Remove unused isSnakeDraft = true dead variable from draft.make-pick
- Replace autodraftSettings: any and draftSlots: any[] in draft-utils with
properly typed InferSelectModel / DraftSlot types
- Update force-manual-pick tests: sequence draftPicks.findFirst mock for
the two-call flow; add new tests for status-check and slot-uniqueness
https://claude.ai/code/session_01FKq2gPFYpgdfxr8cw4Z2AZ
* 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
---------
Co-authored-by: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-22 19:29:29 -08:00
|
|
|
context: ctx,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(mockSocketIO.to).toHaveBeenCalledWith(`draft-${seasonId}`);
|
|
|
|
|
expect(mockSocketIO.emit).toHaveBeenCalledWith("autodraft-updated", {
|
|
|
|
|
teamId,
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
mode: "next_pick",
|
2026-02-27 23:57:42 +00:00
|
|
|
queueOnly: true,
|
2025-10-21 23:22:17 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|