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

addProjectToMachine.test.ts

36 lines1.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { cloneUrlForProtocol, cloneUrlProtocol } from "./addProjectToMachine";
4​
5describe("cloneUrlForProtocol", () => {
6 it("switches between scp-style SSH and HTTPS", () => {
7 expect(cloneUrlForProtocol("git@github.com:pingdotgg/t3code.git", "https")).toBe(
8 "https://github.com/pingdotgg/t3code.git",
9 );
10 expect(cloneUrlForProtocol("https://github.com/pingdotgg/t3code.git", "ssh")).toBe(
11 "git@github.com:pingdotgg/t3code.git",
12 );
13 expect(cloneUrlForProtocol("ssh://git@gitlab.com/group/sub/repo.git", "https")).toBe(
14 "https://gitlab.com/group/sub/repo.git",
15 );
16 });
17​
18 it("keeps the URL as is for its own protocol and drops HTTPS credentials on switch", () => {
19 expect(cloneUrlForProtocol("https://token@github.com/a/b.git", "https")).toBe(
20 "https://token@github.com/a/b.git",
21 );
22 expect(cloneUrlForProtocol("https://token@github.com/a/b.git", "ssh")).toBe(
23 "git@github.com:a/b.git",
24 );
25 });
26​
27 it("refuses rewrites that would guess wrong", () => {
28 expect(cloneUrlForProtocol("ssh://git@host.example:2222/a/b.git", "https")).toBeNull();
29 expect(cloneUrlForProtocol("https://host.example:8443/a/b.git", "ssh")).toBeNull();
30 expect(cloneUrlForProtocol("https://host.example:8443/a/b.git", "https")).toBe(
31 "https://host.example:8443/a/b.git",
32 );
33 expect(cloneUrlForProtocol("/srv/git/repo.git", "https")).toBeNull();
34 expect(cloneUrlProtocol("file:///srv/git/repo.git")).toBeNull();
35 });
36});