You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
3.1 KiB
69 lines
3.1 KiB
import { describe, expect, test } from "bun:test";
|
|
import { getConfigDefinition, KnownConfigKey, validateConfigValue } from "./registry";
|
|
import { normalizeGlobalConfigValue } from "./normalization";
|
|
|
|
describe("comment email config validation", () => {
|
|
test("accepts an empty commentMailFromEmail", () => {
|
|
expect(validateConfigValue("commentMailFromEmail", "")).toBe(true);
|
|
});
|
|
|
|
test("accepts a valid commentMailFromEmail", () => {
|
|
expect(validateConfigValue("commentMailFromEmail", "noreply@example.com")).toBe(true);
|
|
});
|
|
|
|
test("rejects an invalid commentMailFromEmail", () => {
|
|
expect(validateConfigValue("commentMailFromEmail", "invalid-email")).toBe(false);
|
|
});
|
|
|
|
test("validates commentNotifyEnabled as boolean", () => {
|
|
expect(validateConfigValue("commentNotifyEnabled", true)).toBe(true);
|
|
expect(validateConfigValue("commentNotifyEnabled", false)).toBe(true);
|
|
expect(validateConfigValue("commentNotifyEnabled", "true")).toBe(false);
|
|
});
|
|
|
|
test("enforces commentSmtpPort boundaries", () => {
|
|
expect(validateConfigValue("commentSmtpPort", 1)).toBe(true);
|
|
expect(validateConfigValue("commentSmtpPort", 65535)).toBe(true);
|
|
expect(validateConfigValue("commentSmtpPort", 0)).toBe(false);
|
|
expect(validateConfigValue("commentSmtpPort", 65536)).toBe(false);
|
|
expect(validateConfigValue("commentSmtpPort", 465)).toBe(true);
|
|
});
|
|
|
|
test("keeps metadata consistent for new global comment config keys", () => {
|
|
const expected = [
|
|
["commentEmailNotifyEnabled", "global", "boolean", false, false],
|
|
["commentMailFromEmail", "global", "string", "", false],
|
|
["commentSmtpHost", "global", "string", "", false],
|
|
["commentSmtpPort", "global", "number", 465, false],
|
|
["commentSmtpSecure", "global", "boolean", true, false],
|
|
["commentSmtpUser", "global", "string", "", false],
|
|
["commentSmtpPass", "global", "string", "", false],
|
|
] as const satisfies readonly [KnownConfigKey, "global", "string" | "number" | "boolean", string | number | boolean, boolean][];
|
|
|
|
for (const [key, scope, valueType, defaultValue, userOverridable] of expected) {
|
|
expect(getConfigDefinition(key)).toMatchObject({
|
|
scope,
|
|
valueType,
|
|
defaultValue,
|
|
userOverridable,
|
|
});
|
|
}
|
|
});
|
|
|
|
test("keeps metadata consistent for commentNotifyEnabled", () => {
|
|
expect(getConfigDefinition("commentNotifyEnabled")).toMatchObject({
|
|
scope: "both",
|
|
valueType: "boolean",
|
|
defaultValue: true,
|
|
userOverridable: true,
|
|
});
|
|
});
|
|
|
|
test("normalizes comment email and smtp strings by trimming", () => {
|
|
expect(normalizeGlobalConfigValue("commentMailFromEmail", " noreply@example.com ")).toBe("noreply@example.com");
|
|
expect(normalizeGlobalConfigValue("commentMailFromEmail", " ")).toBe("");
|
|
expect(normalizeGlobalConfigValue("commentSmtpHost", " smtp.example.com ")).toBe("smtp.example.com");
|
|
expect(normalizeGlobalConfigValue("commentSmtpUser", " username ")).toBe("username");
|
|
expect(normalizeGlobalConfigValue("commentSmtpPass", " password ")).toBe("password");
|
|
});
|
|
});
|
|
|