| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { canLinkChangeRequest } from "./usePullRequestLinking"; |
| 4 | import { parseChangeRequestUrl } from "~/lib/openPullRequestLink"; |
| 5 | |
| 6 | describe("canLinkChangeRequest (#9435 / #9440)", () => { |
| 7 | // A non-Git parent workspace (a folder of several child repositories that is not itself a |
| 8 | // checkout) registers as a project with no `repositoryIdentity` at all. |
| 9 | const nonGitProject = { id: "scratch-project" } as never; |
| 10 | const link = parseChangeRequestUrl("https://github.com/pingdotgg/t3code/pull/15111")!; |
| 11 | |
| 12 | it("links a pasted pull request URL when the server tracks links on the thread, even with no matching project", () => { |
| 13 | // `multiple` mode (the `threadPullRequests` capability) stores a link's host, repository |
| 14 | // and number on the thread directly, so no project needs to match for the link itself. |
| 15 | expect(canLinkChangeRequest("multiple", [nonGitProject], link)).toBe(true); |
| 16 | expect(canLinkChangeRequest("multiple", [], link)).toBe(true); |
| 17 | }); |
| 18 | |
| 19 | it("still requires a matching project in single-link mode, where the link needs a projectId", () => { |
| 20 | expect(canLinkChangeRequest("single", [nonGitProject], link)).toBe(false); |
| 21 | expect(canLinkChangeRequest("single", [], link)).toBe(false); |
| 22 | }); |
| 23 | |
| 24 | it("never links when the environment does not support pull request linking", () => { |
| 25 | expect(canLinkChangeRequest("unsupported", [nonGitProject], link)).toBe(false); |
| 26 | }); |
| 27 | }); |