You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mail-yubao/tests/unit/imap-connect-error.test.ts

43 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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(
/无法连接|连接超时|网络/,
);
});
});