feat(FN-3573): harden plugin setup sync and test-isolation handling
- Add plugin setup API coverage for migration and sync edge cases - Expand plugin route tests and implementation safeguards for setup state handling - Update legacy API glue to align plugin setup responses with route behavior - Keep test-isolation runtime ignore handling compatible with live app activity Fusion-Task-Id: FN-3573
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { fetchPluginSetupStatus, installPluginSetup } from "../../api";
|
||||
|
||||
describe("plugin setup API helpers", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("fetchPluginSetupStatus calls setup-status endpoint with encoded id", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||
new Response(JSON.stringify({ hasSetup: true, status: "installed" }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
}),
|
||||
);
|
||||
|
||||
const result = await fetchPluginSetupStatus("plugin/id");
|
||||
|
||||
expect(result).toEqual({ hasSetup: true, status: "installed" });
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"/api/plugins/plugin%2Fid/setup-status",
|
||||
expect.objectContaining({
|
||||
headers: expect.objectContaining({ "Content-Type": "application/json" }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("fetchPluginSetupStatus includes projectId query parameter", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||
new Response(JSON.stringify({ hasSetup: false }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
}),
|
||||
);
|
||||
|
||||
await fetchPluginSetupStatus("my-plugin", "project/one");
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"/api/plugins/my-plugin/setup-status?projectId=project%2Fone",
|
||||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
|
||||
it("installPluginSetup posts to setup install endpoint and supports project scope", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
||||
new Response(JSON.stringify({ success: true }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
}),
|
||||
);
|
||||
|
||||
const result = await installPluginSetup("my plugin", "proj");
|
||||
|
||||
expect(result).toEqual({ success: true });
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"/api/plugins/my%20plugin/setup/install?projectId=proj",
|
||||
expect.objectContaining({ method: "POST" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,7 @@ import type {
|
||||
WorkflowStepInput,
|
||||
WorkflowStepResult,
|
||||
PluginInstallation,
|
||||
PluginSetupCheckResult,
|
||||
PluginUiSlotDefinition,
|
||||
PluginUiContributionDefinition,
|
||||
PluginDashboardViewDefinition,
|
||||
@@ -7763,6 +7764,23 @@ export async function updatePluginSettings(
|
||||
});
|
||||
}
|
||||
|
||||
export type PluginSetupStatusResponse =
|
||||
| { hasSetup: false }
|
||||
| { hasSetup: false; status: Extract<PluginSetupCheckResult, { status: "error" }> }
|
||||
| ({ hasSetup: true } & PluginSetupCheckResult);
|
||||
|
||||
/** Fetch plugin setup status */
|
||||
export async function fetchPluginSetupStatus(id: string, projectId?: string): Promise<PluginSetupStatusResponse> {
|
||||
return api<PluginSetupStatusResponse>(withProjectId(`/plugins/${encodeURIComponent(id)}/setup-status`, projectId));
|
||||
}
|
||||
|
||||
/** Trigger plugin setup install hook */
|
||||
export async function installPluginSetup(id: string, projectId?: string): Promise<{ success: boolean; error?: string }> {
|
||||
return api<{ success: boolean; error?: string }>(withProjectId(`/plugins/${encodeURIComponent(id)}/setup/install`, projectId), {
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
/** Reload a running plugin with updated code */
|
||||
export async function reloadPlugin(id: string, projectId?: string): Promise<PluginInstallation> {
|
||||
return api<PluginInstallation>(withProjectId(`/plugins/${encodeURIComponent(id)}/reload`, projectId), {
|
||||
|
||||
Reference in New Issue
Block a user