- Supprimer handler wildcard playlists* qui masquait les spécifiques - Réordonner: search et recommendations avant :id (évite id=search/recommendations) - Handlers: GET recommendations, POST :id/share, search avec query empty - list items: ajout title - create: body.title → data.title/name, track_count, like_count - Tests: addTrack(plId,trackId), removeTrack, createShareLink(plId) - Assertions: getRecommendations.playlists, update retourne objet - RAPPORT: cycle 19 Co-authored-by: Cursor <cursoragent@cursor.com>
119 lines
3.5 KiB
TypeScript
119 lines
3.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { playlistService } from './playlistService';
|
|
|
|
describe('playlistService', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('list', () => {
|
|
it('should return list of playlists', async () => {
|
|
const result = await playlistService.list();
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('playlists');
|
|
expect(Array.isArray(result.playlists)).toBe(true);
|
|
expect(result.playlists.length).toBeGreaterThan(0);
|
|
expect(result.playlists[0]).toHaveProperty('id');
|
|
expect(result.playlists[0]).toHaveProperty('title');
|
|
});
|
|
});
|
|
|
|
describe('search', () => {
|
|
it('should search playlists by query', async () => {
|
|
const result = await playlistService.search('Cyberpunk');
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('playlists');
|
|
expect(Array.isArray(result.playlists)).toBe(true);
|
|
});
|
|
|
|
it('should return empty array for no matches', async () => {
|
|
const result = await playlistService.search('NonExistentPlaylist');
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result.playlists).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('get', () => {
|
|
it('should return playlist details', async () => {
|
|
const result = await playlistService.get('1');
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('playlist');
|
|
expect(result.playlist).toHaveProperty('id');
|
|
expect(result.playlist).toHaveProperty('title');
|
|
});
|
|
});
|
|
|
|
describe('create', () => {
|
|
it('should create a new playlist', async () => {
|
|
const newPlaylist = await playlistService.create({
|
|
title: 'Test Playlist',
|
|
is_public: true,
|
|
});
|
|
|
|
expect(newPlaylist).toBeDefined();
|
|
expect(newPlaylist).toHaveProperty('id');
|
|
expect((newPlaylist as { title?: string }).title ?? (newPlaylist as { name?: string }).name).toBe('Test Playlist');
|
|
const pl = newPlaylist as { track_count?: number; like_count?: number };
|
|
expect(pl.track_count ?? 0).toBe(0);
|
|
expect(pl.like_count ?? 0).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('update', () => {
|
|
it('should update a playlist', async () => {
|
|
const result = await playlistService.update('1', {
|
|
title: 'Updated Title',
|
|
});
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('name');
|
|
});
|
|
});
|
|
|
|
describe('delete', () => {
|
|
it('should delete a playlist', async () => {
|
|
const result = await playlistService.delete('1');
|
|
|
|
expect(result).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('addTrack', () => {
|
|
it('should add track to playlist', async () => {
|
|
const result = await playlistService.addTrack('1', 'track-1');
|
|
|
|
expect(result).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('removeTrack', () => {
|
|
it('should remove track from playlist', async () => {
|
|
const result = await playlistService.removeTrack('1', 'track-1');
|
|
|
|
expect(result).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('getRecommendations', () => {
|
|
it('should return playlist recommendations', async () => {
|
|
const result = await playlistService.getRecommendations();
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('playlists');
|
|
expect(Array.isArray(result.playlists)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('createShareLink', () => {
|
|
it('should create a share link', async () => {
|
|
const result = await playlistService.createShareLink('1');
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('share_url');
|
|
});
|
|
});
|
|
});
|