Files
gitea-axi/test/issue-delete.test.ts
alexion 7a41807a8a
All checks were successful
CI / test (pull_request) Successful in 29s
CI / test (push) Successful in 32s
feat: add issue delete, pin, and unpin (task 0006)
Add the remaining simple issue mutations. `issue delete` hard-deletes via
the DELETE endpoint and is deliberately not idempotent — a nonexistent
issue yields ISSUE_NOT_FOUND rather than reporting success. `issue pin`
and `issue unpin` read the current pin state (Gitea's pin_order field) and
short-circuit to an idempotent no-op with an Already pinned/unpinned
message when there is nothing to do.
2026-07-12 19:02:02 -04:00

52 lines
1.7 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { startFixtureServer, type FixtureServer } from "./fixture-server.js";
import { runCliTest, testModeEnv } from "./harness.js";
const ISSUE_PATH = "/api/v1/repos/testowner/testrepo/issues/7";
let server: FixtureServer;
afterEach(async () => {
await server.close();
});
describe("issue delete", () => {
it("deletes an issue and reports the deletion", async () => {
server = await startFixtureServer([
{ method: "DELETE", path: ISSUE_PATH, status: 204 },
]);
const { stdout, exitCode } = await runCliTest(["issue", "delete", "7"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("issue:");
expect(stdout).toContain("number: 7");
expect(stdout).toContain("status: deleted");
expect(server.requests.some((request) => request.method === "DELETE")).toBe(true);
});
it("refuses to delete a nonexistent issue with ISSUE_NOT_FOUND", async () => {
server = await startFixtureServer([
{ method: "DELETE", path: ISSUE_PATH, status: 404, body: { message: "issue does not exist" } },
]);
const { stdout, exitCode } = await runCliTest(["issue", "delete", "7"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(1);
expect(stdout).toContain("code: ISSUE_NOT_FOUND");
});
it("prints help with --help without calling the API", async () => {
server = await startFixtureServer([]);
const { stdout, exitCode } = await runCliTest(["issue", "delete", "--help"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("usage: gitea-axi issue delete");
expect(server.requests).toHaveLength(0);
});
});