31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { cloudinaryAvatarUrl } from "~/lib/cloudinary-url";
|
|
|
|
const BASE = "https://res.cloudinary.com/demo/image/upload/v1/avatars/user-1.jpg";
|
|
|
|
describe("cloudinaryAvatarUrl", () => {
|
|
it("inserts retina transformation into a Cloudinary URL", () => {
|
|
expect(cloudinaryAvatarUrl(BASE, 48)).toBe(
|
|
"https://res.cloudinary.com/demo/image/upload/w_96,h_96,c_fill,g_face,f_auto,q_auto/v1/avatars/user-1.jpg"
|
|
);
|
|
});
|
|
|
|
it("doubles the display size for retina", () => {
|
|
const result = cloudinaryAvatarUrl(BASE, 24);
|
|
expect(result).toContain("w_48,h_48");
|
|
});
|
|
|
|
it("passes non-Cloudinary URLs through unchanged", () => {
|
|
const url = "https://lh3.googleusercontent.com/photo.jpg";
|
|
expect(cloudinaryAvatarUrl(url, 48)).toBe(url);
|
|
});
|
|
|
|
it("passes null-ish strings through unchanged", () => {
|
|
expect(cloudinaryAvatarUrl("", 48)).toBe("");
|
|
});
|
|
|
|
it("is idempotent — calling twice returns the same URL", () => {
|
|
const once = cloudinaryAvatarUrl(BASE, 48);
|
|
expect(cloudinaryAvatarUrl(once, 48)).toBe(once);
|
|
});
|
|
});
|