chore(config): centralize feature settings

This commit is contained in:
2026-08-09 21:20:19 +07:00 Unverified
parent 26c0b5af18
commit 950d3d4afe
22 changed files with 238 additions and 70 deletions
+31
View File
@@ -0,0 +1,31 @@
import { describe, expect, test } from "bun:test";
import {
optionalEnvironmentValue,
readFeatureEnvironment,
requiredEnvironmentUrl,
requiredEnvironmentValue,
} from "@/lib/config/environment";
describe("feature environment configuration", () => {
test("returns trimmed required and optional values", () => {
const environment = { REQUIRED: " value ", OPTIONAL: " optional " };
expect(requiredEnvironmentValue("REQUIRED", environment)).toBe("value");
expect(optionalEnvironmentValue("OPTIONAL", environment)).toBe("optional");
expect(optionalEnvironmentValue("MISSING", environment)).toBeNull();
});
test("reports the feature and missing variable", () => {
expect(() =>
readFeatureEnvironment("Discord", ["TOKEN", "GUILD"] as const, {
TOKEN: "token",
}),
).toThrow("Discord is not configured: Missing required environment variable: GUILD");
});
test("accepts absolute URLs and removes a trailing slash", () => {
expect(requiredEnvironmentUrl("BASE_URL", { BASE_URL: "https://example.com/" }))
.toBe("https://example.com");
expect(() => requiredEnvironmentUrl("BASE_URL", { BASE_URL: "/relative" }))
.toThrow("must be an absolute URL");
});
});