~james/core

core/web/src/lib/server/config.test.ts -rw-r--r-- 907 bytes
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
import { describe, expect, it } from "vitest";
import { resolveConfig } from "#lib/server/config.ts";

const fosterKnotUrl = (foster?: string) => resolveConfig({ FOSTER_KNOT_URL: foster }).fosterKnotUrl;

describe("resolveConfig fosterKnotUrl", () => {
	it("parses a bare-origin url into the knot origin, ignoring a trailing slash", () => {
		expect(fosterKnotUrl("https://foster.test")).toBe("foster.test");
		expect(fosterKnotUrl("https://foster.test/")).toBe("foster.test");
		expect(fosterKnotUrl("http://127.0.0.1:5555")).toBe("127.0.0.1:5555");
	});

	it("is empty when unset or blank", () => {
		expect(fosterKnotUrl()).toBe("");
		expect(fosterKnotUrl("  ")).toBe("");
	});

	it.each(["https://foster.test/foster", "foster.test"])(
		"rejects %s at config load instead of quietly routing reads to the origin",
		(url) => {
			expect(() => fosterKnotUrl(url)).toThrow(/FOSTER_KNOT_URL/);
		}
	);
});