Skip to content

Commit

Permalink
fix(storage): nextToken is not surfaced when list result contain only…
Browse files Browse the repository at this point in the history
… CommonPrefix
  • Loading branch information
HuiSF committed Oct 17, 2024
1 parent 971bec4 commit 6de4423
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/storage/__tests__/providers/s3/apis/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,47 @@ describe('list API', () => {
},
);

it.each(pathTestCases)(
'should list objects with CommonPrefix and nextToken in results with custom path: $path',
async ({ path }) => {
mockListObject.mockImplementationOnce(() => {
return {
CommonPrefixes: [
{ Prefix: 'photos/2023/' },
{ Prefix: 'photos/2024/' },
{ Prefix: 'photos/2025/' },
{ Prefix: 'photos/2026/' },
{ Prefix: 'photos/2027/' },
{ Prefix: 'photos/time-traveling/' },
],
NextContinuationToken: 'yup_there_is_more',
};
});
const response = await listPaginatedWrapper({
path: resolvePath(path),
});
expect(response.excludedSubpaths).toEqual([
'photos/2023/',
'photos/2024/',
'photos/2025/',
'photos/2026/',
'photos/2027/',
'photos/time-traveling/',
]);

expect(response.nextToken).toEqual('yup_there_is_more');
expect(listObjectsV2).toHaveBeenCalledTimes(1);
await expect(listObjectsV2).toBeLastCalledWithConfigAndInput(
listObjectClientConfig,
{
Bucket: bucket,
MaxKeys: 1000,
Prefix: resolvePath(path),
},
);
},
);

it.each(pathTestCases)(
'should list all objects having three pages with custom path: $path',
async ({ path: inputPath }) => {
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/s3/apis/internal/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const _listWithPath = async ({
if (!contents) {
return {
items: [],
nextToken: nextContinuationToken,
excludedSubpaths,
};
}
Expand Down

0 comments on commit 6de4423

Please sign in to comment.