Files
OmniRoute/tests/unit/api-error-message-5340.test.ts
Diego Rodrigues de Sa e Souza 78f09c8d9f Release v3.8.41 (#5327)
Release v3.8.41 — 52 commits since v3.8.40 (19 CHANGELOG bullets, 11 contributors).

All gating CI green: Unit×8, Coverage×8, Vitest, Package Artifact, Quality Ratchet, CodeQL, Lint, Docs Sync (Strict), Node 24/26 compat, E2E×9, Integration, Electron smoke.

Advisory checks overridden (main unprotected): PR Test Policy = test-masking heuristic on the cumulative 52-commit assert delta (legitimate dead-code-sweep removals + consolidations, reviewed per-PR); SonarCloud/SonarQube = new-code maintainability/coverage quality gate (CodeQL/Semgrep/Security/npm-audit/Dependabot all clean — not a security finding).
2026-06-29 16:51:03 -03:00

29 lines
1.2 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { extractApiErrorMessage } from "@/shared/http/apiErrorMessage";
describe("extractApiErrorMessage (#5340)", () => {
it("surfaces the message from a structured error envelope", () => {
const body = {
error: { code: "INVALID_ORIGIN", message: "Invalid request origin", correlation_id: "x" },
};
assert.equal(extractApiErrorMessage(body, "fallback"), "Invalid request origin");
});
it("returns a plain string error as-is", () => {
assert.equal(extractApiErrorMessage({ error: "boom" }, "fallback"), "boom");
});
it("never renders a raw error object — falls back when message is missing", () => {
assert.equal(extractApiErrorMessage({ error: { code: "X" } }, "fallback"), "fallback");
});
it("falls back for empty, null, or malformed bodies", () => {
assert.equal(extractApiErrorMessage({ error: " " }, "fallback"), "fallback");
assert.equal(extractApiErrorMessage(null, "fallback"), "fallback");
assert.equal(extractApiErrorMessage({}, "fallback"), "fallback");
assert.equal(extractApiErrorMessage({ error: { message: 42 } }, "fallback"), "fallback");
});
});