g1t/apps/web/app/lib/addresses.test.ts

39 lines1,476 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { HOSTED_ADDRESSES, addressesFor, addressesFrom, cloneUrl } from "./addresses.ts";
5import { MCP_URL } from "./agent-setup.ts";
6import { OG, SITE } from "./meta.ts";
7
8test("with no settings, the addresses are g1t.sh's", () => {
9 assert.deepEqual(addressesFor({}), HOSTED_ADDRESSES);
10 assert.deepEqual(addressesFor({ SITE_URL: "", API_URL: "", MCP_URL: "" }), HOSTED_ADDRESSES);
11});
12
13test("settings replace the addresses, without trailing slashes", () => {
14 assert.deepEqual(
15 addressesFor({
16 SITE_URL: "http://localhost:8787/",
17 API_URL: "http://localhost:8788",
18 MCP_URL: "http://localhost:8790/mcp/",
19 OG_URL: "",
20 }),
21 { site: "http://localhost:8787", api: "http://localhost:8788", mcp: "http://localhost:8790/mcp", og: null },
22 );
23});
24
25test("pages without root data use g1t.sh's addresses", () => {
26 assert.deepEqual(addressesFrom(undefined), HOSTED_ADDRESSES);
27 const own = { site: "http://localhost:8787", api: "a", mcp: "m", og: null };
28 assert.deepEqual(addressesFrom({ addresses: own }), own);
29});
30
31test("the defaults kept in meta and agent setup are g1t.sh's", () => {
32 assert.equal(SITE, HOSTED_ADDRESSES.site);
33 assert.equal(OG, HOSTED_ADDRESSES.og);
34 assert.equal(MCP_URL, HOSTED_ADDRESSES.mcp);
35});
36
37test("a clone address is under the site", () => {
38 assert.equal(cloneUrl(HOSTED_ADDRESSES, "acme/web"), "https://g1t.sh/acme/web.git");
39});