Download src/lib/tools.test.ts from T2T-AI-X/copilot_work_3: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/T2T-AI-X/copilot_work_3/resolve/refs%2Fpr%2F4/src/lib/tools.test.ts
- Command line
-
hf download hf://T2T-AI-X/copilot_work_3@refs/pr/4/src/lib/tools.test.ts
-
curl -L -o tools.test.ts https://huggingface.co/T2T-AI-X/copilot_work_3/resolve/refs%2Fpr%2F4/src/lib/tools.test.ts
1.57 kB
| 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); | |
| }); | |
| }); | |