import { describe, it, expect } from "vitest"; import { REVIEW_COMMENT_MAX, REVIEW_HOST_RESPONSE_MAX, REVIEW_RATING_MAX, REVIEW_RATING_MIN, formatAverageRating, isValidRating, } from "@/lib/reviews"; describe("rating constants", () => { it("min=1 max=5", () => { expect(REVIEW_RATING_MIN).toBe(1); expect(REVIEW_RATING_MAX).toBe(5); }); it("comment + host response caps are sensible", () => { expect(REVIEW_COMMENT_MAX).toBeGreaterThan(0); expect(REVIEW_HOST_RESPONSE_MAX).toBeGreaterThan(0); }); }); describe("isValidRating", () => { it("accepts integers 1-5", () => { for (let i = REVIEW_RATING_MIN; i <= REVIEW_RATING_MAX; i++) { expect(isValidRating(i)).toBe(true); } }); it("rejects out-of-range", () => { expect(isValidRating(0)).toBe(false); expect(isValidRating(6)).toBe(false); expect(isValidRating(-1)).toBe(false); }); it("rejects non-integers and non-numbers", () => { expect(isValidRating(3.5)).toBe(false); expect(isValidRating("3")).toBe(false); expect(isValidRating(null)).toBe(false); expect(isValidRating(undefined)).toBe(false); }); }); describe("formatAverageRating", () => { it("returns dash for null", () => { expect(formatAverageRating(null)).toMatch(/—|-|n\/a/i); }); it("formats a number with one decimal", () => { const s = formatAverageRating(4.567); expect(s).toMatch(/4[.,]/); }); });