4fa4f13558
Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { removeSkillFromGateway } from "@/lib/skills/remove";
|
|
|
|
describe("skills remove client", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("posts skill removal payload to the Studio API route", async () => {
|
|
const fetchMock = vi.fn(async () => ({
|
|
ok: true,
|
|
text: async () =>
|
|
JSON.stringify({
|
|
result: {
|
|
removed: true,
|
|
removedPath: "/tmp/workspace/skills/github",
|
|
source: "openclaw-workspace",
|
|
},
|
|
}),
|
|
}));
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
const result = await removeSkillFromGateway({
|
|
skillKey: " github ",
|
|
source: "openclaw-workspace",
|
|
baseDir: " /tmp/workspace/skills/github ",
|
|
workspaceDir: " /tmp/workspace ",
|
|
managedSkillsDir: " /tmp/managed ",
|
|
});
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith("/api/gateway/skills/remove", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({
|
|
skillKey: "github",
|
|
source: "openclaw-workspace",
|
|
baseDir: "/tmp/workspace/skills/github",
|
|
workspaceDir: "/tmp/workspace",
|
|
managedSkillsDir: "/tmp/managed",
|
|
}),
|
|
});
|
|
expect(result).toEqual({
|
|
removed: true,
|
|
removedPath: "/tmp/workspace/skills/github",
|
|
source: "openclaw-workspace",
|
|
});
|
|
});
|
|
|
|
it("fails fast when required payload fields are missing", async () => {
|
|
await expect(
|
|
removeSkillFromGateway({
|
|
skillKey: " ",
|
|
source: "openclaw-workspace",
|
|
baseDir: "/tmp/workspace/skills/github",
|
|
workspaceDir: "/tmp/workspace",
|
|
managedSkillsDir: "/tmp/managed",
|
|
})
|
|
).rejects.toThrow("skillKey is required.");
|
|
|
|
await expect(
|
|
removeSkillFromGateway({
|
|
skillKey: "github",
|
|
source: "openclaw-workspace",
|
|
baseDir: " ",
|
|
workspaceDir: "/tmp/workspace",
|
|
managedSkillsDir: "/tmp/managed",
|
|
})
|
|
).rejects.toThrow("baseDir is required.");
|
|
});
|
|
});
|