fix: fallback to legacy keys for variant lookup
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user