/ opencodehub / tests / unit / email.test.ts
Swadhin Biswas test(qa): add e2e, integration, unit, and load coverage · 3/6/2026
1c29e63
45 lines · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { beforeEach, describe, expect, it, vi } from "vitest";

vi.mock("@/lib/logger", () => ({
  logger: {
    info: vi.fn(),
    warn: vi.fn(),
    error: vi.fn(),
    debug: vi.fn(),
  },
}));

// Mock nodemailer
vi.mock("nodemailer", () => ({
  default: {
    createTransport: vi.fn(() => ({
      sendMail: vi.fn().mockResolvedValue({ messageId: "test-123" }),
    })),
  },
  createTransport: vi.fn(() => ({
    sendMail: vi.fn().mockResolvedValue({ messageId: "test-123" }),
  })),
}));

describe("email", () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("exports isSmtpConfigured function", async () => {
    const mod = await import("@/lib/email");
    expect(typeof mod.isSmtpConfigured).toBe("function");
  });

  it("exports sendEmail function", async () => {
    const mod = await import("@/lib/email");
    expect(typeof mod.sendEmail).toBe("function");
  });

  it("isSmtpConfigured returns boolean", async () => {
    const { isSmtpConfigured } = await import("@/lib/email");
    const result = isSmtpConfigured();
    expect(typeof result).toBe("boolean");
  });
});