chore(config): centralize feature settings
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user