src / __tests__ / accounts.regression.test.ts
import { describe, expect, it } from "vitest";
import { resolveAccount } from "../accounts";
function makeCfg(overrides: Record<string, string | number> = {}) {
const values: Record<string, string | number> = {
account1Label: "Personal",
account1ImapHost: "imap.example.com",
account1ImapPort: 993,
account1User: "one@example.com",
account1Password: "secret-1",
account1SmtpHost: "",
account1SmtpPort: 587,
account2Label: "Work",
account2ImapHost: "imap.example.com",
account2ImapPort: 993,
account2User: "two@example.com",
account2Password: "secret-2",
account2SmtpHost: "",
account2SmtpPort: 587,
account3Label: "",
account3ImapHost: "",
account3ImapPort: 993,
account3User: "",
account3Password: "",
account3SmtpHost: "",
account3SmtpPort: 587,
...overrides,
};
return { get: (key: string) => values[key] ?? "" };
}
describe("resolveAccount regressions", () => {
it("blank uses the first configured account, but exact slot 1 stays exact", () => {
const cfg = makeCfg({ account1Password: "" });
expect(resolveAccount(cfg, "").slot).toBe(2);
expect(() => resolveAccount(cfg, "1")).toThrow("Account 1 is not configured");
});
it("does not accept a numeric prefix with trailing text", () => {
expect(() => resolveAccount(makeCfg(), "2foo")).toThrow("not found");
});
it("trims account references", () => {
expect(resolveAccount(makeCfg(), " 2 ").slot).toBe(2);
expect(resolveAccount(makeCfg(), " work ").slot).toBe(2);
});
it("rejects duplicate labels as ambiguous", () => {
const cfg = makeCfg({ account2Label: "Personal" });
expect(() => resolveAccount(cfg, "personal")).toThrow("ambiguous");
});
});
src / __tests__ / accounts.regression.test.ts
import { describe, expect, it } from "vitest";
import { resolveAccount } from "../accounts";
function makeCfg(overrides: Record<string, string | number> = {}) {
const values: Record<string, string | number> = {
account1Label: "Personal",
account1ImapHost: "imap.example.com",
account1ImapPort: 993,
account1User: "one@example.com",
account1Password: "secret-1",
account1SmtpHost: "",
account1SmtpPort: 587,
account2Label: "Work",
account2ImapHost: "imap.example.com",
account2ImapPort: 993,
account2User: "two@example.com",
account2Password: "secret-2",
account2SmtpHost: "",
account2SmtpPort: 587,
account3Label: "",
account3ImapHost: "",
account3ImapPort: 993,
account3User: "",
account3Password: "",
account3SmtpHost: "",
account3SmtpPort: 587,
...overrides,
};
return { get: (key: string) => values[key] ?? "" };
}
describe("resolveAccount regressions", () => {
it("blank uses the first configured account, but exact slot 1 stays exact", () => {
const cfg = makeCfg({ account1Password: "" });
expect(resolveAccount(cfg, "").slot).toBe(2);
expect(() => resolveAccount(cfg, "1")).toThrow("Account 1 is not configured");
});
it("does not accept a numeric prefix with trailing text", () => {
expect(() => resolveAccount(makeCfg(), "2foo")).toThrow("not found");
});
it("trims account references", () => {
expect(resolveAccount(makeCfg(), " 2 ").slot).toBe(2);
expect(resolveAccount(makeCfg(), " work ").slot).toBe(2);
});
it("rejects duplicate labels as ambiguous", () => {
const cfg = makeCfg({ account2Label: "Personal" });
expect(() => resolveAccount(cfg, "personal")).toThrow("ambiguous");
});
});