diff options
Diffstat (limited to 'packages/meshbay-node/tests/test_tmdb.py')
| -rw-r--r-- | packages/meshbay-node/tests/test_tmdb.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/packages/meshbay-node/tests/test_tmdb.py b/packages/meshbay-node/tests/test_tmdb.py index fcbc2a2..ab452ce 100644 --- a/packages/meshbay-node/tests/test_tmdb.py +++ b/packages/meshbay-node/tests/test_tmdb.py @@ -40,6 +40,59 @@ async def test_search_movie_returns_top_result_and_confidence(): await client.close() +# ── §10.1/V9: year-exact preference, only when the top hit is weak ────────── + +@pytest.mark.asyncio +async def test_year_exact_result_wins_when_the_top_hit_is_low_confidence(): + # results[0] is TMDB's popularity #1 but a poor textual match for the + # query; results[2] is the exact requested year. + body = {"results": [ + {"id": 1, "title": "Franchise vs. The Doctor", "release_date": "1962-10-05"}, + {"id": 2, "title": "Franchise: Goldfinger", "release_date": "1964-09-17"}, + {"id": 3, "title": "Second Errand", "release_date": "2002-11-20"}, + ]} + client = TmdbClient( + roster=FakeRoster(), + transport=httpx.MockTransport(_handler({"search/movie": body})), + ) + result, _ = await client.search_movie("The Franchise", 2002) + + assert result["id"] == 3 + await client.close() + + +@pytest.mark.asyncio +async def test_year_is_ignored_when_the_top_hit_is_already_confident(): + body = {"results": [ + {"id": 1, "title": "The Franchise", "release_date": "1999-01-01"}, + {"id": 2, "title": "Unrelated", "release_date": "2002-01-01"}, + ]} + client = TmdbClient( + roster=FakeRoster(), + transport=httpx.MockTransport(_handler({"search/movie": body})), + ) + result, ratio = await client.search_movie("The Franchise", 2002) + + assert result["id"] == 1 and ratio > 0.9 + await client.close() + + +@pytest.mark.asyncio +async def test_no_year_match_leaves_the_top_result_in_place(): + body = {"results": [ + {"id": 1, "title": "Something Else Entirely", "release_date": "1990-01-01"}, + {"id": 2, "title": "Also Not It", "release_date": "1991-01-01"}, + ]} + client = TmdbClient( + roster=FakeRoster(), + transport=httpx.MockTransport(_handler({"search/movie": body})), + ) + result, _ = await client.search_movie("The Franchise", 2002) + + assert result["id"] == 1 + await client.close() + + @pytest.mark.asyncio async def test_search_tv_returns_top_result(): body = {"results": [{"id": 7, "name": "Some Show"}]} |