import { describe, it, expect } from "vitest"; import { resolveArtistChoice, type ArtistHit } from "./artist-resolve"; const US: ArtistHit = { mbid: "us", name: "Looking Glass", disambiguation: "70's US pop group" }; const AU: ArtistHit = { mbid: "au", name: "Looking Glass", disambiguation: "Australian stoner rock" }; describe("resolveArtistChoice", () => { it("is ambiguous when 2+ candidates share the exact name", () => { expect(resolveArtistChoice("Looking Glass", [US, AU], "au")).toEqual({ kind: "ambiguous", candidates: [US, AU], }); }); it("uses the single exact-name match even over a disagreeing fallback mbid", () => { const hit: ArtistHit = { mbid: "r", name: "Radiohead", disambiguation: "" }; expect(resolveArtistChoice("Radiohead", [hit], "wrong-lastfm-mbid")).toEqual({ kind: "single", mbid: "r", }); }); it("matches exact name case- and whitespace-insensitively", () => { expect(resolveArtistChoice(" looking GLASS ", [US, AU])).toEqual({ kind: "ambiguous", candidates: [US, AU], }); }); it("falls back to the provided mbid when no candidate name matches exactly", () => { const fuzzy: ArtistHit = { mbid: "x", name: "The Beatles", disambiguation: "" }; expect(resolveArtistChoice("Beatles", [fuzzy], "lastfm-mbid")).toEqual({ kind: "single", mbid: "lastfm-mbid", }); }); it("falls back to MB's top hit when there is no exact match and no fallback", () => { const fuzzy: ArtistHit = { mbid: "top", name: "The Beatles", disambiguation: "" }; expect(resolveArtistChoice("Beatles", [fuzzy])).toEqual({ kind: "single", mbid: "top" }); }); it("is none when there are no candidates and no fallback", () => { expect(resolveArtistChoice("Nobody Here", [])).toEqual({ kind: "none" }); }); });