import { describe, expect, it } from "vitest"; import { parseBaseEloPriorityChoice, projectionMethodMetadata, resolvedInputMethodLabel, } from "../admin.sports-seasons.$id.simulator.helpers"; import { DEFAULT_BASE_ELO_PRIORITY } from "~/services/simulations/input-policy"; describe("projectionMethodMetadata", () => { it("flags a row that supplies projected wins and no Elo", () => { expect(projectionMethodMetadata(undefined, 95, undefined)).toEqual({ sourceEloMethod: "projectedWins", }); }); it("flags a row that supplies projected table points and no Elo", () => { expect(projectionMethodMetadata(undefined, undefined, 76.5)).toEqual({ sourceEloMethod: "projectedTablePoints", }); }); it("leaves metadata alone when the row supplies an explicit Elo", () => { // An explicit Elo is a direct entry and must stay trusted, even alongside a // projection — the upsert then clears any stale generated flag. expect(projectionMethodMetadata(1600, 95, undefined)).toBeUndefined(); }); it("leaves metadata alone for a row with neither", () => { expect(projectionMethodMetadata(undefined, undefined, undefined)).toBeUndefined(); }); it("prefers wins over table points when a row somehow carries both", () => { expect(projectionMethodMetadata(undefined, 95, 76.5)).toEqual({ sourceEloMethod: "projectedWins", }); }); }); describe("parseBaseEloPriorityChoice", () => { it("puts projections ahead of raw Elo", () => { expect(parseBaseEloPriorityChoice("projectionsFirst", DEFAULT_BASE_ELO_PRIORITY)).toEqual([ "projectedWins", "projectedTablePoints", "sourceElo", ]); }); it("puts raw Elo first for eloFirst", () => { expect(parseBaseEloPriorityChoice("eloFirst", DEFAULT_BASE_ELO_PRIORITY)).toEqual( DEFAULT_BASE_ELO_PRIORITY ); }); it("keeps the stored ordering when the select was not on the form", () => { // Simulators with no projection alternative never render the control; saving // other config must not rewrite their ordering. const custom: typeof DEFAULT_BASE_ELO_PRIORITY = ["projectedWins", "sourceElo"]; expect(parseBaseEloPriorityChoice(null, custom)).toEqual(custom); }); it("preserves the relative order of the projection keys", () => { expect( parseBaseEloPriorityChoice("projectionsFirst", [ "projectedTablePoints", "sourceElo", "projectedWins", ]) ).toEqual(["projectedTablePoints", "projectedWins", "sourceElo"]); }); it("round-trips: flipping back restores Elo-first", () => { const flipped = parseBaseEloPriorityChoice("projectionsFirst", DEFAULT_BASE_ELO_PRIORITY); expect(parseBaseEloPriorityChoice("eloFirst", flipped)).toEqual(DEFAULT_BASE_ELO_PRIORITY); }); }); describe("resolvedInputMethodLabel", () => { it("badges nothing for a directly entered Elo or rating", () => { expect(resolvedInputMethodLabel("direct")).toBeNull(); }); it("badges both projection methods the same way", () => { expect(resolvedInputMethodLabel("projectedWins")).toBe("from projections"); expect(resolvedInputMethodLabel("projectedTablePoints")).toBe("from projections"); }); it("distinguishes futures and blended Elo", () => { expect(resolvedInputMethodLabel("sourceOdds")).toBe("from futures"); expect(resolvedInputMethodLabel("blend")).toBe("blended"); }); it("badges every missing-input strategy as a fallback", () => { expect(resolvedInputMethodLabel("fallbackElo")).toBe("fallback"); expect(resolvedInputMethodLabel("fallbackRating")).toBe("fallback"); expect(resolvedInputMethodLabel("averageKnown")).toBe("fallback"); expect(resolvedInputMethodLabel("worstKnownMinus")).toBe("fallback"); }); });