video wishlist badge: count YouTube videos too (header + sidebar)
bug: the wishlist badge read /wishlist/counts 'total', which was movies+episodes only — YouTube videos (kind='video') are counted by a separate method and were left out. so a wishlist of only youtube videos showed NO number; it only lit up once tv episodes were added. fix: the /wishlist/counts endpoint now folds youtube_wishlist_counts().video into the total (+ exposes video/channel counts). the badge already live-refreshes on wishlist-changed events (which youtube add/remove fire), so it now updates for youtube too. db methods unchanged (their byte-identical contract is intact). regression tests: mixed + youtube-only.
This commit is contained in:
parent
23c64e000a
commit
3fa7b48f4c
2 changed files with 48 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue