From b1a9c1b458820693171561c84742ac650759eeaa Mon Sep 17 00:00:00 2001 From: Antti Kettunen Date: Thu, 30 Apr 2026 07:59:43 +0300 Subject: [PATCH] Accept wishlist track_data aliases - Let the wishlist service accept both track_data and spotify_track_data - Preserve the backward-compatible wrapper while avoiding the keyword argument crash - Add a regression test for the alias path --- core/wishlist/service.py | 24 ++++++++++++++++++------ tests/wishlist/test_service.py | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/core/wishlist/service.py b/core/wishlist/service.py index bdbee1f2..6dc8c859 100644 --- a/core/wishlist/service.py +++ b/core/wishlist/service.py @@ -94,8 +94,9 @@ class WishlistService: def add_track_to_wishlist( self, - track_data: Dict[str, Any], - failure_reason: str, + track_data: Dict[str, Any] = None, + spotify_track_data: Dict[str, Any] = None, + failure_reason: str = "", source_type: str = "manual", source_context: Dict[str, Any] = None, profile_id: int = 1, @@ -110,8 +111,15 @@ class WishlistService: source_context: Additional context information profile_id: Profile to add to """ + if track_data is None: + track_data = spotify_track_data + + if not track_data: + logger.error("No track data provided for wishlist add") + return False + return self.database.add_to_wishlist( - spotify_track_data=track_data, + track_data=track_data, failure_reason=failure_reason, source_type=source_type, source_info=source_context or {}, @@ -120,15 +128,19 @@ class WishlistService: def add_spotify_track_to_wishlist( self, - spotify_track_data: Dict[str, Any], - failure_reason: str, + spotify_track_data: Dict[str, Any] = None, + track_data: Dict[str, Any] = None, + failure_reason: str = "", source_type: str = "manual", source_context: Dict[str, Any] = None, profile_id: int = 1, ) -> bool: """Backward-compatible wrapper for `add_track_to_wishlist`.""" + if track_data is None: + track_data = spotify_track_data + return self.add_track_to_wishlist( - track_data=spotify_track_data, + track_data=track_data, failure_reason=failure_reason, source_type=source_type, source_context=source_context, diff --git a/tests/wishlist/test_service.py b/tests/wishlist/test_service.py index b9e0b1de..83d4b438 100644 --- a/tests/wishlist/test_service.py +++ b/tests/wishlist/test_service.py @@ -88,6 +88,29 @@ def test_add_failed_track_from_modal_returns_false_when_no_spotify_track_found() assert fake_db.add_calls == [] +def test_add_spotify_track_to_wishlist_accepts_track_data_alias(): + fake_db = _FakeWishlistDatabase() + service = _build_service(fake_db) + + result = service.add_spotify_track_to_wishlist( + track_data={ + "id": "sp-1", + "name": "Song One", + "artists": [{"name": "Artist One"}], + "album": {"name": "Album One"}, + }, + failure_reason="Download failed", + source_type="manual", + profile_id=2, + ) + + assert result is True + assert fake_db.add_calls[0]["track_data"]["id"] == "sp-1" + assert fake_db.add_calls[0]["failure_reason"] == "Download failed" + assert fake_db.add_calls[0]["source_type"] == "manual" + assert fake_db.add_calls[0]["profile_id"] == 2 + + def test_get_wishlist_tracks_for_download_formats_modal_shape(): fake_db = _FakeWishlistDatabase( tracks=[