perf : cache
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ reads: [] as unknown[], rows: new Map<unknown, unknown[]>() }));
|
||||
const mocks = vi.hoisted(() => ({ reads: [] as unknown[], selections: [] as unknown[], rows: new Map<unknown, unknown[]>() }));
|
||||
vi.mock("server-only", () => ({}));
|
||||
vi.mock("@/lib/media/storage", () => ({ publicMediaUrl: (key: string) => `/media/${key}` }));
|
||||
vi.mock("@/db", () => ({
|
||||
getDb: () => ({
|
||||
select: () => {
|
||||
select: (columns?: unknown) => {
|
||||
mocks.selections.push(columns);
|
||||
let table: unknown;
|
||||
const query = {
|
||||
from(value: unknown) { table = value; return query; },
|
||||
@@ -29,10 +30,11 @@ import {
|
||||
guides, guideSections, teamCompositions, teamConditions, teamMembers, weaponConditions,
|
||||
catalogCharacters, catalogMaterials, guidePosterBleeding, media, weaponRecommendations, artifactRecommendations,
|
||||
} from "@/db/schema";
|
||||
import { getActiveCatalog, getAdminGuideContent, getPublicGuide, listAdminTeamImportsForCharacter } from "./queries";
|
||||
import { getActiveCatalog, getCatalogOptions, getAdminGuideContent, getPublicGuide, listAdminTeamImportsForCharacter } from "./queries";
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.reads.length = 0;
|
||||
mocks.selections.length = 0;
|
||||
mocks.rows.clear();
|
||||
mocks.rows.set(guides, [{
|
||||
guide: { id: "guide", slug: "test", posterArtMediaId: null },
|
||||
@@ -202,3 +204,15 @@ describe("public overview build summary", () => {
|
||||
expect(mocks.reads).not.toContain(weaponRecommendations);
|
||||
});
|
||||
});
|
||||
|
||||
describe("catalog picker reads", () => {
|
||||
it("selects only character picker and export artwork fields", async () => {
|
||||
mocks.rows.set(catalogCharacters, [{ key: "test", name: "Test", imageKey: "avatar", coopImageKey: "splash" }]);
|
||||
const catalog = await getCatalogOptions();
|
||||
expect(catalog?.characters[0].splashImageUrl).toBe("/media/splash");
|
||||
expect(mocks.reads).not.toContain(catalogMaterials);
|
||||
expect(Object.keys(mocks.selections[0] as object).sort()).toEqual([
|
||||
"key", "name", "rarity", "weaponType", "element", "imageKey", "elementIconKey", "coopImageKey",
|
||||
].sort());
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user