Skip to content

Commit

Permalink
GetPulls iterate all pages when there's a null author PR
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenTiki authored and manuelmhtr committed Jul 22, 2023
1 parent 008e1ea commit 3ec8bf5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/interactors/__tests__/getPulls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,26 @@ describe('Interactors | .getPulls', () => {
}),
);
});


it('calls fetcher the expected amount of times when there are null pr author items', async () => {
const itemsPerPage = 3;

const nullAuthorResponse = buildResponse(itemsPerPage);
nullAuthorResponse.search.edges[0].node.author = null;

fetchPullRequests
.mockReturnValueOnce(nullAuthorResponse)
.mockReturnValueOnce(buildResponse(1));

await getPulls({ ...input, itemsPerPage });
expect(parsePullRequest).toBeCalledTimes(itemsPerPage + 1);
expect(fetchPullRequests).toBeCalledTimes(2);
expect(fetchPullRequests).toHaveBeenLastCalledWith(
expect.objectContaining({
after: 'CURSOR',
}),
);
});
});
});
2 changes: 1 addition & 1 deletion src/interactors/getPulls.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getPullRequests = async (params) => {
.filter(filterNullAuthor)
.map(parsePullRequest);

if (results.length < limit) return results;
if (data.search.edges.length < limit) return results;

const last = results[results.length - 1].cursor;
return results.concat(await getPullRequests({ ...params, after: last }));
Expand Down

0 comments on commit 3ec8bf5

Please sign in to comment.