|
|
import { describe, expect, it } from "vitest";
|
|
|
import { formatImapConnectError } from "@/lib/imap-presets";
|
|
|
import { formatImapSyncError } from "@/constants/error-copy";
|
|
|
|
|
|
describe("formatImapConnectError", () => {
|
|
|
it("digs ETIMEDOUT out of empty AggregateError", () => {
|
|
|
const child = Object.assign(new Error(""), {
|
|
|
code: "ETIMEDOUT",
|
|
|
address: "74.125.204.108",
|
|
|
port: 993,
|
|
|
});
|
|
|
const err = new AggregateError([child], "");
|
|
|
(err as NodeJS.ErrnoException).code = "ETIMEDOUT";
|
|
|
const msg = formatImapConnectError(err, {
|
|
|
host: "imap.gmail.com",
|
|
|
user: "a@gmail.com",
|
|
|
});
|
|
|
expect(msg).toMatch(/无法连接 Gmail/);
|
|
|
expect(msg).toMatch(/国内网络/);
|
|
|
expect(msg).toMatch(/ETIMEDOUT/);
|
|
|
});
|
|
|
|
|
|
it("keeps auth guidance for Gmail", () => {
|
|
|
const msg = formatImapConnectError(new Error("Invalid credentials"), {
|
|
|
host: "imap.gmail.com",
|
|
|
user: "a@gmail.com",
|
|
|
});
|
|
|
expect(msg).toMatch(/应用专用密码/);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe("formatImapSyncError", () => {
|
|
|
it("does not fall back to import-record copy", () => {
|
|
|
expect(formatImapSyncError("")).toMatch(/邮件服务器/);
|
|
|
expect(formatImapSyncError("mailbox_fail:谷歌邮箱测试: ")).not.toMatch(
|
|
|
/导入记录/,
|
|
|
);
|
|
|
expect(formatImapSyncError("无法连接 imap.gmail.com:ETIMEDOUT")).toMatch(
|
|
|
/无法连接|连接超时|网络/,
|
|
|
);
|
|
|
});
|
|
|
});
|