feat(web): API client for /api/discover/suggestions
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
vi.mock('./client', () => ({
|
||||
api: { get: vi.fn() }
|
||||
}));
|
||||
|
||||
import { listSuggestions } from './suggestions';
|
||||
import { qk } from './queries';
|
||||
import { api } from './client';
|
||||
import type { ArtistSuggestion } from './types';
|
||||
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
|
||||
describe('suggestions client', () => {
|
||||
test('listSuggestions hits the right URL with default limit', async () => {
|
||||
const fixture: ArtistSuggestion[] = [
|
||||
{
|
||||
mbid: 'm1',
|
||||
name: 'Outsider',
|
||||
score: 1.5,
|
||||
attribution: [
|
||||
{ artist_id: 'a1', name: 'Seed', contribution: 0.9, is_liked: true, play_count: 0 }
|
||||
]
|
||||
}
|
||||
];
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce(fixture);
|
||||
const got = await listSuggestions();
|
||||
expect(api.get).toHaveBeenCalledWith('/api/discover/suggestions?limit=12');
|
||||
expect(got).toEqual(fixture);
|
||||
});
|
||||
|
||||
test('listSuggestions honors a custom limit', async () => {
|
||||
(api.get as ReturnType<typeof vi.fn>).mockResolvedValueOnce([]);
|
||||
await listSuggestions(20);
|
||||
expect(api.get).toHaveBeenCalledWith('/api/discover/suggestions?limit=20');
|
||||
});
|
||||
|
||||
test('qk.suggestions key shape', () => {
|
||||
expect(qk.suggestions()).toEqual(['suggestions', { limit: 12 }]);
|
||||
expect(qk.suggestions(20)).toEqual(['suggestions', { limit: 20 }]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user