diff --git a/tests/test_graphql_api/test_reservation_unit/test_text_search.py b/tests/test_graphql_api/test_reservation_unit/test_text_search.py index b1dac1b73..3f85d3a8b 100644 --- a/tests/test_graphql_api/test_reservation_unit/test_text_search.py +++ b/tests/test_graphql_api/test_reservation_unit/test_text_search.py @@ -246,3 +246,19 @@ def test_reservation_unit__filter__by_text_search__and_other_filters(graphql): assert response.has_errors is False, response assert len(response.edges) == 1, response assert response.node(0) == {"pk": reservation_unit.pk} + + +def test_reservation_unit__filter__by_text_search__unauthenticated_user(graphql): + # Django translations are inactive during testing, so `get_language_from_request` + # always returns `settings.LANGUAGE_CODE`, see `django.utils.translation.trans_null.get_language_from_request` + + reservation_unit_data = SearchableData(description="Kuvaus") + reservation_unit = ReservationUnitFactory.create(**dataclasses.asdict(reservation_unit_data)) + ReservationUnit.objects.update_search_vectors() + + query = reservation_units_query(text_search="kuvaus") + response = graphql(query) + + assert response.has_errors is False, response + assert len(response.edges) == 1, response + assert response.node(0) == {"pk": reservation_unit.pk} diff --git a/utils/utils.py b/utils/utils.py index 4d313785e..945715e6a 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -122,7 +122,9 @@ def get_text_search_language(request: HttpRequest) -> TextSearchLang: Use preferred language if user is authenticated, otherwise use the language from the request. """ user: AnyUser = request.user - lang_code = user.preferred_language if user.is_authenticated else get_language_from_request(request) + lang_code = ( + user.preferred_language if user.is_authenticated else get_language_from_request(request, check_path=True) + ) return "swedish" if lang_code == "sv" else "english" if lang_code == "en" else "finnish"