Fix: Remove episodes from missing list on download/rescan

- Update _update_series_in_db to sync missing episodes bidirectionally
- Add delete_by_series_and_episode method to EpisodeService
- Remove downloaded episodes from DB after successful download
- Clear anime service cache when episodes are removed
- Fix tests to use 'message' instead of 'detail' in API responses
- Mock DB operations in rescan tests
This commit is contained in:
2025-12-15 16:17:34 +01:00
parent bf332f27e0
commit 4c9bf6b982
8 changed files with 182 additions and 33 deletions

View File

@@ -201,7 +201,7 @@ class TestFrontendAnimeAPI:
async def test_rescan_anime(self, authenticated_client):
"""Test POST /api/anime/rescan triggers rescan with events."""
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from src.server.services.progress_service import ProgressService
from src.server.utils.dependencies import get_anime_service
@@ -210,7 +210,7 @@ class TestFrontendAnimeAPI:
mock_series_app = MagicMock()
mock_series_app.directory_to_search = "/tmp/test"
mock_series_app.series_list = []
mock_series_app.rescan = AsyncMock()
mock_series_app.rescan = AsyncMock(return_value=[])
mock_series_app.download_status = None
mock_series_app.scan_status = None
@@ -232,7 +232,16 @@ class TestFrontendAnimeAPI:
app.dependency_overrides[get_anime_service] = lambda: anime_service
try:
response = await authenticated_client.post("/api/anime/rescan")
# Mock database operations called during rescan
with patch.object(
anime_service, '_save_scan_results_to_db', new_callable=AsyncMock
):
with patch.object(
anime_service, '_load_series_from_db', new_callable=AsyncMock
):
response = await authenticated_client.post(
"/api/anime/rescan"
)
assert response.status_code == 200
data = response.json()
@@ -448,7 +457,7 @@ class TestFrontendJavaScriptIntegration:
assert response.status_code in [200, 400]
if response.status_code == 400:
# Verify error message indicates empty queue
assert "No pending downloads" in response.json()["detail"]
assert "No pending downloads" in response.json()["message"]
# Test pause - always succeeds even if nothing is processing
response = await authenticated_client.post("/api/queue/pause")