import { describe, expect, it } from "vitest"; import { buildLinks, mergePeople, mergePlatforms, selectScreenshots } from "@/lib/game/game-profile"; import type { IgdbGame } from "@/lib/game/game-profile-types"; describe("mergePeople", () => { it("prefers IGDB companies when present", () => { const igdb = { involved_companies: [ { developer: true, company: { name: "Dev Studio" } }, { publisher: true, company: { name: "Pub Inc" } }, ], } as IgdbGame; const { developers, publishers } = mergePeople(igdb, null, null); expect(developers).toEqual(["Dev Studio"]); expect(publishers).toEqual(["Pub Inc"]); }); it("falls back to Steam and ITAD lists", () => { const steam = { developers: ["Valve"], publishers: ["Valve"] }; const { developers, publishers } = mergePeople(null, steam, null); expect(developers).toEqual(["Valve"]); expect(publishers).toEqual(["Valve"]); }); it("returns empty lists without sources", () => { expect(mergePeople(null, null, null)).toEqual({ developers: [], publishers: [] }); }); }); describe("mergePlatforms", () => { it("normalizes IGDB platform names", () => { const igdb = { platforms: [{ name: "PC (Microsoft Windows)" }, { name: "Mac" }, { name: "Switch" }], } as IgdbGame; expect(mergePlatforms(igdb, null, undefined)).toEqual(["Windows", "MacOS", "Switch"]); }); it("merges IGDB, Steam, and SKU platforms without early exit", () => { const igdb = { platforms: [{ name: "Switch" }] } as IgdbGame; const steam = { platforms: { windows: true, mac: false, linux: false } }; const entry = { id: "g", name: "G", third_party_skus: [{ distributor: "xbox", id: "1" }] }; expect(mergePlatforms(igdb, steam, entry)).toEqual(["Switch", "Windows", "Xbox"]); }); it("still resolves SKUs when Steam data is missing", () => { const entry = { id: "g", name: "G", third_party_skus: [{ distributor: "playstation", id: "1" }], }; expect(mergePlatforms(null, null, entry)).toEqual(["PlayStation"]); }); }); describe("buildLinks", () => { it("labels known categories and dedupes", () => { const igdb = { websites: [ { url: "https://store.steampowered.com/app/1", category: 13 }, { url: "https://store.steampowered.com/app/1", category: 13 }, { url: "example.com", category: 99 }, ], } as IgdbGame; const links = buildLinks(igdb); expect(links).toHaveLength(2); expect(links[0]).toEqual({ label: "Steam", url: "https://store.steampowered.com/app/1", }); expect(links[1].label).toBe("example.com"); }); it("returns no links without websites", () => { expect(buildLinks(null)).toEqual([]); }); }); describe("selectScreenshots", () => { it("prefers IGDB shots and caps at 8", () => { const igdb = { screenshots: Array.from({ length: 10 }, (_, i) => ({ url: `//images.igdb.com/t_thumb/${i}.jpg`, })), } as IgdbGame; const shots = selectScreenshots(igdb, null); expect(shots).toHaveLength(8); expect(shots[0]).toContain("t_screenshot_big"); }); it("falls back to Steam shots", () => { const steam = { screenshots: [{ path_full: "https://cdn/shot.jpg" }] }; expect(selectScreenshots(null, steam)).toEqual(["https://cdn/shot.jpg"]); }); });