import { describe, expect, it } from "@suaveplan/testing/runner"; import { FakeSmtpClient } from "./fake-smtp-client.js"; describe("FakeSmtpClient", () => { it("consumes scripted responses in FIFO order", { timeout: 5000, }, async () => { const f = new FakeSmtpClient(); f.push({ info: { messageId: "<1@h>" } }); f.push({ info: { messageId: "<2@h>" } }); const a = await f.sendMail({ from: "a", to: "b", subject: "x" }); const b = await f.sendMail({ from: "a", to: "b", subject: "x" }); expect(a.messageId).toBe("<1@h>"); expect(b.messageId).toBe("<2@h>"); expect(f.calls.length).toBe(2); }); it("rejects with no response queued", { timeout: 5000 }, async () => { const f = new FakeSmtpClient(); await expect( f.sendMail({ from: "a", to: "b", subject: "x" }) ).rejects.toThrow("no response queued"); }); it("rejects when scripted reject is supplied", { timeout: 5000, }, async () => { const f = new FakeSmtpClient(); f.push({ reject: new Error("nope") }); await expect( f.sendMail({ from: "a", to: "b", subject: "x" }) ).rejects.toThrow("nope"); }); it("throws when scripted info is missing", { timeout: 5000 }, async () => { const f = new FakeSmtpClient(); f.push({}); await expect( f.sendMail({ from: "a", to: "b", subject: "x" }) ).rejects.toThrow("scripted response missing info"); }); it("verify returns scheduled boolean", { timeout: 5000 }, async () => { const f = new FakeSmtpClient(); expect(await f.verify()).toBe(true); f.scheduleVerify(false); expect(await f.verify()).toBe(false); }); it("verify rejects when scheduled error", { timeout: 5000 }, async () => { const f = new FakeSmtpClient(); f.scheduleVerify(false); f.scheduleVerify(new Error("boom")); await expect(f.verify()).rejects.toThrow("boom"); // and reverts to the last scheduled boolean expect(await f.verify()).toBe(false); }); it("close increments closeCalls", { timeout: 5000 }, async () => { const f = new FakeSmtpClient(); await f.close(); await f.close(); expect(f.closeCalls).toBe(2); }); });