All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 2m27s
🚀 Deploy / ʦ TypeScript (pull_request) Successful in 1m16s
🚀 Deploy / 🔍 Lint (pull_request) Successful in 48s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
simulator-inputs: move dynamic import to top level so heavy module initialization happens during file load (no timeout) instead of inside the test body. llws-simulator: make iteration count injectable via constructor (default 50_000 for production, tests pass 1_000). Cuts test suite from ~4s per test to <150ms for all 21 tests combined. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
import { getParticipantSimulatorInputs } from "../simulator";
|
|
|
|
const mockDb = vi.hoisted(() => ({
|
|
query: {
|
|
seasonParticipants: { findMany: vi.fn() },
|
|
seasonParticipantSimulatorInputs: { findMany: vi.fn() },
|
|
seasonParticipantExpectedValues: { findMany: vi.fn() },
|
|
},
|
|
}));
|
|
|
|
vi.mock("~/database/context", () => ({
|
|
database: () => mockDb,
|
|
}));
|
|
|
|
describe("simulator input model", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("does not treat previously generated ratings as direct rating inputs", async () => {
|
|
mockDb.query.seasonParticipants.findMany.mockResolvedValue([
|
|
{ id: "direct-rating" },
|
|
{ id: "generated-rating" },
|
|
{ id: "legacy-direct-rating" },
|
|
]);
|
|
mockDb.query.seasonParticipantSimulatorInputs.findMany.mockResolvedValue([
|
|
{
|
|
participantId: "direct-rating",
|
|
sourceOdds: 750,
|
|
sourceElo: null,
|
|
worldRanking: null,
|
|
rating: "31.2500",
|
|
projectedWins: null,
|
|
projectedTablePoints: null,
|
|
seed: null,
|
|
region: null,
|
|
metadata: { ratingMethod: "direct" },
|
|
},
|
|
{
|
|
participantId: "generated-rating",
|
|
sourceOdds: 750,
|
|
sourceElo: null,
|
|
worldRanking: null,
|
|
rating: "35.0000",
|
|
projectedWins: null,
|
|
projectedTablePoints: null,
|
|
seed: null,
|
|
region: null,
|
|
metadata: { ratingMethod: "sourceOdds" },
|
|
},
|
|
{
|
|
participantId: "legacy-direct-rating",
|
|
sourceOdds: null,
|
|
sourceElo: null,
|
|
worldRanking: null,
|
|
rating: "27.5000",
|
|
projectedWins: null,
|
|
projectedTablePoints: null,
|
|
seed: null,
|
|
region: null,
|
|
metadata: null,
|
|
},
|
|
]);
|
|
mockDb.query.seasonParticipantExpectedValues.findMany.mockResolvedValue([]);
|
|
|
|
const inputs = await getParticipantSimulatorInputs("season-1");
|
|
const byParticipant = new Map(inputs.map((input) => [input.participantId, input]));
|
|
|
|
expect(byParticipant.get("direct-rating")?.rating).toBe(31.25);
|
|
expect(byParticipant.get("generated-rating")?.rating).toBeNull();
|
|
expect(byParticipant.get("legacy-direct-rating")?.rating).toBe(27.5);
|
|
});
|
|
});
|