Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

definition.test.ts

64 lines2.2 KB

1import { recognizeRemoteWith } from "@t3tools/source-control-core/shared/definition";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { definition } from "./definition.ts";
5​
6const parse = (url: string) => definition.parseChangeRequestUrl(new URL(url));
7​
8describe("GitCafe change request URLs", () => {
9 it("reads its canonical /pull/ path and the older /pulls/ path on its own hosts", () => {
10 for (const path of ["pull", "pulls"]) {
11 expect(parse(`https://git.cafe/PingDotGG/T3Code/${path}/23897`), path).toEqual({
12 host: "git.cafe",
13 repository: "pingdotgg/t3code",
14 number: 23897,
15 repositoryUrl: "https://git.cafe/PingDotGG/T3Code",
16 });
17 }
18 expect(parse("https://staging.git.cafe/team/repo/pull/7/files")).toMatchObject({
19 host: "staging.git.cafe",
20 repository: "team/repo",
21 number: 7,
22 });
23 });
24​
25 it("leaves other hosts and routes alone", () => {
26 for (const url of [
27 "https://github.com/team/repo/pull/7",
28 "https://forge.example/team/repo/pulls/7",
29 "https://git.cafe/pingdotgg/t3code/issues/23897",
30 "https://git.cafe/pingdotgg/t3code/pull/abc",
31 "https://git.cafe/pingdotgg/t3code",
32 ]) {
33 expect(parse(url), url).toBeNull();
34 }
35 });
36​
37 it("builds pull request URLs below the repository", () => {
38 expect(
39 definition.changeRequestUrl({ host: "git.cafe", repository: "team/repo", number: 8 }),
40 ).toBe("https://git.cafe/team/repo/pulls/8");
41 expect(
42 definition.changeRequestUrl({
43 host: "git.cafe",
44 repository: "team/repo",
45 number: 8,
46 webUrl: "https://git.cafe/Team/Repo/",
47 }),
48 ).toBe("https://git.cafe/Team/Repo/pulls/8");
49 });
50});
51​
52describe("GitCafe remotes", () => {
53 it("recognises its own hosts only, without a port", () => {
54 expect(recognizeRemoteWith(definition, "https://git.cafe:8443/a/b")).toEqual({
55 kind: "gitcafe",
56 name: "GitCafe",
57 baseUrl: "https://git.cafe",
58 });
59 expect(recognizeRemoteWith(definition, "git@staging.git.cafe:team/repo.git")?.kind).toBe(
60 "gitcafe",
61 );
62 expect(recognizeRemoteWith(definition, "https://cafe.example/a/b")).toBeNull();
63 });
64});