| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import type { PullRequestActivity, PullRequestReviewThread } from "@t3tools/contracts"; |
| 3 | |
| 4 | import { settledReviewSummary } from "./pullRequestReviewGuideInput.ts"; |
| 5 | |
| 6 | const thread = ( |
| 7 | overrides: Partial<PullRequestReviewThread> & { body?: string; login?: string }, |
| 8 | ): PullRequestReviewThread => ({ |
| 9 | id: overrides.id ?? "t1", |
| 10 | path: overrides.path ?? "src/a.ts", |
| 11 | line: 1, |
| 12 | side: "right", |
| 13 | isResolved: overrides.isResolved ?? false, |
| 14 | isOutdated: overrides.isOutdated ?? false, |
| 15 | comments: [ |
| 16 | { |
| 17 | id: "c1", |
| 18 | author: { login: overrides.login ?? "macroscope[bot]", name: null, avatarUrl: null }, |
| 19 | body: overrides.body ?? "Possible null dereference", |
| 20 | createdAt: "2026-10-01T00:00:00.000Z", |
| 21 | url: null, |
| 22 | }, |
| 23 | ], |
| 24 | }); |
| 25 | |
| 26 | const activity = (reviewThreads: ReadonlyArray<PullRequestReviewThread>): PullRequestActivity => ({ |
| 27 | comments: [], |
| 28 | commentCount: 0, |
| 29 | commentsTruncated: false, |
| 30 | reviewThreads, |
| 31 | commits: [], |
| 32 | }); |
| 33 | |
| 34 | describe("settledReviewSummary", () => { |
| 35 | it("lists resolved and outdated threads and leaves open ones for the guide", () => { |
| 36 | const summary = settledReviewSummary( |
| 37 | activity([ |
| 38 | thread({ id: "open", path: "src/open.ts", body: "Still open" }), |
| 39 | thread({ id: "resolved", path: "src/a.ts", isResolved: true }), |
| 40 | thread({ |
| 41 | id: "outdated", |
| 42 | path: "src/b.ts", |
| 43 | isOutdated: true, |
| 44 | login: "julius", |
| 45 | body: "Rename this <!-- bot:meta -->\n\nplease", |
| 46 | }), |
| 47 | ]), |
| 48 | ); |
| 49 | |
| 50 | expect(summary).toBe( |
| 51 | [ |
| 52 | "- src/a.ts (resolved, macroscope[bot]): Possible null dereference", |
| 53 | "- src/b.ts (outdated, julius): Rename this please", |
| 54 | ].join("\n"), |
| 55 | ); |
| 56 | }); |
| 57 | }); |