fix: fallback to legacy keys for variant lookup

This commit is contained in:
William Valentin
2026-02-01 12:13:39 -08:00
parent 26e2d74d2b
commit 517e21d0b7
3 changed files with 71 additions and 17 deletions

View File

@@ -1,9 +1,33 @@
import { test, expect } from "bun:test";
test("/api/assets/:id/url returns 404 when requested variant missing", async () => {
test("variant lookup returns null when no matching variant", async () => {
const { pickVariantKey } = await import(
"../../app/api/assets/[id]/url/variant",
);
const key = pickVariantKey({ variants: [] }, { kind: "thumb", size: 256 });
expect(key).toBeNull();
});
test("legacy fallback maps kind+size to asset keys", async () => {
const { pickLegacyKeyForRequest } = await import(
"../../app/api/assets/[id]/url/variant",
);
const asset = {
thumb_small_key: "thumb-small",
thumb_med_key: "thumb-med",
poster_key: "poster",
};
expect(
pickLegacyKeyForRequest({ asset }, { kind: "thumb", size: 256 }),
).toBe("thumb-small");
expect(
pickLegacyKeyForRequest({ asset }, { kind: "thumb", size: 768 }),
).toBe("thumb-med");
expect(
pickLegacyKeyForRequest({ asset }, { kind: "poster", size: 256 }),
).toBe("poster");
expect(
pickLegacyKeyForRequest({ asset }, { kind: "thumb", size: 1024 }),
).toBeNull();
});