Add SMTP admin settings and contact form delivery

This commit is contained in:
MOH
2026-03-08 06:27:09 +01:00
parent 993a4673d8
commit 5ca4819bcb
28 changed files with 2087 additions and 55 deletions
+65
View File
@@ -0,0 +1,65 @@
import { describe, expect, it } from "vitest";
import {
buildDefaultContactProtectionSettings,
parseContactProtectionValue,
toContactProtectionFormValues,
} from "../lib/contact-protection";
describe("contact protection helpers", () => {
it("builds safe defaults", () => {
expect(buildDefaultContactProtectionSettings()).toEqual({
turnstile: {
enabled: false,
siteKey: "",
secretKey: "",
},
rateLimit: {
enabled: true,
maxRequests: 5,
windowMinutes: 10,
},
});
});
it("parses stored settings and trims keys", () => {
const settings = parseContactProtectionValue(
JSON.stringify({
turnstile: {
enabled: true,
siteKey: " 0x4AAAAA ",
secretKey: "secret",
},
rateLimit: {
enabled: true,
maxRequests: "8",
windowMinutes: "15",
},
}),
);
expect(settings.turnstile.enabled).toBe(true);
expect(settings.turnstile.siteKey).toBe("0x4AAAAA");
expect(settings.turnstile.secretKey).toBe("secret");
expect(settings.rateLimit.maxRequests).toBe(8);
expect(settings.rateLimit.windowMinutes).toBe(15);
});
it("hides the stored secret in form values", () => {
const values = toContactProtectionFormValues({
turnstile: {
enabled: true,
siteKey: "site-key",
secretKey: "secret-key",
},
rateLimit: {
enabled: true,
maxRequests: 5,
windowMinutes: 10,
},
});
expect(values.turnstile.secretKey).toBe("");
expect(values.turnstile.hasSecretKey).toBe(true);
});
});