import { describe, it, expect, vi, beforeEach } from 'vitest'; vi.mock('./client', () => ({ api: { get: vi.fn(), post: vi.fn(), put: vi.fn(), del: vi.fn() } })); import { refetchAlbumCover, refetchMissingCovers } from './admin'; import { api } from './client'; describe('admin covers API', () => { beforeEach(() => vi.clearAllMocks()); it('refetchAlbumCover POSTs to the correct path', async () => { (api.post as unknown as ReturnType).mockResolvedValueOnce({ album_id: 'a1', cover_art_path: '/x.jpg', cover_art_source: 'mbcaa' }); const got = await refetchAlbumCover('a1'); expect(api.post).toHaveBeenCalledWith('/api/admin/albums/a1/cover/refetch', {}); expect(got.cover_art_source).toBe('mbcaa'); }); it('refetchMissingCovers POSTs to the bulk endpoint', async () => { (api.post as unknown as ReturnType).mockResolvedValueOnce({ queued: 7 }); const got = await refetchMissingCovers(); expect(api.post).toHaveBeenCalledWith('/api/admin/covers/refetch-missing', {}); expect(got.queued).toBe(7); }); });