Files
gitea-axi/test/issue-reopen.test.ts
alexion 6296f47fab
All checks were successful
CI / test (pull_request) Successful in 27s
CI / test (push) Successful in 37s
feat: add issue edit, close, and reopen (task 0005)
Implement the issue state-transition mutations:

- issue edit: --title, --body/--body-file, --add-label/--remove-label,
  --add-assignee/--remove-assignee, --milestone. Label mutations use
  Gitea's dedicated additive/removal endpoints (names added directly,
  removals resolved to IDs, unapplied-label 404 as silent success);
  assignees use fetch-then-patch (ADR 0007); title/body/milestone and the
  recomputed assignee list travel in one PATCH. Outputs edited: {number,
  status: ok}.
- issue close: PATCHes state closed, optional --comment posted after with
  its failure surfaced; already-closed short-circuits with Already closed.
- issue reopen: PATCHes state open; already-open short-circuits with
  Already open.

Extract a shared getIssue helper used by view/edit/close/reopen.
2026-07-12 09:47:51 -04:00

55 lines
1.9 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 reopen", () => {
it("reopens a closed issue and reports the action", async () => {
server = await startFixtureServer([
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "closed" } },
{ method: "PATCH", path: ISSUE_PATH, body: { number: 7, state: "open" } },
]);
const { stdout, exitCode } = await runCliTest(["issue", "reopen", "7"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("reopened:");
expect(stdout).toContain("number: 7");
expect(stdout).toContain("status: ok");
const patch = server.requests.find((request) => request.method === "PATCH");
expect(patch?.body).toEqual({ state: "open" });
});
it("returns early with Already open on an already-open issue", async () => {
server = await startFixtureServer([
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "open" } },
]);
const { stdout, exitCode } = await runCliTest(["issue", "reopen", "7"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("message: Already open");
expect(server.requests.some((request) => request.method === "PATCH")).toBe(false);
});
it("prints help with --help without calling the API", async () => {
server = await startFixtureServer([]);
const { stdout, exitCode } = await runCliTest(["issue", "reopen", "--help"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("usage: gitea-axi issue reopen");
expect(server.requests).toHaveLength(0);
});
});