Files
w-make-portfolio/src/lib/contact/schema.test.ts
T
Jan WagnerandCursor 0482b780f4 feat(site): tighten proof, contact, and inquiry delivery
Lead with Batch on the home page, drop the product changelog, add a
domain note, and stop reporting success when SMTP fails.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-16 11:12:40 +02:00

62 lines
2.0 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { validateInquiry } from "./schema.ts";
import { offerIds } from "../../content/offer-ids.ts";
describe("validateInquiry", () => {
const valid = {
name: "Anna Müller",
email: "anna@example.com",
company: "Glaswerk",
message: "Wir brauchen eine belastbare Abbildung unseres Satzprozesses.",
locale: "de",
website: "",
};
it("accepts a complete inquiry", () => {
const result = validateInquiry(valid);
assert.equal(result.ok, true);
if (result.ok) {
assert.equal(result.data.email, "anna@example.com");
assert.equal(result.data.company, "Glaswerk");
}
});
it("rejects a filled honeypot", () => {
const result = validateInquiry({ ...valid, website: "https://spam.test" });
assert.equal(result.ok, false);
if (!result.ok) assert.equal(result.code, "spam");
});
it("rejects short messages and invalid email", () => {
assert.equal(validateInquiry({ ...valid, message: "Hallo" }).ok, false);
assert.equal(validateInquiry({ ...valid, email: "not-an-email" }).ok, false);
});
it("allows an empty company field", () => {
const result = validateInquiry({ ...valid, company: " " });
assert.equal(result.ok, true);
if (result.ok) assert.equal(result.data.company, undefined);
});
it("accepts every published offer id", () => {
for (const topic of offerIds) {
const result = validateInquiry({ ...valid, topic });
assert.equal(result.ok, true);
if (result.ok) assert.equal(result.data.topic, topic);
}
});
it("rejects an unknown topic", () => {
const result = validateInquiry({ ...valid, topic: "casino" });
assert.equal(result.ok, false);
if (!result.ok) assert.equal(result.field, "topic");
});
it("treats a blank topic as omitted", () => {
const result = validateInquiry({ ...valid, topic: " " });
assert.equal(result.ok, true);
if (result.ok) assert.equal(result.data.topic, undefined);
});
});