@@ -111,6 +111,53 @@ async def _fetch(after=None):
111111class TestPaginationHTTPIntegration :
112112 """Integration test verifying auto_paging_iter fetches multiple pages via httpx."""
113113
114+ def test_forward_pagination_clears_before (self , workos , httpx_mock ):
115+ httpx_mock .add_response (
116+ json = {"data" : [{"id" : "1" }], "list_metadata" : {"after" : "next" }}
117+ )
118+ httpx_mock .add_response (json = {"data" : [{"id" : "2" }], "list_metadata" : {}})
119+ params = {"before" : "initial" , "limit" : 1 , "organization_id" : "org_1" }
120+ page = workos .request_page ("GET" , ["items" ], model = FakeItem , params = params )
121+ assert [item .id for item in page ] == ["1" , "2" ]
122+ requests = httpx_mock .get_requests ()
123+ assert dict (requests [0 ].url .params ) == {
124+ "before" : "initial" ,
125+ "limit" : "1" ,
126+ "organization_id" : "org_1" ,
127+ }
128+ assert dict (requests [1 ].url .params ) == {
129+ "after" : "next" ,
130+ "limit" : "1" ,
131+ "organization_id" : "org_1" ,
132+ }
133+ assert params == {"before" : "initial" , "limit" : 1 , "organization_id" : "org_1" }
134+
135+ @pytest .mark .asyncio
136+ async def test_async_forward_pagination_clears_before (
137+ self , async_workos , httpx_mock
138+ ):
139+ httpx_mock .add_response (
140+ json = {"data" : [{"id" : "1" }], "list_metadata" : {"after" : "next" }}
141+ )
142+ httpx_mock .add_response (json = {"data" : [{"id" : "2" }], "list_metadata" : {}})
143+ params = {"before" : "initial" , "limit" : 1 , "organization_id" : "org_1" }
144+ page = await async_workos .request_page (
145+ "GET" , ["items" ], model = FakeItem , params = params
146+ )
147+ assert [item .id async for item in page ] == ["1" , "2" ]
148+ requests = httpx_mock .get_requests ()
149+ assert dict (requests [0 ].url .params ) == {
150+ "before" : "initial" ,
151+ "limit" : "1" ,
152+ "organization_id" : "org_1" ,
153+ }
154+ assert dict (requests [1 ].url .params ) == {
155+ "after" : "next" ,
156+ "limit" : "1" ,
157+ "organization_id" : "org_1" ,
158+ }
159+ assert params == {"before" : "initial" , "limit" : 1 , "organization_id" : "org_1" }
160+
114161 def test_auto_paging_iter_fetches_two_pages (self , workos , httpx_mock ):
115162 org_base = {
116163 "object" : "organization" ,
0 commit comments