test: update contact api test to mock nodemailer
Some checks failed
🚀 Build & Deploy / 🔍 Prepare (push) Failing after 6s
🚀 Build & Deploy / 🧪 QA (push) Has been skipped
🚀 Build & Deploy / 🏗️ Build (push) Has been skipped
🚀 Build & Deploy / 🚀 Deploy (push) Has been skipped
🚀 Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
🚀 Build & Deploy / 🔔 Notify (push) Successful in 2s

This commit is contained in:
2026-04-13 19:11:04 +02:00
parent 55123132f4
commit 9bb2186f7a

View File

@@ -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",