test(api): add triggerInsightRun model params tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Timothy Laurent
2026-05-06 08:10:54 -07:00
parent 6e81daf98f
commit c6571eea4e

View File

@@ -78,6 +78,7 @@ import {
type GlobalConcurrencyState,
type ExecutorStats,
type ExecutorState,
triggerInsightRun,
} from "../api";
import type { Task, TaskDetail, BatchStatusResponse, MergeResult } from "@fusion/core";
import { clearAuthToken } from "../auth";
@@ -1002,3 +1003,52 @@ describe("batchUpdateTaskModels", () => {
});
});
describe("triggerInsightRun", () => {
const originalFetch = globalThis.fetch;
beforeEach(() => {
clearAuthToken();
localStorage.removeItem("fn.authToken");
});
afterEach(() => {
globalThis.fetch = originalFetch;
clearAuthToken();
localStorage.removeItem("fn.authToken");
});
it("sends POST to /api/insights/run without model params by default", async () => {
globalThis.fetch = vi.fn().mockReturnValue(mockFetchResponse(true, { id: "INSR-test", status: "completed" }));
await triggerInsightRun("manual");
const call = (globalThis.fetch as ReturnType<typeof vi.fn>).mock.calls[0];
const body = JSON.parse(call[1].body);
expect(body).not.toHaveProperty("modelProvider");
expect(body).not.toHaveProperty("modelId");
expect(body.trigger).toBe("manual");
});
it("includes modelProvider and modelId in POST body when provided", async () => {
globalThis.fetch = vi.fn().mockReturnValue(mockFetchResponse(true, { id: "INSR-test", status: "completed" }));
await triggerInsightRun("manual", undefined, undefined, "openai", "gpt-4o");
const call = (globalThis.fetch as ReturnType<typeof vi.fn>).mock.calls[0];
const body = JSON.parse(call[1].body);
expect(body.modelProvider).toBe("openai");
expect(body.modelId).toBe("gpt-4o");
});
it("omits model params when provider is empty string", async () => {
globalThis.fetch = vi.fn().mockReturnValue(mockFetchResponse(true, { id: "INSR-test", status: "completed" }));
await triggerInsightRun("manual", undefined, undefined, "", "");
const call = (globalThis.fetch as ReturnType<typeof vi.fn>).mock.calls[0];
const body = JSON.parse(call[1].body);
expect(body).not.toHaveProperty("modelProvider");
expect(body).not.toHaveProperty("modelId");
});
});