refactor: enforce enum machine codes #18
Use owner enums for known codes; preserve wire values and unknown fallbacks. Verified npm ci and verify: 379 tests, 5 lint checks, app and Storybook builds.
This commit was merged in pull request #41.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
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();
|
||||
});
|
||||
Reference in New Issue
Block a user