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
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:
@@ -6,6 +6,16 @@ const { mockCreate, mockSendEmail } = vi.hoisted(() => ({
|
|||||||
mockSendEmail: vi.fn(),
|
mockSendEmail: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Mock Nodemailer
|
||||||
|
const mockSendMail = vi.fn();
|
||||||
|
vi.mock("nodemailer", () => ({
|
||||||
|
default: {
|
||||||
|
createTransport: vi.fn().mockReturnValue({
|
||||||
|
sendMail: mockSendMail,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("payload", () => ({
|
vi.mock("payload", () => ({
|
||||||
getPayload: vi.fn().mockResolvedValue({
|
getPayload: vi.fn().mockResolvedValue({
|
||||||
create: mockCreate,
|
create: mockCreate,
|
||||||
@@ -101,7 +111,7 @@ describe("Contact API Integration", () => {
|
|||||||
|
|
||||||
// But it actually does NOTHING internally
|
// But it actually does NOTHING internally
|
||||||
expect(mockCreate).not.toHaveBeenCalled();
|
expect(mockCreate).not.toHaveBeenCalled();
|
||||||
expect(mockSendEmail).not.toHaveBeenCalled();
|
expect(mockSendMail).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should successfully save to Payload and send emails", async () => {
|
it("should successfully save to Payload and send emails", async () => {
|
||||||
@@ -140,10 +150,10 @@ describe("Contact API Integration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 2. Verify Email Sending
|
// 2. Verify Email Sending
|
||||||
// Note: sendEmail is called twice (Notification + User Confirmation)
|
// Note: sendMail is called twice (Notification + User Confirmation)
|
||||||
expect(mockSendEmail).toHaveBeenCalledTimes(2);
|
expect(mockSendMail).toHaveBeenCalledTimes(2);
|
||||||
|
|
||||||
expect(mockSendEmail).toHaveBeenNthCalledWith(
|
expect(mockSendMail).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
subject: "Kontaktanfrage von Jane Doe",
|
subject: "Kontaktanfrage von Jane Doe",
|
||||||
@@ -151,7 +161,7 @@ describe("Contact API Integration", () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(mockSendEmail).toHaveBeenNthCalledWith(
|
expect(mockSendMail).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
to: "jane@example.com",
|
to: "jane@example.com",
|
||||||
|
|||||||
Reference in New Issue
Block a user