19 lines
694 B
TypeScript
19 lines
694 B
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { ApiErrorCode, apiErrorCode, isApiErrorCode } 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();
|
|
});
|