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.
31 lines
1.1 KiB
31 lines
1.1 KiB
import { describe, expect, it } from "vitest";
|
|
import type { TranslationKey } from "@/i18n";
|
|
import { formatUserFacingError } from "@/utils/userFacingErrors";
|
|
|
|
const t = (key: TranslationKey, values?: Record<string, string | number>) => {
|
|
if (key === "error.providerOverloaded") {
|
|
return `${values?.model}: localized overload`;
|
|
}
|
|
return key;
|
|
};
|
|
|
|
describe("formatUserFacingError", () => {
|
|
it("localizes normalized provider overload errors", () => {
|
|
expect(formatUserFacingError(
|
|
"apiyi_nano_banana_pro: provider is temporarily overloaded. Please retry in a moment or switch models.",
|
|
t
|
|
)).toBe("apiyi_nano_banana_pro: localized overload");
|
|
});
|
|
|
|
it("uses the currently displayed model name when provided", () => {
|
|
expect(formatUserFacingError(
|
|
"apiyi_nano_banana_pro: provider is temporarily overloaded. Please retry in a moment or switch models.",
|
|
t,
|
|
"PopiArt Nano Pro"
|
|
)).toBe("PopiArt Nano Pro: localized overload");
|
|
});
|
|
|
|
it("preserves unknown upstream errors", () => {
|
|
expect(formatUserFacingError("unexpected upstream failure", t)).toBe("unexpected upstream failure");
|
|
});
|
|
});
|
|
|