OmniRoute/open-sse/mcp-server/__tests__/pricingSync.test.ts
Regis 7db280ee64 fix(api): address review feedback on pricing sync
- Add .catch() to initial and periodic sync promises (Gemini, Kilo)
- Wrap JSON.parse in try-catch for corrupted DB data (Kilo)
- Wrap response.json() in try-catch for invalid LiteLLM JSON (Kilo)
- Validate PRICING_SYNC_INTERVAL (guard against NaN/0 → tight loop) (Copilot)
- Validate and allowlist sources — reject unknown, prevent empty sync
  from clearing pricing_synced data (Copilot, Kilo)
- Extract merge loop into shared iteration to reduce duplication (Gemini)
- Add data/warnings fields to MCP output schema (Copilot)
- Remove unused z import in vitest (Copilot)
- Filter non-string entries from sources array in API route (Copilot)
- Track active interval for accurate getSyncStatus().nextSync (Copilot)
2026-03-14 19:01:27 +01:00

59 lines
1.9 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { syncPricingInput, syncPricingTool, MCP_TOOLS, MCP_TOOL_MAP } from "../schemas/tools.ts";
describe("omniroute_sync_pricing MCP tool schema", () => {
it("should be registered in MCP_TOOLS", () => {
const tool = MCP_TOOLS.find((t) => t.name === "omniroute_sync_pricing");
expect(tool).toBeDefined();
expect(tool?.phase).toBe(2);
});
it("should be in MCP_TOOL_MAP", () => {
expect(MCP_TOOL_MAP["omniroute_sync_pricing"]).toBeDefined();
});
it("should require pricing:write scope", () => {
expect(syncPricingTool.scopes).toContain("pricing:write");
});
it("should have full audit level", () => {
expect(syncPricingTool.auditLevel).toBe("full");
});
it("should validate empty input (all fields optional)", () => {
const result = syncPricingInput.safeParse({});
expect(result.success).toBe(true);
});
it("should validate input with sources array", () => {
const result = syncPricingInput.safeParse({ sources: ["litellm"] });
expect(result.success).toBe(true);
});
it("should validate input with dryRun", () => {
const result = syncPricingInput.safeParse({ dryRun: true });
expect(result.success).toBe(true);
});
it("should validate full input", () => {
const result = syncPricingInput.safeParse({
sources: ["litellm"],
dryRun: false,
});
expect(result.success).toBe(true);
});
it("should reject invalid sources type", () => {
const result = syncPricingInput.safeParse({ sources: "litellm" });
expect(result.success).toBe(false);
});
it("should reject invalid dryRun type", () => {
const result = syncPricingInput.safeParse({ dryRun: "yes" });
expect(result.success).toBe(false);
});
it("should point to correct source endpoint", () => {
expect(syncPricingTool.sourceEndpoints).toContain("/api/pricing/sync");
});
});