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

sourceControl.test.ts

60 lines1.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 detectSourceControlProviderFromRemoteUrl,
5 getChangeRequestTerminologyForKind,
6 resolveChangeRequestPresentation,
7} from "./sourceControl.ts";
8​
9describe("source control presentation", () => {
10 it("uses pull request terminology for GitHub", () => {
11 expect(getChangeRequestTerminologyForKind("github")).toEqual({
12 shortLabel: "PR",
13 singular: "pull request",
14 });
15 });
16​
17 it("falls back to generic change request copy for unknown providers", () => {
18 expect(
19 resolveChangeRequestPresentation({ kind: "unknown", name: "forge", baseUrl: "" }),
20 ).toEqual(
21 expect.objectContaining({
22 shortName: "change request",
23 longName: "change request",
24 }),
25 );
26 });
27});
28​
29describe("detectSourceControlProviderFromRemoteUrl", () => {
30 it("detects GitHub remotes and treats every other host as unknown", () => {
31 expect(detectSourceControlProviderFromRemoteUrl("git@github.com:owner/repo.git")?.kind).toBe(
32 "github",
33 );
34 expect(
35 detectSourceControlProviderFromRemoteUrl("https://gitlab.com/group/repo.git")?.kind,
36 ).toBe("unknown");
37 expect(
38 detectSourceControlProviderFromRemoteUrl("git@bitbucket.org:workspace/repo.git")?.kind,
39 ).toBe("unknown");
40 });
41​
42 it("preserves ports while classifying by hostname", () => {
43 expect(
44 detectSourceControlProviderFromRemoteUrl("https://github.com:8443/owner/repo.git"),
45 ).toEqual({
46 kind: "github",
47 name: "GitHub",
48 baseUrl: "https://github.com:8443",
49 });
50 expect(
51 detectSourceControlProviderFromRemoteUrl(
52 "https://self-hosted.example.test:8443/group/repo.git",
53 ),
54 ).toEqual({
55 kind: "unknown",
56 name: "self-hosted.example.test:8443",
57 baseUrl: "https://self-hosted.example.test:8443",
58 });
59 });
60});