Files
frontend/src/shared/api/problem-details.test.ts
T
codex-bot 9619dc9791
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 10s
Frontend verify / verify (push) Failing after 6m34s
fix(account): show source metadata on empty account and income (WealthLedger/frontend#55) (#133)
2026-11-03 06:44:13 +03:00

31 lines
1.1 KiB
TypeScript

import { expect, it } from "vitest";
import {
ApiErrorCode,
apiErrorCode,
isApiErrorCode,
isBrokerageAccessLoss,
} from "./problem-details";
it("matches known codes and preserves unknown wire codes for fallback handling", () => {
expect(
isApiErrorCode(
apiErrorCode({ code: "UNAUTHORIZED" }),
ApiErrorCode.Unauthorized,
),
).toBe(true);
const unknownCode = apiErrorCode({ code: "FUTURE_PROVIDER_ERROR" });
expect(unknownCode).toBe("FUTURE_PROVIDER_ERROR");
expect(isApiErrorCode(unknownCode, ApiErrorCode.Unauthorized)).toBe(false);
expect(isApiErrorCode(undefined, ApiErrorCode.Unauthorized)).toBe(false);
expect(apiErrorCode(null)).toBeUndefined();
expect(apiErrorCode({})).toBeUndefined();
});
it("separates brokerage access loss from UNAUTHORIZED, temporary and unknown codes", () => {
for (const code of ["INVALID_TBANK_TOKEN", "NOT_FOUND", "TBANK_NOT_CONNECTED"])
expect(isBrokerageAccessLoss(code)).toBe(true);
for (const code of ["UNAUTHORIZED", "TBANK_UNAVAILABLE", "FUTURE_PROVIDER_ERROR", undefined])
expect(isBrokerageAccessLoss(code)).toBe(false);
});