Skip to content

Commit

Permalink
Add a failing pagination test
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed May 3, 2020
1 parent 157e02b commit e23b7f9
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,53 @@ test('next url in json response', withServer, async (t, server, got) => {
'/?page=3'
]);
});

test.failing('pagiantion using searchParams', withServer, async (t, server, got) => {
server.get('/', (request, response) => {
const parameters = new URLSearchParams(request.url.slice(2));
const page = Number(parameters.get('page') ?? 0);

response.end(JSON.stringify({
currentUrl: request.url,
next: page < 3
}));
});

interface Page {
currentUrl: string;
next?: string;
}

const all = await got.paginate.all('', {
searchParams: {
page: 0
},
responseType: 'json',
pagination: {
transform: (response: Response<Page>) => {
return [response.body.currentUrl];
},
paginate: (response: Response<Page>) => {
const {next} = response.body;
const previousPage = Number(response.request.options.searchParams!.get('page'));

if (!next) {
return false;
}

return {
searchParams: {
page: previousPage + 1
}
};
}
}
});

t.deepEqual(all, [
'/?page=0',
'/?page=1',
'/?page=2',
'/?page=3'
]);
});

4 comments on commit e23b7f9

@fiznool
Copy link
Contributor

@fiznool fiznool commented on e23b7f9 May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szmarczak is there an issue tracking this failure? I've just come across it again today but on searching the issue tracker couldn't find anything specifically pointing to this.

@szmarczak
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see one. /cc @PopGoesTheWza

@PopGoesTheWza
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None open AFAIK. When Got@11 is stable enough with SugarAPI, I'll use it with some other api which have use for searchParams

@fiznool
Copy link
Contributor

@fiznool fiznool commented on e23b7f9 May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I proposed a fix with #1229.

Please sign in to comment.