@@ -39,3 +39,37 @@ async def test_bad_json(self, httpx_mock, monkeypatch):
3939
4040 response = await fulltext .fulltext_search_api ({"q" : "hello" })
4141 assert response == {"error" : "Error converting search engine data to JSON" }
42+
43+ @pytest .mark .asyncio
44+ async def test_pagination_offset_calculation (self , httpx_mock , monkeypatch ):
45+ """Test that page parameter correctly calculates offset for pagination."""
46+ url = "http://mock"
47+ monkeypatch .setattr (
48+ config , "plugin_inside" , {"search_endpoint" : url }, raising = False
49+ )
50+
51+ # Mock a successful response
52+ httpx_mock .add_response (json = {"hits" : {"hits" : []}})
53+
54+ # Test page 1 should have offset 0
55+ await fulltext .fulltext_search_async ("test" , page = 1 , limit = 20 )
56+ request = httpx_mock .get_request ()
57+ assert "from=0" in request .url .query .decode ()
58+
59+ # Reset mock
60+ httpx_mock .reset (False )
61+ httpx_mock .add_response (json = {"hits" : {"hits" : []}})
62+
63+ # Test page 10 should have offset 180 (9 * 20)
64+ await fulltext .fulltext_search_async ("test" , page = 10 , limit = 20 )
65+ request = httpx_mock .get_request ()
66+ assert "from=180" in request .url .query .decode ()
67+
68+ # Reset mock
69+ httpx_mock .reset (False )
70+ httpx_mock .add_response (json = {"hits" : {"hits" : []}})
71+
72+ # Test explicit offset overrides page
73+ await fulltext .fulltext_search_async ("test" , page = 5 , offset = 100 , limit = 20 )
74+ request = httpx_mock .get_request ()
75+ assert "from=100" in request .url .query .decode ()
0 commit comments