From 75d38cc937f9b985e68a33fb6c400057beede2af Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 8 Mar 2026 10:27:01 -0400 Subject: [PATCH] add tests --- .trunk/trunk.yaml | 26 +++++++------- backend/pytest.ini | 2 +- backend/tests/handler/test_db_handler.py | 45 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index b88b1fa0e..9d55ed808 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -7,7 +7,7 @@ cli: plugins: sources: - id: trunk - ref: v1.7.4 + ref: v1.7.5 uri: https://github.com/trunk-io/plugins # Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) runtimes: @@ -24,26 +24,26 @@ lint: enabled: - dotenv-linter@4.0.0 - hadolint@2.14.0 - - markdownlint@0.47.0 - - eslint@9.34.0 - - actionlint@1.7.10 - - bandit@1.9.3 - - black@26.1.0 - - checkov@3.2.500 + - markdownlint@0.48.0 + - eslint@10.0.3 + - actionlint@1.7.11 + - bandit@1.9.4 + - black@26.3.0 + - checkov@3.2.508 - git-diff-check - - isort@7.0.0 + - isort@8.0.1 - mypy@1.19.1 - - osv-scanner@2.3.2 + - osv-scanner@2.3.3 - prettier@3.8.1: packages: - "@trivago/prettier-plugin-sort-imports@6.0.2" - - "@vue/compiler-sfc@3.5.27" - - ruff@0.15.0 + - "@vue/compiler-sfc@3.5.29" + - ruff@0.15.5 - shellcheck@0.11.0 - shfmt@3.6.0 - taplo@0.10.0 - - trivy@0.69.1 - - trufflehog@3.93.1 + - trivy@0.69.3 + - trufflehog@3.93.7 - yamllint@1.38.0 ignore: - linters: [ALL] diff --git a/backend/pytest.ini b/backend/pytest.ini index 98b3089fb..d2d75fb31 100644 --- a/backend/pytest.ini +++ b/backend/pytest.ini @@ -7,7 +7,7 @@ env = DB_NAME=romm_test DB_USER=romm_test DB_PASSWD=passwd - ROMM_DB_DRIVER=mariadb + D:ROMM_DB_DRIVER=mariadb IGDB_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx IGDB_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx RETROACHIEVEMENTS_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/backend/tests/handler/test_db_handler.py b/backend/tests/handler/test_db_handler.py index b35581f93..da30b4fb2 100644 --- a/backend/tests/handler/test_db_handler.py +++ b/backend/tests/handler/test_db_handler.py @@ -180,6 +180,51 @@ def test_filter_by_search_term_with_multiple_terms(platform: Platform): assert actual_rom_ids_single == expected_rom_ids_single +def test_natural_sort_order(platform: Platform): + """Numbers in names should sort numerically, not lexicographically.""" + for name in ["Game 10", "Game 2", "Game 1"]: + db_rom_handler.add_rom( + Rom( + platform_id=platform.id, + name=name, + slug=name.lower().replace(" ", "-"), + fs_name=f"{name}.zip", + fs_name_no_tags=name, + fs_name_no_ext=name, + fs_extension="zip", + fs_path=f"{platform.slug}/roms", + ) + ) + + roms = db_rom_handler.get_roms_scalar( + platform_ids=[platform.id], order_by="name", order_dir="asc" + ) + assert [r.name for r in roms] == ["Game 1", "Game 2", "Game 10"] + + +def test_article_stripping_sort(platform: Platform): + """Leading articles (the, a, an) are stripped when sorting, case-insensitively.""" + for name in ["Zelda", "The Legend", "A Quest"]: + db_rom_handler.add_rom( + Rom( + platform_id=platform.id, + name=name, + slug=name.lower().replace(" ", "-"), + fs_name=f"{name}.zip", + fs_name_no_tags=name, + fs_name_no_ext=name, + fs_extension="zip", + fs_path=f"{platform.slug}/roms", + ) + ) + + roms = db_rom_handler.get_roms_scalar( + platform_ids=[platform.id], order_by="name", order_dir="asc" + ) + # "The Legend" → sorts as "legend", "A Quest" → "quest", "Zelda" → "zelda" + assert [r.name for r in roms] == ["The Legend", "A Quest", "Zelda"] + + def test_users(admin_user): db_user_handler.add_user( User(