Skip to content

Commit 7e4e4c7

Browse files
fix(python): add warning in replace_all_objects for empty objects (generated)
algolia/api-clients-automation#6611 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
1 parent 47d6512 commit 7e4e4c7

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

packages/algoliasearch/__tests__/algoliasearch.common.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, test } from 'vitest';
22

3+
import type { EndRequest, Requester } from '@algolia/client-common';
34
import {
45
DEFAULT_CONNECT_TIMEOUT_BROWSER,
56
DEFAULT_READ_TIMEOUT_BROWSER,
@@ -283,3 +284,44 @@ describe('init', () => {
283284
});
284285
});
285286
});
287+
288+
describe('browseSynonyms', () => {
289+
test('paginates until a non-full page and never re-fetches page 0 (CR-11727)', async () => {
290+
const hitsPerPage = 1000;
291+
const pagesRequested: number[] = [];
292+
293+
const paginatingRequester: Requester = {
294+
send(request: EndRequest) {
295+
const body = (typeof request.data === 'string' ? JSON.parse(request.data) : {}) as { page?: number };
296+
const page = body.page ?? 0;
297+
pagesRequested.push(page);
298+
299+
// Full first page, then a partial page: a correct iterator walks page 0 then page 1 and stops.
300+
const count = page === 0 ? hitsPerPage : 3;
301+
const hits = Array.from({ length: count }, (_, i) => ({ objectID: `page${page}-hit${i}` }));
302+
303+
return Promise.resolve({
304+
content: JSON.stringify({ hits, nbHits: hitsPerPage + 3 }),
305+
isTimedOut: false,
306+
status: 200,
307+
});
308+
},
309+
};
310+
311+
const paginatingClient = algoliasearch('APP_ID', 'API_KEY', { requester: paginatingRequester });
312+
313+
const objectIDs: string[] = [];
314+
await paginatingClient.browseSynonyms({
315+
indexName: 'my-index',
316+
aggregator: (response) => {
317+
for (const hit of response.hits) {
318+
objectIDs.push(hit.objectID);
319+
}
320+
},
321+
});
322+
323+
expect(pagesRequested).toEqual([0, 1]);
324+
expect(objectIDs).toHaveLength(hitsPerPage + 3);
325+
expect(new Set(objectIDs).size).toEqual(hitsPerPage + 3);
326+
});
327+
});

0 commit comments

Comments
 (0)