fix: replace misleading SDK claims with honest code examples messaging
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Failing after 1m3s

This commit is contained in:
Hoid 2026-02-26 07:02:57 +00:00
parent 50a163b12d
commit 9dcc473e78
4 changed files with 64 additions and 5 deletions

View file

@ -0,0 +1,59 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
// Mock nodemailer before importing email service
const mockSendMail = vi.fn();
vi.mock("nodemailer", () => ({
default: {
createTransport: vi.fn(() => ({
sendMail: mockSendMail,
})),
},
}));
// Mock logger
vi.mock("../services/logger.js", () => ({
default: { info: vi.fn(), error: vi.fn(), warn: vi.fn(), debug: vi.fn() },
}));
import { sendVerificationEmail } from "../services/email.js";
describe("Email Service", () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe("sendVerificationEmail", () => {
it("constructs correct email with code", async () => {
mockSendMail.mockResolvedValueOnce({ messageId: "test-123" });
const result = await sendVerificationEmail("user@example.com", "654321");
expect(result).toBe(true);
expect(mockSendMail).toHaveBeenCalledOnce();
const mailOptions = mockSendMail.mock.calls[0][0];
expect(mailOptions.to).toBe("user@example.com");
expect(mailOptions.subject).toContain("DocFast");
expect(mailOptions.subject).toContain("Verify");
expect(mailOptions.text).toContain("654321");
expect(mailOptions.html).toContain("654321");
});
it("returns false when SMTP fails", async () => {
mockSendMail.mockRejectedValueOnce(new Error("SMTP connection refused"));
const result = await sendVerificationEmail("user@example.com", "123456");
expect(result).toBe(false);
});
it("includes expiry notice in email body", async () => {
mockSendMail.mockResolvedValueOnce({ messageId: "test-456" });
await sendVerificationEmail("user@example.com", "111111");
const mailOptions = mockSendMail.mock.calls[0][0];
expect(mailOptions.text).toContain("15 minutes");
});
});
});