From 8427d348dd15278ffaf43f91578e1bf4c3a84f83 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 15 Apr 2026 00:05:45 +0200 Subject: [PATCH] fix: ensure smtp metadata logger doesn't crash in tests --- app/api/contact/route.ts | 4 ++-- tests/api-contact.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/api/contact/route.ts b/app/api/contact/route.ts index c4455ab..09bbf10 100644 --- a/app/api/contact/route.ts +++ b/app/api/contact/route.ts @@ -123,7 +123,7 @@ export async function POST(req: Request) { subject: `Kontaktanfrage von ${name}`, html: notificationHtml, }); - logger.info("Notification email sent successfully", { messageId: info.messageId }); + logger.info("Notification email sent successfully", { messageId: info?.messageId }); } catch (notifyError) { logger.error("Failed to send notification email", { error: notifyError }); throw notifyError; // Re-throw to be caught by the outer SMTP catch @@ -145,7 +145,7 @@ export async function POST(req: Request) { subject: `Ihre Kontaktanfrage bei ${clientName}`, html: confirmationHtml, }); - logger.info("Confirmation email sent successfully", { messageId: info.messageId }); + logger.info("Confirmation email sent successfully", { messageId: info?.messageId }); } catch (confirmError) { logger.warn( "Failed to send confirmation email, but notification was sent", diff --git a/tests/api-contact.test.ts b/tests/api-contact.test.ts index 6cd1a94..16d3d5a 100644 --- a/tests/api-contact.test.ts +++ b/tests/api-contact.test.ts @@ -8,7 +8,7 @@ const { mockCreate, mockSendEmail } = vi.hoisted(() => ({ // Mock Nodemailer const { mockSendMail } = vi.hoisted(() => ({ - mockSendMail: vi.fn(), + mockSendMail: vi.fn().mockResolvedValue({ messageId: "mock-message-id" }), })); vi.mock("nodemailer", () => ({