/**
 * Tests for the fanart.tv album-cover picker (metadataEnrichmentService.ts:
 * pickFanartAlbumCover).
 *
 * This is the pure parsing step behind the fanart.tv FALLBACK for missing album
 * artwork: given a `/music/albums/{rgid}` response and the requested rgid, it
 * extracts `albums[rgid].albumcover[0].url`, defending against every way that
 * path can be absent. Network/db-free by design — pure function only.
 */ import { describe, it, expect } from "@jest/globals";
import { pickFanartAlbumCover } from "../metadataEnrichmentService.js";
const RGID = "abcd-1234-rg";
describe("pickFanartAlbumCover", ()=>{
    it("returns the cover url from a valid albums map", ()=>{
        const resp = {
            name: "Some Album",
            mbid_id: RGID,
            albums: {
                [RGID]: {
                    albumcover: [
                        {
                            id: "1",
                            url: "https://assets.fanart.tv/fanart/music/cover-front.jpg",
                            likes: "5"
                        },
                        {
                            id: "2",
                            url: "https://assets.fanart.tv/fanart/music/cover-alt.jpg",
                            likes: "1"
                        }
                    ],
                    cdart: [
                        {
                            id: "9",
                            url: "https://assets.fanart.tv/fanart/music/cd.png"
                        }
                    ]
                }
            }
        };
        expect(pickFanartAlbumCover(resp, RGID)).toBe("https://assets.fanart.tv/fanart/music/cover-front.jpg");
    });
    it("returns null when the albums object is missing entirely", ()=>{
        expect(pickFanartAlbumCover({
            name: "x",
            mbid_id: RGID
        }, RGID)).toBeNull();
    });
    it("returns null when the albums map has no entry for the requested rgid", ()=>{
        const resp = {
            albums: {
                "some-other-rgid": {
                    albumcover: [
                        {
                            url: "https://assets.fanart.tv/fanart/music/other.jpg"
                        }
                    ]
                }
            }
        };
        expect(pickFanartAlbumCover(resp, RGID)).toBeNull();
    });
    it("returns null when the albumcover array is empty", ()=>{
        const resp = {
            albums: {
                [RGID]: {
                    albumcover: [],
                    cdart: []
                }
            }
        };
        expect(pickFanartAlbumCover(resp, RGID)).toBeNull();
    });
    it("returns null when albumcover is missing", ()=>{
        const resp = {
            albums: {
                [RGID]: {
                    cdart: [
                        {
                            url: "https://x/cd.png"
                        }
                    ]
                }
            }
        };
        expect(pickFanartAlbumCover(resp, RGID)).toBeNull();
    });
    it("returns null when the first cover url is not a string", ()=>{
        const resp = {
            albums: {
                [RGID]: {
                    albumcover: [
                        {
                            url: 12345
                        }
                    ]
                }
            }
        };
        expect(pickFanartAlbumCover(resp, RGID)).toBeNull();
    });
    it("returns null when the first cover url is an empty string", ()=>{
        const resp = {
            albums: {
                [RGID]: {
                    albumcover: [
                        {
                            url: ""
                        }
                    ]
                }
            }
        };
        expect(pickFanartAlbumCover(resp, RGID)).toBeNull();
    });
    it("returns null for null / undefined / non-object responses", ()=>{
        expect(pickFanartAlbumCover(null, RGID)).toBeNull();
        expect(pickFanartAlbumCover(undefined, RGID)).toBeNull();
        expect(pickFanartAlbumCover("nope", RGID)).toBeNull();
    });
});

//# sourceMappingURL=fanartAlbumArt.test.js.map