import { describe, expect, it, vi } from "vitest"; import { pollForLibrary } from "./librarySync"; describe("pollForLibrary", () => { it("waits until Navidrome returns indexed tracks", async () => { const load = vi.fn() .mockRejectedValueOnce(new Error("server is still starting")) .mockResolvedValueOnce({ tracks: [] }) .mockResolvedValueOnce({ tracks: [] }) .mockResolvedValueOnce({ tracks: [{ id: "real-track" }] }); const wait = vi.fn().mockResolvedValue(undefined); await expect(pollForLibrary(load, { attempts: 5, wait })).resolves.toEqual({ tracks: [{ id: "real-track" }], }); expect(load).toHaveBeenCalledTimes(4); expect(wait).toHaveBeenCalledTimes(3); }); it("returns null when the scan never yields a track", async () => { const load = vi.fn().mockResolvedValue({ tracks: [] }); const wait = vi.fn().mockResolvedValue(undefined); await expect(pollForLibrary(load, { attempts: 3, wait })).resolves.toBeNull(); expect(load).toHaveBeenCalledTimes(3); }); });