diff --git a/web/src/lib/api/playlists.refresh-discover.test.ts b/web/src/lib/api/playlists.refresh-discover.test.ts index d8ec35a7..98b72e43 100644 --- a/web/src/lib/api/playlists.refresh-discover.test.ts +++ b/web/src/lib/api/playlists.refresh-discover.test.ts @@ -2,28 +2,25 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { refreshDiscover } from './playlists'; vi.mock('./client', () => ({ - apiFetch: vi.fn() + api: { post: vi.fn() } })); -import { apiFetch } from './client'; +import { api } 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); + (api.post as unknown as ReturnType).mockResolvedValueOnce(sample); const got = await refreshDiscover(); - expect(apiFetch).toHaveBeenCalledWith( - '/api/playlists/system/discover/refresh', - expect.objectContaining({ method: 'POST' }) - ); + expect(api.post).toHaveBeenCalledWith('/api/playlists/system/discover/refresh', {}); 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); + (api.post as unknown as ReturnType).mockResolvedValueOnce(sample); const got = await refreshDiscover(); expect(got.playlist_id).toBe(null); expect(got.track_count).toBe(0); diff --git a/web/src/lib/api/playlists.refresh-foryou.test.ts b/web/src/lib/api/playlists.refresh-foryou.test.ts index b4602730..de715232 100644 --- a/web/src/lib/api/playlists.refresh-foryou.test.ts +++ b/web/src/lib/api/playlists.refresh-foryou.test.ts @@ -2,28 +2,25 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { refreshForYou } from './playlists'; vi.mock('./client', () => ({ - apiFetch: vi.fn() + api: { post: vi.fn() } })); -import { apiFetch } from './client'; +import { api } from './client'; describe('refreshForYou', () => { beforeEach(() => vi.clearAllMocks()); it('POSTs the correct path and returns the response', async () => { const sample = { playlist_id: 'pl-abc', track_count: 25, track_ids: ['t1', 't2'] }; - (apiFetch as unknown as ReturnType).mockResolvedValueOnce(sample); + (api.post as unknown as ReturnType).mockResolvedValueOnce(sample); const got = await refreshForYou(); - expect(apiFetch).toHaveBeenCalledWith( - '/api/playlists/system/for-you/refresh', - expect.objectContaining({ method: 'POST' }) - ); + expect(api.post).toHaveBeenCalledWith('/api/playlists/system/for-you/refresh', {}); expect(got).toEqual(sample); }); it('handles empty-library response', async () => { const sample = { playlist_id: null, track_count: 0, track_ids: [] }; - (apiFetch as unknown as ReturnType).mockResolvedValueOnce(sample); + (api.post as unknown as ReturnType).mockResolvedValueOnce(sample); const got = await refreshForYou(); expect(got.playlist_id).toBe(null); expect(got.track_ids).toEqual([]); diff --git a/web/src/lib/api/playlists.test.ts b/web/src/lib/api/playlists.test.ts index 4fe7f464..c2c017f6 100644 --- a/web/src/lib/api/playlists.test.ts +++ b/web/src/lib/api/playlists.test.ts @@ -29,7 +29,8 @@ describe('playlists API helper', () => { expect(r.public).toEqual([]); const call = spy.mock.calls[0]; expect(call[0]).toBe('/api/playlists?kind=user'); - expect((call[1] as RequestInit).method).toBe('GET'); + // GET is fetch's default method; api.get omits init.method entirely. + expect((call[1] as RequestInit | undefined)?.method ?? 'GET').toBe('GET'); }); test('listPlaylists passes kind=system through the query string', async () => {