feat: complete migration to static MDX, stabilize local infrastructure and fix i18n issues
Some checks failed
🚀 Build & Deploy / 🔍 Prepare (push) Successful in 4s
🚀 Build & Deploy / 🚀 Deploy (push) Has been cancelled
🚀 Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
🚀 Build & Deploy / 🏗️ Build (push) Has been cancelled
🚀 Build & Deploy / 🔔 Notify (push) Has been cancelled
🚀 Build & Deploy / 🧪 QA (push) Has been cancelled
Some checks failed
🚀 Build & Deploy / 🔍 Prepare (push) Successful in 4s
🚀 Build & Deploy / 🚀 Deploy (push) Has been cancelled
🚀 Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
🚀 Build & Deploy / 🏗️ Build (push) Has been cancelled
🚀 Build & Deploy / 🔔 Notify (push) Has been cancelled
🚀 Build & Deploy / 🧪 QA (push) Has been cancelled
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
// Mock Payload CMS
|
||||
const { mockCreate, mockSendEmail } = vi.hoisted(() => ({
|
||||
mockCreate: vi.fn(),
|
||||
mockSendEmail: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock Nodemailer
|
||||
const { mockSendMail } = vi.hoisted(() => ({
|
||||
mockSendMail: vi.fn().mockResolvedValue({ messageId: "mock-message-id" }),
|
||||
@@ -19,13 +13,6 @@ vi.mock("nodemailer", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("payload", () => ({
|
||||
getPayload: vi.fn().mockResolvedValue({
|
||||
create: mockCreate,
|
||||
sendEmail: mockSendEmail,
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock Email Template renders
|
||||
vi.mock("@mintel/mail", () => ({
|
||||
render: vi.fn().mockResolvedValue("<html>Mocked Email HTML</html>"),
|
||||
@@ -92,9 +79,8 @@ describe("Contact API Integration", () => {
|
||||
const data = await response.json();
|
||||
expect(data.error).toBe("message_too_short");
|
||||
|
||||
// Ensure payload and email were NOT called
|
||||
expect(mockCreate).not.toHaveBeenCalled();
|
||||
expect(mockSendEmail).not.toHaveBeenCalled();
|
||||
// Ensure email was NOT called
|
||||
expect(mockSendMail).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should catch honeypot submissions", async () => {
|
||||
@@ -113,11 +99,10 @@ describe("Contact API Integration", () => {
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
// But it actually does NOTHING internally
|
||||
expect(mockCreate).not.toHaveBeenCalled();
|
||||
expect(mockSendMail).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should successfully save to Payload and send emails", async () => {
|
||||
it("should successfully send emails", async () => {
|
||||
const req = new Request("http://localhost/api/contact", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -139,20 +124,7 @@ describe("Contact API Integration", () => {
|
||||
const data = await response.json();
|
||||
expect(data.message).toBe("Ok");
|
||||
|
||||
// 1. Verify Payload creation
|
||||
expect(mockCreate).toHaveBeenCalledTimes(1);
|
||||
expect(mockCreate).toHaveBeenCalledWith({
|
||||
collection: "form-submissions",
|
||||
data: {
|
||||
name: "Jane Doe",
|
||||
email: "jane@example.com",
|
||||
company: "Jane Tech",
|
||||
message:
|
||||
"Hello, I am interested in exploring your high-voltage grid solutions.",
|
||||
},
|
||||
});
|
||||
|
||||
// 2. Verify Email Sending
|
||||
// 1. Verify Email Sending
|
||||
// Note: sendMail is called twice (Notification + User Confirmation)
|
||||
expect(mockSendMail).toHaveBeenCalledTimes(2);
|
||||
|
||||
@@ -172,8 +144,7 @@ describe("Contact API Integration", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 3. Verify notification and analytics
|
||||
expect(mockNotify).toHaveBeenCalledTimes(1);
|
||||
// 2. Verify notifications and analytics
|
||||
expect(mockTrack).toHaveBeenCalledWith("contact-form-success", {
|
||||
has_company: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user