Files
romm/backend/tests/handler/database/test_collections_handler.py
Spinnich 983f016efe feat(roms): filter games by matched metadata provider
Adds a "Metadata provider" gallery filter so a library can be narrowed by
which providers each ROM matched (IGDB, MobyGames, ScreenScraper, etc.),
mirroring the existing multi-value filters (player count, age rating).

Backend:
- New `_filter_by_metadata_providers` keyed off each provider's id column
  on Rom, with any/all/none logic; wired through filter_roms,
  get_roms_scalar, the /roms endpoint, and the unscoped cache gate.
- Smart collections apply the criterion via get_smart_collection_roms.
- Unknown provider slugs are ignored (no-op) so stale bookmarks or
  hand-edited URLs don't error.

Frontend (v1 + v2):
- Shared METADATA_PROVIDER_OPTIONS registry; provider list is a fixed set
  rather than data-derived, so options are static.
- Wired into the galleryFilter store, rom API service, request cache key,
  both filter drawers, v2 URL persistence, the v2 refetch watcher, and
  smart-collection serialization/summary.
- Added the `platform.metadata-provider` key to all locales.

Tests:
- Backend handler, endpoint, and smart-collection coverage (any/all/none
  plus unknown-slug).
- Frontend smartCollectionCriteria serialization/summary coverage.

Also normalized collections_handler.py to LF (it was the only CRLF file in
the backend, which tripped git-diff-check on the edited lines).

AI assistance: implemented with Claude Code (Anthropic).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 13:52:19 +00:00

45 lines
1.4 KiB
Python

from handler.database import db_collection_handler
from models.collection import SmartCollection
from models.user import User
def test_get_smart_collection_roms_normalizes_legacy_selected_status_lists(
admin_user: User, mocker
):
get_roms_scalar = mocker.patch("handler.database.db_rom_handler.get_roms_scalar")
smart_collection = SmartCollection(
name="Finished games",
description="",
user_id=admin_user.id,
filter_criteria={"selected_status": ["finished", "completed_100"]},
)
db_collection_handler.get_smart_collection_roms(
smart_collection, user_id=admin_user.id
)
assert get_roms_scalar.call_args.kwargs["statuses"] == [
"finished",
"completed_100",
]
def test_get_smart_collection_roms_passes_metadata_providers(admin_user: User, mocker):
get_roms_scalar = mocker.patch("handler.database.db_rom_handler.get_roms_scalar")
smart_collection = SmartCollection(
name="IGDB and Moby matches",
description="",
user_id=admin_user.id,
filter_criteria={
"metadata_providers": ["igdb", "moby"],
"metadata_providers_logic": "all",
},
)
db_collection_handler.get_smart_collection_roms(
smart_collection, user_id=admin_user.id
)
assert get_roms_scalar.call_args.kwargs["metadata_providers"] == ["igdb", "moby"]
assert get_roms_scalar.call_args.kwargs["metadata_providers_logic"] == "all"