From 3ec8bf53c903ada858303f8539bb0595f841a469 Mon Sep 17 00:00:00 2001 From: Glen Keane Date: Fri, 14 Jul 2023 20:13:19 +0100 Subject: [PATCH] GetPulls iterate all pages when there's a null author PR --- src/interactors/__tests__/getPulls.test.js | 21 +++++++++++++++++++++ src/interactors/getPulls.js | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/interactors/__tests__/getPulls.test.js b/src/interactors/__tests__/getPulls.test.js index 0aaa97c..8e31427 100644 --- a/src/interactors/__tests__/getPulls.test.js +++ b/src/interactors/__tests__/getPulls.test.js @@ -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', + }), + ); + }); }); }); diff --git a/src/interactors/getPulls.js b/src/interactors/getPulls.js index 53ed5d5..9dbbf6b 100644 --- a/src/interactors/getPulls.js +++ b/src/interactors/getPulls.js @@ -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 }));