Files
OmniRoute/tests/unit/shared/comboSchema.test.ts
Dizzle d5dfcfff58 feat(combo): choose sort method for combo models (manual/provider/score/name) (#11812)
Lets the combo dashboard builder order models manually/by-provider/by-score/by-name — the choice is stored in config.modelSort and re-applied on load and after adding models. Score-based ordering fetches provider rankings from the existing /api/free-provider-rankings endpoint; the field is inert on execution (client-side hint only). 9/9 focused tests passing (schema, sort logic, and rendered component). Thanks!
2026-08-28 12:37:58 -03:00

40 lines
1.5 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { comboRuntimeConfigSchema, updateComboSchema } from "@/shared/validation/schemas/combo";
describe("comboRuntimeConfigSchema.modelSort", () => {
it("accepts a valid modelSort method", () => {
const parsed = comboRuntimeConfigSchema.parse({ modelSort: { method: "provider" } });
assert.deepEqual(parsed.modelSort, { method: "provider" });
});
it("rejects an invalid method", () => {
assert.throws(() => comboRuntimeConfigSchema.parse({ modelSort: { method: "bogus" } }));
});
it("allows extra keys on the modelSort sub-object (passthrough)", () => {
const parsed = comboRuntimeConfigSchema.parse({ modelSort: { method: "name", future: 1 } });
assert.equal(parsed.modelSort?.method, "name");
});
it("is optional", () => {
const parsed = comboRuntimeConfigSchema.parse({});
assert.equal(parsed.modelSort, undefined);
});
});
describe("modelSort persistence", () => {
it("round-trips through updateComboSchema (models + config)", () => {
const parsed = updateComboSchema.parse({
models: [{ id: "m1", kind: "model", model: "openai/gpt", providerId: "openai", weight: 0 }],
config: { modelSort: { method: "score" } },
});
assert.equal(parsed.config?.modelSort?.method, "score");
});
it("passes through comboRuntimeConfigSchema", () => {
const parsed = comboRuntimeConfigSchema.parse({ modelSort: { method: "provider" } });
assert.equal(parsed.modelSort?.method, "provider");
});
});