diff --git a/api/video/wishlist.py b/api/video/wishlist.py index 63c3a002..62a125d3 100644 --- a/api/video/wishlist.py +++ b/api/video/wishlist.py @@ -51,7 +51,16 @@ def register_routes(bp): def video_wishlist_counts(): from . import get_video_db try: - return jsonify({"success": True, **get_video_db().wishlist_counts()}) + db = get_video_db() + counts = db.wishlist_counts() # {movie, show, episode, total(movie+ep)} + yt = db.youtube_wishlist_counts() # {channel, video} (its own table-shape) + counts["video"] = yt.get("video", 0) + counts["channel"] = yt.get("channel", 0) + # The header/sidebar badge is the WHOLE wishlist — movies + episodes + YouTube + # videos — so fold the YouTube count into the total (it was movies+episodes only, + # which is why a YouTube-only wishlist showed no badge). + counts["total"] = counts.get("total", 0) + counts["video"] + return jsonify({"success": True, **counts}) except Exception: logger.exception("Failed to count video wishlist") return jsonify({"success": False, "error": "Failed"}), 500 diff --git a/tests/test_video_wishlist_clear.py b/tests/test_video_wishlist_clear.py index 26f4fbfe..9e03b0f4 100644 --- a/tests/test_video_wishlist_clear.py +++ b/tests/test_video_wishlist_clear.py @@ -60,6 +60,44 @@ def test_clear_empty_tab_is_a_noop(db): assert db.clear_wishlist("movie") == 0 +def test_counts_endpoint_total_includes_youtube_videos(tmp_path): + # regression: the header/sidebar wishlist badge reads this 'total'. It used to be + # movies+episodes only, so a wishlist of only YouTube videos showed NO badge. + from flask import Flask + import api.video as videoapi + db = VideoDatabase(database_path=str(tmp_path / "video_library.db")) + _seed(db) # 2 movies, 2 episodes (1 show), 2 youtube videos + videoapi._video_db = db + app = Flask(__name__) + app.register_blueprint(videoapi.create_video_blueprint(), url_prefix="/api/video") + client = app.test_client() + try: + r = client.get("/api/video/wishlist/counts").get_json() + assert r["success"] + assert r["movie"] == 2 and r["episode"] == 2 and r["video"] == 2 + assert r["total"] == 6 # movies + episodes + YouTube videos (was 4) + finally: + videoapi._video_db = None + + +def test_counts_endpoint_youtube_only_shows_a_total(tmp_path): + # the exact reported case: only YouTube videos wished → badge must still show a number + from flask import Flask + import api.video as videoapi + db = VideoDatabase(database_path=str(tmp_path / "video_library.db")) + db.add_videos_to_wishlist({"youtube_id": "UC1", "title": "Ch"}, + [{"youtube_id": "v1", "title": "A"}, {"youtube_id": "v2", "title": "B"}]) + videoapi._video_db = db + app = Flask(__name__) + app.register_blueprint(videoapi.create_video_blueprint(), url_prefix="/api/video") + client = app.test_client() + try: + r = client.get("/api/video/wishlist/counts").get_json() + assert r["total"] == 2 and r["video"] == 2 and r["movie"] == 0 + finally: + videoapi._video_db = None + + def test_clear_endpoint(tmp_path): from flask import Flask import api.video as videoapi