mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-24 14:55:37 +00:00
test(extensions): cover bounded marketplace details
This commit is contained in:
@@ -28,6 +28,28 @@ describe("formatMarketplaceHttpError", () => {
|
||||
).toBe("Marketplace request failed (HTTP 400): Invalid search query");
|
||||
});
|
||||
|
||||
it("uses a JSON message when an error field is absent", () => {
|
||||
expect(
|
||||
formatMarketplaceHttpError({
|
||||
status: 409,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ message: "Extension version already exists" }),
|
||||
}),
|
||||
).toBe("Marketplace request failed (HTTP 409): Extension version already exists");
|
||||
});
|
||||
|
||||
it("bounds long JSON details and marks truncation without splitting Unicode", () => {
|
||||
const detail = `🚀${"x".repeat(200)}`;
|
||||
const message = formatMarketplaceHttpError({
|
||||
status: 400,
|
||||
contentType: "application/problem+json",
|
||||
body: JSON.stringify({ error: detail }),
|
||||
});
|
||||
|
||||
expect(message).toBe(`Marketplace request failed (HTTP 400): 🚀${"x".repeat(198)}…`);
|
||||
expect(Array.from(message.split(": ")[1])).toHaveLength(200);
|
||||
});
|
||||
|
||||
it("does not expose non-JSON response bodies", () => {
|
||||
expect(
|
||||
formatMarketplaceHttpError({
|
||||
|
||||
@@ -25,10 +25,12 @@ export function formatMarketplaceHttpError({
|
||||
const { error, message } = payload as { error?: unknown; message?: unknown };
|
||||
const value = typeof error === "string" ? error : message;
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
detail = value
|
||||
.trim()
|
||||
.replace(/\s+/g, " ")
|
||||
.slice(0, MAX_MARKETPLACE_ERROR_DETAIL_LENGTH);
|
||||
const normalized = value.trim().replace(/\s+/g, " ");
|
||||
const codePoints = Array.from(normalized);
|
||||
detail =
|
||||
codePoints.length > MAX_MARKETPLACE_ERROR_DETAIL_LENGTH
|
||||
? `${codePoints.slice(0, MAX_MARKETPLACE_ERROR_DETAIL_LENGTH - 1).join("")}…`
|
||||
: normalized;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user