refactor: Update playlist service and endpoints for global current playlist management

This commit is contained in:
JSC
2025-08-01 16:58:25 +02:00
parent 3132175354
commit c0f51b2e23
4 changed files with 63 additions and 30 deletions

View File

@@ -358,14 +358,14 @@ class TestPlaylistEndpoints:
assert data["genre"] == "jazz"
@pytest.mark.asyncio
async def test_update_playlist_set_current(
async def test_update_playlist_basic_fields(
self,
authenticated_client: AsyncClient,
test_session: AsyncSession,
test_user: User,
) -> None:
"""Test PUT /api/v1/playlists/{id} - set playlist as current."""
# Create test playlists within this test
"""Test PUT /api/v1/playlists/{id} - update basic fields only."""
# Create test playlist
user_id = test_user.id
test_playlist = Playlist(
user_id=user_id,
@@ -377,25 +377,13 @@ class TestPlaylistEndpoints:
is_deletable=True,
)
test_session.add(test_playlist)
# Note: main_playlist doesn't need to be current=True for this test
# The service logic handles current playlist management
main_playlist = Playlist(
user_id=None,
name="Main Playlist",
description="Main playlist",
is_main=True,
is_current=False,
is_deletable=False,
)
test_session.add(main_playlist)
await test_session.commit()
await test_session.refresh(test_playlist)
# Extract ID before HTTP request
playlist_id = test_playlist.id
payload = {"is_current": True}
payload = {"name": "Updated Playlist", "description": "Updated description"}
response = await authenticated_client.put(
f"/api/v1/playlists/{playlist_id}", json=payload,
@@ -403,7 +391,10 @@ class TestPlaylistEndpoints:
assert response.status_code == 200
data = response.json()
assert data["is_current"] is True
assert data["name"] == "Updated Playlist"
assert data["description"] == "Updated description"
# is_current should remain unchanged (not handled by this endpoint)
assert data["is_current"] is False
@pytest.mark.asyncio
async def test_delete_playlist_success(