Files
STCourses/packages/core/test/config.test.ts
T
2026-10-30 03:04:46 +01:00

28 lines
1.0 KiB
TypeScript

import { expect, test, spyOn } from "bun:test";
import { loadConfig } from "../src";
test("defaults", () => {
const warn = spyOn(console, "warn").mockImplementation(() => {});
const c = loadConfig({});
expect(c.port).toBe(3000);
expect(c.databaseUrl).toBe("sqlite://./data/stcourses.db");
expect(c.dataDir).toBe("./data");
expect(c.courseDirs).toEqual(["./overlays", "./courses"]);
expect(c.publicUrl).toBe("http://localhost:3000");
expect(warn).toHaveBeenCalledTimes(1);
warn.mockRestore();
});
test("colon splitting and overrides", () => {
const c = loadConfig({ STC_PORT: "8080", STC_COURSE_DIRS: "/a b:/c", STC_SECRET: "s", STC_PUBLIC_URL: "https://x.test" });
expect(c.port).toBe(8080);
expect(c.courseDirs).toEqual(["/a b", "/c"]);
expect(c.secret).toBe("s");
expect(c.publicUrl).toBe("https://x.test");
});
test("production without a secret throws", () => {
expect(() => loadConfig({ NODE_ENV: "production" })).toThrow(/STC_SECRET/);
expect(loadConfig({ NODE_ENV: "production", STC_SECRET: "x" }).secret).toBe("x");
});