File size: 1,568 Bytes
416bdd1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import { beforeEach, describe, expect, it } from "vitest";
import { DuplicateRepoError, getTools, listToolsByStatus, rateTool, setToolStatus, submitTool } from "@/lib/tools";
const input = {
name: "Demo Tool",
summary: "A summary that is long enough to pass.",
category: "Planning" as const,
repoUrl: "https://github.com/Acme/Widget.git",
websiteUrl: "",
submittedBy: "Tester",
};
beforeEach(() => {
globalThis.__chainkitDemoState = undefined;
});
describe("demo store moderation", () => {
it("keeps new submissions hidden until approved", async () => {
const tool = await submitTool(input);
expect(tool.status).toBe("pending");
expect((await getTools()).some((t) => t.id === tool.id)).toBe(false);
expect(await rateTool(tool.id, crypto.randomUUID(), 5)).toBeUndefined();
await setToolStatus(tool.id, "approved");
expect((await getTools()).some((t) => t.id === tool.id)).toBe(true);
expect(await rateTool(tool.id, crypto.randomUUID(), 5)).toBeDefined();
});
it("rejects duplicates regardless of case, .git and trailing slash", async () => {
await submitTool(input);
await expect(submitTool({ ...input, repoUrl: "https://github.com/acme/widget/" })).rejects.toBeInstanceOf(
DuplicateRepoError,
);
});
it("allows resubmitting a repo after it was rejected", async () => {
const tool = await submitTool(input);
await setToolStatus(tool.id, "rejected");
await expect(submitTool(input)).resolves.toBeDefined();
expect(await listToolsByStatus("rejected")).toHaveLength(1);
});
});
|