import { describe, it, expect } from "vitest"; import { prisma } from "@/lib/db"; import { GET } from "./route"; describe("library API", () => { it("lists owned albums enriched with rgMbid + year from the matching release", async () => { await prisma.monitoredRelease.create({ data: { artistMbid: "a1", artistName: "Radiohead", rgMbid: "rg-inrainbows", album: "In Rainbows", primaryType: "Album", firstReleaseDate: "2007-10-10", monitored: true, state: "fulfilled", }, }); await prisma.libraryItem.create({ data: { artist: "Radiohead", album: "In Rainbows", path: "/m", source: "qobuz", format: "FLAC", qualityClass: 3 }, }); await prisma.libraryItem.create({ data: { artist: "Unknown", album: "Bootleg", path: "/m", source: "scan", format: "MP3", qualityClass: 1 }, }); const res = await GET(); expect(res.status).toBe(200); const { albums } = await res.json(); expect(albums).toHaveLength(2); const inr = albums.find((a: { album: string }) => a.album === "In Rainbows"); expect(inr).toMatchObject({ artist: "Radiohead", rgMbid: "rg-inrainbows", year: "2007", format: "FLAC", qualityClass: 3 }); const boot = albums.find((a: { album: string }) => a.album === "Bootleg"); expect(boot).toMatchObject({ rgMbid: null, year: null }); // no matching release → no art/tracks }); });