karbe/tests/lib/email.test.ts
Claude Integration 14fd9a5940
Some checks failed
CI / test (pull_request) Failing after 2m13s
feat(p2): vitest + 27 tests + /api/health enrichi + /api/metrics + workflow CI
2026-06-01 02:27:14 +00:00

30 lines
990 B
TypeScript

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: "<p>world</p>",
});
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();
});
});