@@ -45,6 +45,53 @@ def test_best_ps_id_multiple_ep_returns_first():
4545 assert result .startswith ("EP" )
4646
4747
48+ # --- rep_game title selection ---
49+
50+ @pytest .mark .asyncio
51+ async def test_ascii_title_preferred_over_cyrillic (mocker , common_mocks ):
52+ """ASCII title from a later region should replace a non-ASCII title found first."""
53+ regions = [_region ("uk-ua" ), _region ("en-gb" )]
54+ mocker .patch ("bot.handlers.search.get_user_regions" , new_callable = AsyncMock , return_value = regions )
55+
56+ cyrillic_game = _make_game (EP_ID , title = "Набір FINAL FANTASY VII REMAKE & REBIRTH Twin Pack" )
57+ ascii_game = _make_game (EP_ID , title = "FINAL FANTASY VII REMAKE & REBIRTH Twin Pack" )
58+ mocker .patch ("bot.handlers.search.search_games" , new_callable = AsyncMock ,
59+ side_effect = [[cyrillic_game ], [ascii_game ]])
60+ mocker .patch ("bot.handlers.search.get_game_info" , new_callable = AsyncMock )
61+
62+ state = AsyncMock ()
63+ captured = {}
64+ state .update_data = AsyncMock (side_effect = lambda ** kw : captured .update (kw ))
65+
66+ await _do_search (_make_message (), state , AsyncMock (), "final fantasy" )
67+
68+ entries = captured .get ("entries" , [])
69+ assert len (entries ) == 1
70+ assert entries [0 ]["game" ]["title" ] == "FINAL FANTASY VII REMAKE & REBIRTH Twin Pack"
71+
72+
73+ @pytest .mark .asyncio
74+ async def test_non_ascii_title_kept_when_no_ascii_alternative (mocker , common_mocks ):
75+ """If only non-ASCII title exists (regional exclusive), it should still be shown."""
76+ regions = [_region ("uk-ua" )]
77+ mocker .patch ("bot.handlers.search.get_user_regions" , new_callable = AsyncMock , return_value = regions )
78+
79+ cyrillic_game = _make_game (EP_ID , title = "Набір FINAL FANTASY VII REMAKE & REBIRTH Twin Pack" )
80+ mocker .patch ("bot.handlers.search.search_games" , new_callable = AsyncMock ,
81+ side_effect = [[cyrillic_game ]])
82+ mocker .patch ("bot.handlers.search.get_game_info" , new_callable = AsyncMock )
83+
84+ state = AsyncMock ()
85+ captured = {}
86+ state .update_data = AsyncMock (side_effect = lambda ** kw : captured .update (kw ))
87+
88+ await _do_search (_make_message (), state , AsyncMock (), "final fantasy" )
89+
90+ entries = captured .get ("entries" , [])
91+ assert len (entries ) == 1
92+ assert entries [0 ]["game" ]["title" ] == "Набір FINAL FANTASY VII REMAKE & REBIRTH Twin Pack"
93+
94+
4895# --- fallback helpers ---
4996
5097def _make_game (ps_id , title = "Test Game" , price = 49.99 , currency = "€" ):
@@ -126,8 +173,8 @@ async def test_fallback_not_fired_when_all_regions_found(mocker, common_mocks):
126173
127174
128175@pytest .mark .asyncio
129- async def test_fallback_deduplication (mocker , common_mocks ):
130- """en-gb finds game (EP id); de-de and fr-fr both miss → get_game_info called once, not twice ."""
176+ async def test_fallback_fires_per_region (mocker , common_mocks ):
177+ """en-gb finds game (EP id); de-de and fr-fr both miss → get_game_info called for each missing region ."""
131178 regions = [_region ("en-gb" ), _region ("de-de" ), _region ("fr-fr" )]
132179 mocker .patch ("bot.handlers.search.get_user_regions" , new_callable = AsyncMock , return_value = regions )
133180
@@ -139,8 +186,9 @@ async def test_fallback_deduplication(mocker, common_mocks):
139186
140187 await _do_search (_make_message (), AsyncMock (), AsyncMock (), "test game" )
141188
142- assert mock_get_info .call_count == 1
143- mock_get_info .assert_called_once_with (EP_ID , "de-de" )
189+ assert mock_get_info .call_count == 2
190+ calls = {call .args for call in mock_get_info .call_args_list }
191+ assert calls == {(EP_ID , "de-de" ), (EP_ID , "fr-fr" )}
144192
145193
146194@pytest .mark .asyncio
0 commit comments