import { AxiosError, CanceledError } from "axios"; const { getApiErrorMessage } = jest.requireActual("./api"); test.each(["Failed to update company.", "Kunne ikke oppdatere selskap."])("transport failures use the caller's localized fallback: %s", (fallback) => { for (const message of ["Request failed with status code 500", "Network Error", "timeout of 10000ms exceeded"]) { expect(getApiErrorMessage(new AxiosError(message), fallback)).toBe(fallback); } }); test("structured validation and sanitized server explanations remain available", () => { for (const data of [{ detail: "Review the company name." }, { errors: { name: ["Review the company name."] } }]) { expect(getApiErrorMessage(Object.assign(new AxiosError("Request failed with status code 400"), { response: { data } }), "Localized fallback")).toBe("Review the company name."); } expect(getApiErrorMessage({ response: { data: "proxy error" } }, "Localized fallback")).toBe("Localized fallback"); }); test("explicit session cancellation explanations remain intact", () => { expect(getApiErrorMessage(new CanceledError("This page belongs to an earlier session."), "Localized fallback")).toBe("This page belongs to an earlier session."); }); test("ordinary application errors retain their explanation", () => { expect(getApiErrorMessage(new Error("The draft changed."), "Localized fallback")).toBe("The draft changed."); });