Project Files
__tests__ / smtp.test.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const nodemailer_1 = __importDefault(require("nodemailer"));
const smtp_1 = require("../smtp");
// Uses Ethereal — a free fake SMTP service that accepts mail without delivering it.
// No credentials needed: nodemailer.createTestAccount() provisions a throw-away account.
(0, vitest_1.describe)("sendEmail (Ethereal SMTP)", () => {
(0, vitest_1.it)("sends a plain email and returns a messageId", async () => {
const testAccount = await nodemailer_1.default.createTestAccount();
const messageId = await (0, smtp_1.sendEmail)({
host: testAccount.smtp.host,
port: testAccount.smtp.port,
user: testAccount.user,
password: testAccount.pass,
}, {
from: testAccount.user,
to: testAccount.user,
subject: "Test email from email-plugin",
body: "Hello from the email plugin test suite.",
});
(0, vitest_1.expect)(typeof messageId).toBe("string");
(0, vitest_1.expect)(messageId.length).toBeGreaterThan(0);
console.log("Preview URL:", nodemailer_1.default.getTestMessageUrl({ messageId, envelope: { from: testAccount.user, to: [testAccount.user] } }));
}, 15_000);
(0, vitest_1.it)("sends a reply with In-Reply-To header", async () => {
const testAccount = await nodemailer_1.default.createTestAccount();
const messageId = await (0, smtp_1.sendEmail)({
host: testAccount.smtp.host,
port: testAccount.smtp.port,
user: testAccount.user,
password: testAccount.pass,
}, {
from: testAccount.user,
to: testAccount.user,
subject: "Re: Original subject",
body: "This is a reply.",
inReplyTo: "<original-message-id@test.com>",
references: "<original-message-id@test.com>",
});
(0, vitest_1.expect)(messageId).toBeTruthy();
}, 15_000);
(0, vitest_1.it)("sends with CC", async () => {
const testAccount = await nodemailer_1.default.createTestAccount();
const messageId = await (0, smtp_1.sendEmail)({
host: testAccount.smtp.host,
port: testAccount.smtp.port,
user: testAccount.user,
password: testAccount.pass,
}, {
from: testAccount.user,
to: testAccount.user,
cc: testAccount.user,
subject: "CC test",
body: "Testing CC field.",
});
(0, vitest_1.expect)(messageId).toBeTruthy();
}, 15_000);
(0, vitest_1.it)("throws on bad credentials", async () => {
await (0, vitest_1.expect)((0, smtp_1.sendEmail)({ host: "smtp.ethereal.email", port: 587, user: "bad@user.com", password: "wrongpass" }, { from: "bad@user.com", to: "test@test.com", subject: "fail", body: "fail" })).rejects.toThrow();
}, 15_000);
});