42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import { buildImageProxyUrl } from "@/lib/image-delivery";
|
|
|
|
test.describe("Qiniu image delivery", () => {
|
|
test("uses Qiniu image processing for direct canvas previews", () => {
|
|
expect(
|
|
buildImageProxyUrl("https://yybb.top/uploads/result.png", {
|
|
width: 1200,
|
|
quality: 80,
|
|
format: "webp",
|
|
})
|
|
).toBe(
|
|
"https://yybb.top/uploads/result.png?imageView2/2/w/1200/format/webp/q/80"
|
|
);
|
|
});
|
|
|
|
test("optimizes legacy first-party upload URLs without changing their identity", () => {
|
|
expect(
|
|
buildImageProxyUrl("https://bbyy.ai/uploads/result.png", {
|
|
width: 960,
|
|
quality: 88,
|
|
format: "webp",
|
|
})
|
|
).toBe(
|
|
"https://bbyy.ai/uploads/result.png?imageView2/2/w/960/format/webp/q/88"
|
|
);
|
|
});
|
|
|
|
test("does not overwrite an existing storage query", () => {
|
|
const url = "https://yybb.top/uploads/result.png?imageView2/2/w/400";
|
|
expect(buildImageProxyUrl(url, { width: 1200, format: "webp" })).toBe(url);
|
|
});
|
|
|
|
test("keeps unrelated first-party URLs out of the Qiniu path", () => {
|
|
const result = buildImageProxyUrl("https://bbyy.ai/logo.png", {
|
|
delivery: "proxy",
|
|
width: 320,
|
|
});
|
|
expect(result).toContain("/api/image-proxy?");
|
|
});
|
|
});
|