Files
Resonant/src/lib/librarySync.test.ts
T
cyph3rasi 0168767819 Automatically prepare the bundled Navidrome sidecar and replace demo content with real-library scan states and polling
Hop-State: A_06FNEE4FJ502PSGDYQ3272G
Hop-Proposal: R_06FNED6AR1ZZM7CJH7ETC9G
Hop-Task: T_06FNEAPFW0DYEP35V3BMAHG
Hop-Attempt: AT_06FNEAPFW1QY3KAF1QM61N0
2026-07-12 09:45:52 -07:00

28 lines
1.0 KiB
TypeScript

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);
});
});