Skip to content

Commit

Permalink
fix(getFiles): add nextPageToken to fields for autoPaginate (#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaareet authored Jan 17, 2025
1 parent 36b882b commit 75c309c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,13 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
callback = queryOrCallback as GetFilesCallback;
}
query = Object.assign({}, query);
if (
query.fields &&
query.autoPaginate &&
!query.fields.includes('nextPageToken')
) {
query.fields = `${query.fields},nextPageToken`;
}

this.request(
{
Expand Down
23 changes: 23 additions & 0 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,29 @@ describe('Bucket', () => {
);
});

it('should add nextPageToken to fields for autoPaginate', done => {
bucket.request = (
reqOpts: DecorateRequestOptions,
callback: Function
) => {
assert.strictEqual(reqOpts.qs.fields, 'items(name),nextPageToken');
callback(null, {
items: [{name: 'fake-file-name'}],
nextPageToken: 'fake-page-token',
});
};

bucket.getFiles(
{fields: 'items(name)', autoPaginate: true},
(err: Error, files: FakeFile[], nextQuery: {pageToken: string}) => {
assert.ifError(err);
assert.strictEqual(files[0].name, 'fake-file-name');
assert.strictEqual(nextQuery.pageToken, 'fake-page-token');
done();
}
);
});

it('should return soft-deleted Files if queried for softDeleted', done => {
const softDeletedTime = new Date('1/1/2024').toISOString();
bucket.request = (
Expand Down

0 comments on commit 75c309c

Please sign in to comment.