|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { getRouteErrorMessage } from "./httpErrors"; |
| 3 | + |
| 4 | +describe("getRouteErrorMessage", () => { |
| 5 | + it("returns data.message when present", () => { |
| 6 | + expect(getRouteErrorMessage(500, "Internal Server Error", { message: "boom" })).toBe("boom"); |
| 7 | + }); |
| 8 | + |
| 9 | + it("falls back when data is null", () => { |
| 10 | + expect(getRouteErrorMessage(500, "Internal Server Error", null)).toBe( |
| 11 | + "Something went wrong on our end. Please try again later." |
| 12 | + ); |
| 13 | + }); |
| 14 | + |
| 15 | + it("falls back when data is undefined", () => { |
| 16 | + expect(getRouteErrorMessage(404, "Not Found", undefined)).toBe( |
| 17 | + "The page you're looking for doesn't exist." |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + it("uses a string data body", () => { |
| 22 | + expect(getRouteErrorMessage(400, "Bad Request", "Invalid payload")).toBe("Invalid payload"); |
| 23 | + }); |
| 24 | + |
| 25 | + it("falls back when message is missing or empty", () => { |
| 26 | + expect(getRouteErrorMessage(403, "Forbidden", {})).toBe( |
| 27 | + "You don't have permission to access this resource." |
| 28 | + ); |
| 29 | + expect(getRouteErrorMessage(403, "Forbidden", { message: "" })).toBe( |
| 30 | + "You don't have permission to access this resource." |
| 31 | + ); |
| 32 | + }); |
| 33 | +}); |
0 commit comments