55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
getAvatarUrl,
|
|
resolveImagerBase,
|
|
resolveUpstreamBase,
|
|
} from "./imager";
|
|
|
|
describe("resolveImagerBase", () => {
|
|
it("defaults to /imaging when no public URL env is set", () => {
|
|
expect(resolveImagerBase()).toBe("/imaging");
|
|
expect(resolveImagerBase("")).toBe("/imaging");
|
|
expect(resolveImagerBase(null)).toBe("/imaging");
|
|
});
|
|
|
|
it("rejects the broken self-hosted proxy", () => {
|
|
expect(resolveImagerBase("/api/imaging/avatar")).toBe("/imaging");
|
|
expect(
|
|
resolveImagerBase("https://www.epicnabbo.nl/api/imaging/avatar"),
|
|
).toBe("/imaging");
|
|
});
|
|
|
|
it("accepts /imaging as a valid configured URL", () => {
|
|
expect(resolveImagerBase("/imaging")).toBe("/imaging");
|
|
});
|
|
|
|
it("keeps a custom Habbo-compatible base", () => {
|
|
expect(
|
|
resolveImagerBase("https://www.habbo.com/habbo-imaging/avatarimage/"),
|
|
).toBe("https://www.habbo.com/habbo-imaging/avatarimage");
|
|
});
|
|
});
|
|
|
|
describe("resolveUpstreamBase", () => {
|
|
it("defaults to Habbo's public imager", () => {
|
|
const url = resolveUpstreamBase();
|
|
expect(url).toBe("https://www.habbo.com/habbo-imaging/avatarimage");
|
|
});
|
|
});
|
|
|
|
describe("getAvatarUrl", () => {
|
|
it("builds an imager URL", () => {
|
|
const url = getAvatarUrl("hr-115-42.hd-180-1", {
|
|
size: "l",
|
|
headOnly: true,
|
|
direction: 2,
|
|
});
|
|
expect(url.startsWith("/imaging?")).toBe(true);
|
|
expect(url).toContain("figure=hr-115-42.hd-180-1");
|
|
expect(url).toContain("size=l");
|
|
expect(url).toContain("headonly=1");
|
|
expect(url).toContain("direction=2");
|
|
expect(url).toContain("img_format=png");
|
|
});
|
|
});
|