|
1 | 1 | import { recognizeRemoteWith } from "@t3tools/source-control-core/shared/definition"; |
2 | 2 | import { describe, expect, it } from "vite-plus/test"; |
3 | 3 |
|
4 | | -import { definition } from "./definition.ts"; |
| 4 | +import { canonicalizePullRequestUrl, definition, parsePullRequestUrl } from "./definition.ts"; |
5 | 5 |
|
6 | 6 | const parse = (url: string) => definition.parseChangeRequestUrl(new URL(url)); |
7 | 7 |
|
8 | 8 | describe("GitCafe change request URLs", () => { |
| 9 | + it.each(["git.cafe", "staging.git.cafe"])("normalizes links for storage on %s", (host) => { |
| 10 | + for (const repository of ["web", "pull", "pulls"]) { |
| 11 | + for (const route of ["pull", "pulls"]) { |
| 12 | + const url = `https://${host}/Acme/${repository}/${route}/42/files?w=1#diff`; |
| 13 | + expect(parsePullRequestUrl(url)).toMatchObject({ |
| 14 | + host, |
| 15 | + repository: `acme/${repository}`, |
| 16 | + number: 42, |
| 17 | + }); |
| 18 | + expect(definition.isChangeRequestReference(url)).toBe(true); |
| 19 | + expect(canonicalizePullRequestUrl(url)).toBe(`https://${host}/acme/${repository}/pulls/42`); |
| 20 | + } |
| 21 | + } |
| 22 | + }); |
| 23 | + |
| 24 | + it("preserves other URLs and rejects invalid GitCafe references", () => { |
| 25 | + for (const url of [ |
| 26 | + "https://github.com/team/repo/pull/7", |
| 27 | + "https://forge.example/team/repo/pulls/7", |
| 28 | + "https://not.git.cafe/team/repo/pull/7", |
| 29 | + "https://git.cafe.evil.test/team/repo/pull/7", |
| 30 | + "https://git.cafe/tfs/collection/project/_git/repo/pullrequest/7", |
| 31 | + "https://git.cafe/team/repo/pull/0", |
| 32 | + "https://git.cafe/team/repo/pulls/9007199254740992", |
| 33 | + "https://staging.git.cafe/team/repo/pull/7suffix", |
| 34 | + "ftp://git.cafe/team/repo/pull/7", |
| 35 | + "not a url", |
| 36 | + ]) { |
| 37 | + expect(parsePullRequestUrl(url), url).toBeNull(); |
| 38 | + expect(definition.isChangeRequestReference(url), url).toBe(false); |
| 39 | + expect(canonicalizePullRequestUrl(url), url).toBe(url); |
| 40 | + } |
| 41 | + }); |
| 42 | + |
9 | 43 | it("reads its canonical /pull/ path and the older /pulls/ path on its own hosts", () => { |
10 | 44 | for (const path of ["pull", "pulls"]) { |
11 | 45 | expect(parse(`https://git.cafe/PingDotGG/T3Code/${path}/23897`), path).toEqual({ |
|
0 commit comments