|
| 1 | +import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
1 | 2 | import { describe, expect, it } from "vite-plus/test"; |
2 | 3 | import { nativePullRequestDestination } from "../../lib/pullRequestNavigation"; |
| 4 | + |
3 | 5 | const context = { environmentId: "remote", projectId: "project" }; |
| 6 | +const project = (id: string, canonicalKey: string, provider: string, remoteUrl: string) => ({ |
| 7 | + id: ProjectId.make(id), |
| 8 | + environmentId: EnvironmentId.make("remote"), |
| 9 | + repositoryIdentity: { |
| 10 | + canonicalKey, |
| 11 | + locator: { source: "git-remote" as const, remoteName: "origin", remoteUrl }, |
| 12 | + displayName: canonicalKey.split("/").slice(1).join("/"), |
| 13 | + provider, |
| 14 | + }, |
| 15 | +}); |
| 16 | +const projects = [ |
| 17 | + project("project", "github.com/org/repo", "github", "[email protected]:org/repo.git"), |
| 18 | + project("gitlab", "git.example/group/sub/repo", "gitlab", "[email protected]:group/sub/repo.git"), |
| 19 | + project("forgejo", "forgejo.test/org/repo", "forgejo", "http://forgejo.test:3000/org/repo.git"), |
| 20 | +]; |
| 21 | + |
4 | 22 | describe("native PR entry points", () => { |
5 | 23 | it("keeps a thread link in its own environment and handles renamed host path shapes", () => { |
6 | 24 | expect( |
7 | | - nativePullRequestDestination("https://github.com/org/repo/pull/12/files#diff", context), |
| 25 | + nativePullRequestDestination( |
| 26 | + "https://github.com/org/repo/pull/12/files#diff", |
| 27 | + context, |
| 28 | + projects, |
| 29 | + ), |
8 | 30 | ).toEqual({ ...context, host: "github.com", repository: "org/repo", number: 12 }); |
9 | 31 | expect( |
10 | | - nativePullRequestDestination("https://git.example/group/sub/repo/-/merge_requests/9", context) |
11 | | - ?.repository, |
12 | | - ).toBe("group/sub/repo"); |
| 32 | + nativePullRequestDestination( |
| 33 | + "https://git.example/group/sub/repo/-/merge_requests/9", |
| 34 | + context, |
| 35 | + projects, |
| 36 | + ), |
| 37 | + ).toMatchObject({ projectId: "gitlab", repository: "group/sub/repo" }); |
13 | 38 | expect( |
14 | | - nativePullRequestDestination("http://forgejo.test:3000/org/repo/pulls/3", context)?.host, |
| 39 | + nativePullRequestDestination("http://forgejo.test:3000/org/repo/pulls/3", context, projects) |
| 40 | + ?.host, |
15 | 41 | ).toBe("forgejo.test:3000"); |
16 | 42 | }); |
| 43 | + |
| 44 | + it("leaves pull requests from repositories without a project to the external opener", () => { |
| 45 | + expect( |
| 46 | + nativePullRequestDestination("https://github.com/someone/else/pull/12", context, projects), |
| 47 | + ).toBeNull(); |
| 48 | + }); |
| 49 | + |
17 | 50 | it("leaves issues, unknown sites, and unscoped links to the external opener", () => { |
18 | 51 | expect( |
19 | | - nativePullRequestDestination("https://github.com/org/repo/issues/12", context), |
| 52 | + nativePullRequestDestination("https://github.com/org/repo/issues/12", context, projects), |
| 53 | + ).toBeNull(); |
| 54 | + expect( |
| 55 | + nativePullRequestDestination("https://example.com/org/repo/pull/12", context, projects), |
20 | 56 | ).toBeNull(); |
21 | 57 | expect( |
22 | | - nativePullRequestDestination("https://example.com/org/repo/pull/12", context), |
| 58 | + nativePullRequestDestination("https://github.com/org/repo/pull/12", null, projects), |
23 | 59 | ).toBeNull(); |
24 | | - expect(nativePullRequestDestination("https://github.com/org/repo/pull/12", null)).toBeNull(); |
25 | 60 | }); |
26 | 61 | }); |
0 commit comments