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.
33 lines
1.1 KiB
33 lines
1.1 KiB
import { describe, expect, it } from "vitest";
|
|
import { p1DateFromIso, p1DateToIso } from "@/lib/priority1/date-format";
|
|
import { resolvePriority1UserMessage } from "@/lib/priority1/api-errors";
|
|
|
|
describe("p1 date format", () => {
|
|
it("converts MM/DD/YYYY to ISO and back", () => {
|
|
expect(p1DateToIso("07/15/2026")).toBe("2026-07-15");
|
|
expect(p1DateFromIso("2026-07-15")).toBe("07/15/2026");
|
|
});
|
|
});
|
|
|
|
describe("resolvePriority1UserMessage", () => {
|
|
it("keeps Chinese validation messages", () => {
|
|
expect(resolvePriority1UserMessage("VALIDATION_FAILED", "提货日须晚于今天")).toBe(
|
|
"提货日须晚于今天",
|
|
);
|
|
});
|
|
|
|
it("masks English framework errors", () => {
|
|
const msg = resolvePriority1UserMessage(
|
|
"INTERNAL_ERROR",
|
|
"Attempted to call p1DateToIso() from the server but p1DateToIso is on the client",
|
|
);
|
|
expect(msg).toContain("服务器处理失败");
|
|
expect(msg).toContain("服务配置异常");
|
|
expect(msg).not.toContain("client");
|
|
});
|
|
|
|
it("maps known error codes", () => {
|
|
expect(resolvePriority1UserMessage("UNAUTHORIZED", "")).toContain("未授权");
|
|
});
|
|
});
|