import { describe, it, expect, vi, beforeEach } from 'vitest'; import { refreshDiscover } from './playlists'; vi.mock('./client', () => ({ apiFetch: vi.fn() })); import { apiFetch } from './client'; describe('refreshDiscover', () => { beforeEach(() => vi.clearAllMocks()); it('POSTs the correct path and returns the response', async () => { const sample = { playlist_id: 'abc-123', track_count: 100 }; (apiFetch as unknown as ReturnType).mockResolvedValueOnce(sample); const got = await refreshDiscover(); expect(apiFetch).toHaveBeenCalledWith( '/api/playlists/system/discover/refresh', expect.objectContaining({ method: 'POST' }) ); expect(got).toEqual(sample); }); it('handles empty-library response', async () => { const sample = { playlist_id: null, track_count: 0 }; (apiFetch as unknown as ReturnType).mockResolvedValueOnce(sample); const got = await refreshDiscover(); expect(got.playlist_id).toBe(null); expect(got.track_count).toBe(0); }); });