import { expect, test } from "bun:test"; import { PlatformAuth } from "./auth"; import { readConfig } from "./config"; import { TOKEN } from "./testing/fixtures"; const credentials = JSON.stringify([{ platform: "maincasts.com", token: TOKEN }]); test("configuration authenticates platforms, not individual publisher repositories", () => { const config = readConfig({ PLATFORM_CREDENTIALS: credentials }); expect(config.credentials).toEqual([{ platform: "maincasts.com", token: TOKEN }]); expect(config.databasePath).toBe("./data/resolver.sqlite"); expect(config.freshnessMs).toBe(300_000); expect(config.maxAgeMs).toBe(21_600_000); expect(config.analyticsSecret).toBeUndefined(); }); test("media-host configuration is no longer read or enforced", () => { const config = readConfig({ PLATFORM_CREDENTIALS: credentials, MEDIA_HOSTS: "old-cdn.example.com" }); expect("allowedHosts" in config).toBe(false); }); test("old publisher-scoped configuration fails with migration guidance", () => { expect(() => readConfig({ PUBLISHER_CREDENTIALS: "[]" })).toThrow("Replace PUBLISHER_CREDENTIALS with PLATFORM_CREDENTIALS"); }); test("unsafe or incomplete deployment configuration is rejected", () => { expect(() => readConfig({ PUBLIC_BASE_URL: "http://pod.place" })).toThrow(); expect(() => readConfig({ MAPPING_FRESHNESS_SECONDS: "999999" })).toThrow(); expect(() => readConfig({ ANALYTICS_SECRET: "short" })).toThrow(); expect(() => readConfig({ PLATFORM_CREDENTIALS: "{}" })).toThrow(); expect(() => new PlatformAuth([])).toThrow(); expect(() => new PlatformAuth([{ platform: "", token: TOKEN }])).toThrow(); });