test(extensions): cover malformed marketplace details

This commit is contained in:
wiiiii123
2026-07-11 11:22:22 +07:00
parent e032f3705f
commit 2b4d69a210
+22
View File
@@ -38,6 +38,28 @@ describe("formatMarketplaceHttpError", () => {
).toBe("Marketplace request failed (HTTP 409): Extension version already exists");
});
it("prefers a string error when both JSON detail fields are present", () => {
expect(
formatMarketplaceHttpError({
status: 400,
contentType: "application/json",
body: JSON.stringify({ error: "Primary detail", message: "Secondary detail" }),
}),
).toBe("Marketplace request failed (HTTP 400): Primary detail");
});
it("hides malformed JSON bodies", () => {
const body = '{"error":"internal route details"';
const message = formatMarketplaceHttpError({
status: 400,
contentType: "application/json",
body,
});
expect(message).toBe("Marketplace request failed (HTTP 400).");
expect(message).not.toContain(body);
});
it("bounds long JSON details and marks truncation without splitting Unicode", () => {
const detail = `🚀${"x".repeat(200)}`;
const message = formatMarketplaceHttpError({