~james/core

core/web/src/lib/cloneUrl.test.ts -rw-r--r-- 1.5 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, expect, it } from "vitest";
import { sshRemote } from "#lib/cloneUrl.ts";

describe("sshRemote", () => {
	it("renders viewer's atproto handle in the SSH user section so that knot can get their SSH key inline", () => {
		expect(sshRemote("knot.oyster.cafe", "nel.pet", "nel.pet/proj")).toBe(
			"nel.pet@knot.oyster.cafe:nel.pet/proj"
		);
	});

	it("falls back to git when viewing while signed out", () => {
		expect(sshRemote("knot.oyster.cafe", undefined, "did:plc:repo")).toBe(
			"git@knot.oyster.cafe:did:plc:repo"
		);
	});

	it("falls back to git when the viewer's handle is un-hydrated, so that we avoid trying a DID in user section for now", () => {
		expect(sshRemote("knot.oyster.cafe", "did:plc:nel", "did:plc:repo")).toBe(
			"git@knot.oyster.cafe:did:plc:repo"
		);
	});

	it.each([
		["knot1.tangled.sh", "nel.pet@tangled.org:did:plc:repo"],
		["https://knot1.tangled.sh:8443", "nel.pet@tangled.org:did:plc:repo"],
		["did:web:knot1.tangled.sh", "nel.pet@tangled.org:did:plc:repo"],
		["KNOT1.TANGLED.SH", "nel.pet@tangled.org:did:plc:repo"],
		["did:web:custom-knot.test", "nel.pet@custom-knot.test:did:plc:repo"],
		["https://knot.oyster.cafe:8443", "nel.pet@knot.oyster.cafe:did:plc:repo"],
		["HTTPS://knot.oyster.cafe", "nel.pet@knot.oyster.cafe:did:plc:repo"],
		["not_a_host", "nel.pet@not_a_host:did:plc:repo"]
	])("builds the ssh host for %s as %s", (knot, expected) => {
		expect(sshRemote(knot, "nel.pet", "did:plc:repo")).toBe(expected);
	});
});