37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { expect, test, vi } from "vitest";
|
|
|
|
import { createMailer } from "./mailer";
|
|
|
|
test("sends a verification link through the configured SMTP boundary", async () => {
|
|
const transport = { sendMail: vi.fn().mockResolvedValue({ messageId: "message-1" }) };
|
|
const mailer = createMailer({ from: "portal@example.com", transport });
|
|
|
|
await mailer.sendVerification({
|
|
to: "editorial@example.com",
|
|
verificationUrl: "https://portal.example.com/api/auth/verify-email?token=secret-token",
|
|
});
|
|
|
|
expect(transport.sendMail).toHaveBeenCalledWith({
|
|
from: "portal@example.com",
|
|
to: "editorial@example.com",
|
|
subject: "Bitte bestätigen Sie Ihre E-Mail-Adresse",
|
|
text: expect.stringContaining(
|
|
"https://portal.example.com/api/auth/verify-email?token=secret-token",
|
|
),
|
|
});
|
|
});
|
|
|
|
test("sends an approval notice without leaking SMTP credentials", async () => {
|
|
const transport = { sendMail: vi.fn().mockResolvedValue({ messageId: "message-2" }) };
|
|
const mailer = createMailer({ from: "portal@example.com", transport });
|
|
|
|
await mailer.sendApprovalNotice({ to: "editorial@example.com", editorialName: "Neue Redaktion" });
|
|
|
|
expect(transport.sendMail).toHaveBeenCalledWith({
|
|
from: "portal@example.com",
|
|
to: "editorial@example.com",
|
|
subject: "Ihr Zugang zum Redaktionsportal ist freigegeben",
|
|
text: expect.stringContaining("Neue Redaktion"),
|
|
});
|
|
});
|