import { describe, it, expect } from "vitest"; import { prisma } from "@/lib/db"; import { GET } from "./route"; async function li(artist: string, album: string, rgMbid: string | null, path = "/m") { return prisma.libraryItem.create({ data: { artist, album, path, source: "scan", format: "FLAC", qualityClass: 2, rgMbid }, }); } describe("library duplicates API", () => { it("groups items sharing a release-group", async () => { await li("Adele", "21", "rg-21"); await li("Adele", "21 (Deluxe)", "rg-21"); // same rg → duplicate await li("Adele", "25", "rg-25"); // unrelated const { duplicates } = await (await GET()).json(); expect(duplicates).toHaveLength(1); expect(duplicates[0].map((d: { album: string }) => d.album).sort()).toEqual(["21", "21 (Deluxe)"]); }); it("groups items with the same edition-normalized title even without a shared rgMbid", async () => { await li("Nirvana", "Nevermind", null); await li("Nirvana", "Nevermind (Deluxe Edition)", "rg-x"); const { duplicates } = await (await GET()).json(); expect(duplicates).toHaveLength(1); expect(duplicates[0]).toHaveLength(2); }); it("returns nothing when there are no duplicates", async () => { await li("A", "One", "rg-1"); await li("B", "Two", "rg-2"); const { duplicates } = await (await GET()).json(); expect(duplicates).toEqual([]); }); });