fix: prevent duplicate year suffixes in series name and folder creation

Apply the same duplicate-year prevention logic to additional code paths:

- Serie.name_with_year property: skip adding year suffix if name already ends with it
- add_series API endpoint: avoid duplicating year in folder_name_with_year
- Add integration test for Serie.name_with_year idempotency
- Add API test for add_series endpoint year deduplication

Complements the folder_rename_service fix for comprehensive coverage.
This commit is contained in:
2026-05-19 21:25:21 +02:00
parent 75c22fe296
commit 7930e49701
4 changed files with 42 additions and 2 deletions

View File

@@ -271,7 +271,10 @@ class Serie:
'Dororo (2025)'
"""
if self._year:
return f"{self._name} ({self._year})"
year_suffix = f" ({self._year})"
if self._name.endswith(year_suffix):
return self._name
return f"{self._name}{year_suffix}"
return self._name
@property

View File

@@ -730,7 +730,11 @@ async def add_series(
# Create folder name with year if available
if year:
folder_name_with_year = f"{name} ({year})"
year_suffix = f" ({year})"
if name.endswith(year_suffix):
folder_name_with_year = name
else:
folder_name_with_year = f"{name}{year_suffix}"
else:
folder_name_with_year = name

View File

@@ -334,6 +334,25 @@ async def test_add_series_sanitizes_folder_name(authenticated_client):
assert "?" not in folder
@pytest.mark.asyncio
async def test_add_series_does_not_duplicate_year(authenticated_client):
"""Test that add_series doesn't duplicate year when name already contains it."""
response = await authenticated_client.post(
"/api/anime/add",
json={
"link": "https://aniworld.to/anime/stream/eighty-six",
"name": "86 Eighty Six (2021)"
}
)
assert response.status_code == 202
data = response.json()
# Folder should contain year only once
folder = data["folder"]
assert folder.count("(2021)") == 1
@pytest.mark.asyncio
async def test_add_series_returns_missing_episodes(authenticated_client):
"""Test that add_series returns loading progress info."""

View File

@@ -495,6 +495,20 @@ class TestNameWithYearProperty:
assert "(2013)" in sanitized
assert "Attack on Titan" in sanitized
def test_name_with_year_does_not_duplicate(self):
"""Test that name_with_year doesn't duplicate year."""
serie = Serie(
key="eighty-six",
name="86 Eighty Six (2021)",
site="aniworld.to",
folder="86 Eighty Six (2021)",
episodeDict={},
year=2021
)
assert serie.name_with_year == "86 Eighty Six (2021)"
assert serie.name_with_year.count("(2021)") == 1
class TestEnsureFolderWithYear:
"""Test Serie.ensure_folder_with_year method."""