import { describe, it, expect, beforeEach, vi } from "vitest"; // Mock server-only avant l'import du module sous test (sinon ça jette). vi.mock("server-only", () => ({})); describe("sendEmail (dry-run sans RESEND_API_KEY)", () => { beforeEach(() => { delete process.env.RESEND_API_KEY; vi.resetModules(); }); it("renvoie ok=true + reason=dry-run quand pas de clé", async () => { const { sendEmail } = await import("@/lib/email"); const res = await sendEmail({ to: "test@example.com", subject: "hello", html: "
world
", }); expect(res.ok).toBe(true); expect(res.reason).toBe("dry-run"); }); it("n'écrit pas d'erreur quand pas de clé", async () => { const errSpy = vi.spyOn(console, "error").mockImplementation(() => {}); const { sendEmail } = await import("@/lib/email"); await sendEmail({ to: "x@y.z", subject: "s", html: "h" }); expect(errSpy).not.toHaveBeenCalled(); errSpy.mockRestore(); }); });