diff --git a/tests/api-contact.test.ts b/tests/api-contact.test.ts index 4cd06fa..3eeeff3 100644 --- a/tests/api-contact.test.ts +++ b/tests/api-contact.test.ts @@ -6,6 +6,16 @@ const { mockCreate, mockSendEmail } = vi.hoisted(() => ({ mockSendEmail: vi.fn(), })); +// Mock Nodemailer +const mockSendMail = vi.fn(); +vi.mock("nodemailer", () => ({ + default: { + createTransport: vi.fn().mockReturnValue({ + sendMail: mockSendMail, + }), + }, +})); + vi.mock("payload", () => ({ getPayload: vi.fn().mockResolvedValue({ create: mockCreate, @@ -101,7 +111,7 @@ describe("Contact API Integration", () => { // But it actually does NOTHING internally expect(mockCreate).not.toHaveBeenCalled(); - expect(mockSendEmail).not.toHaveBeenCalled(); + expect(mockSendMail).not.toHaveBeenCalled(); }); it("should successfully save to Payload and send emails", async () => { @@ -140,10 +150,10 @@ describe("Contact API Integration", () => { }); // 2. Verify Email Sending - // Note: sendEmail is called twice (Notification + User Confirmation) - expect(mockSendEmail).toHaveBeenCalledTimes(2); + // Note: sendMail is called twice (Notification + User Confirmation) + expect(mockSendMail).toHaveBeenCalledTimes(2); - expect(mockSendEmail).toHaveBeenNthCalledWith( + expect(mockSendMail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ subject: "Kontaktanfrage von Jane Doe", @@ -151,7 +161,7 @@ describe("Contact API Integration", () => { }), ); - expect(mockSendEmail).toHaveBeenNthCalledWith( + expect(mockSendMail).toHaveBeenNthCalledWith( 2, expect.objectContaining({ to: "jane@example.com",