Files
punktfunk-plugin-rom-manager/plugin/test/steamgriddb.test.ts
enricobuehler 899028e20f feat: Effect services + HttpApi implementation + kit entry/CLI/dev server
- RomConfig/RomCache on the kit's ConfigService/CacheStore; RomSync wires the
  pure domain into the kit SyncEngine (poll/watch/coalesce/fingerprint) and
  ProviderClient; EngineStatus assembly shared by REST + SSE
- makeApi: HttpApiBuilder groups over live service values (handler runtime
  shares the plugin runtime's singletons) + sseRoute status feed
- index.ts: definePluginKit entry (async-main boundary); headless-first (UI
  serve failure logged, engine continues)
- cli.ts on the kit dispatcher: scan/detect/preview offline, sync/uninstall
  online; set-password is gone with the standalone server
- dev.ts: auth-free loopback API server (:5885) — the dev:live proxy target;
  never bundled
- verified live host-less: raw config round-trip on disk, status/platforms/
  preview endpoints, soft-fail reconcile without a host
- CI: workspace install, per-package typecheck, publish from plugin/

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 19:04:25 +02:00

73 lines
2.5 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { SteamGridDbProvider } from "../src/art/steamgriddb.js";
import { platformById } from "../src/domain/platforms.js";
import { parseTitle } from "../src/domain/titles.js";
const snes = platformById("snes")!;
/** A fake SteamGridDB backend keyed by URL path fragments. */
const fakeFetch = (opts: {
status?: number;
games?: unknown[];
grids?: unknown[];
heroes?: unknown[];
logos?: unknown[];
}): typeof fetch =>
((input: string | URL | Request) => {
const url = typeof input === "string" ? input : input.toString();
const path = new URL(url).pathname;
if (opts.status && opts.status !== 200) {
return Promise.resolve(new Response("nope", { status: opts.status }));
}
let data: unknown[] = [];
if (path.includes("/search/autocomplete/")) data = opts.games ?? [];
else if (path.includes("/grids/game/")) data = opts.grids ?? [];
else if (path.includes("/heroes/game/")) data = opts.heroes ?? [];
else if (path.includes("/logos/game/")) data = opts.logos ?? [];
return Promise.resolve(Response.json({ success: true, data }));
}) as typeof fetch;
describe("SteamGridDbProvider", () => {
test("classifies grids into portrait + header and pulls hero + logo", async () => {
const provider = new SteamGridDbProvider(
"key",
fakeFetch({
games: [{ id: 1, name: "Chrono Trigger" }],
grids: [
{ url: "http://p600.png", width: 600, height: 900 },
{ url: "http://h460.png", width: 460, height: 215 },
],
heroes: [{ url: "http://hero.png", width: 1920, height: 620 }],
logos: [{ url: "http://logo.png", width: 400, height: 200 }],
}),
);
const art = await provider.resolve(
snes,
parseTitle("Chrono Trigger (USA)"),
);
expect(art).toEqual({
portrait: "http://p600.png",
header: "http://h460.png",
hero: "http://hero.png",
logo: "http://logo.png",
});
});
test("no game match → null", async () => {
const provider = new SteamGridDbProvider("key", fakeFetch({ games: [] }));
expect(await provider.resolve(snes, parseTitle("Nope"))).toBeNull();
});
test("a bad key (401) disables the provider and returns null", async () => {
const provider = new SteamGridDbProvider("bad", fakeFetch({ status: 401 }));
expect(await provider.resolve(snes, parseTitle("Anything"))).toBeNull();
});
test("the cache id is scoped to the key (so a key change re-resolves)", () => {
const a = new SteamGridDbProvider("k1").id;
const b = new SteamGridDbProvider("k2").id;
expect(a).not.toBe(b);
expect(a.startsWith("steamgriddb:")).toBe(true);
});
});