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>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import { deliverInquiry } from "./deliver.ts";
|
|
import type { Inquiry } from "./schema.ts";
|
|
|
|
const inquiry: Inquiry = {
|
|
name: "Anna Müller",
|
|
email: "anna@example.com",
|
|
message: "Wir brauchen eine belastbare Abbildung unseres Satzprozesses.",
|
|
locale: "de",
|
|
topic: "process",
|
|
};
|
|
|
|
describe("deliverInquiry", () => {
|
|
it("saves and succeeds when mail is sent", async () => {
|
|
const saved: Inquiry[] = [];
|
|
const result = await deliverInquiry(inquiry, {
|
|
save: (item) => {
|
|
saved.push(item);
|
|
return "id-1";
|
|
},
|
|
send: async () => true,
|
|
});
|
|
|
|
assert.deepEqual(result, { ok: true });
|
|
assert.equal(saved.length, 1);
|
|
});
|
|
|
|
it("does not report success when mail fails after save", async () => {
|
|
let saved = false;
|
|
const result = await deliverInquiry(inquiry, {
|
|
save: () => {
|
|
saved = true;
|
|
return "id-2";
|
|
},
|
|
send: async () => false,
|
|
});
|
|
|
|
assert.equal(saved, true);
|
|
assert.deepEqual(result, { ok: false, code: "delivery" });
|
|
});
|
|
|
|
it("returns error when save throws", async () => {
|
|
const result = await deliverInquiry(inquiry, {
|
|
save: () => {
|
|
throw new Error("disk");
|
|
},
|
|
send: async () => true,
|
|
});
|
|
|
|
assert.deepEqual(result, { ok: false, code: "error" });
|
|
});
|
|
});
|