diff --git a/test/paginate.test.ts b/test/paginate.test.ts index 3dc34918..83049304 100644 --- a/test/paginate.test.ts +++ b/test/paginate.test.ts @@ -868,4 +868,68 @@ describe("pagination", () => { expect(results[0].state).toEqual("success"); }); }); + + it("Does correctly flatten the response from the 2nd page (octokit/rest.js#1632)", async () => { + const result1 = { + total_count: 2, + workflow_runs: [ + { + id: "123" + } + ] + }; + const result2 = { + total_count: 2, + repository_selection: "all", + workflow_runs: [ + { + id: "456" + } + ] + }; + + const mock = fetchMock + .sandbox() + .get( + `https://api.github.com/repos/octocat/hello-world/actions/runs?per_page=1`, + { + body: result1, + headers: { + link: `; rel="next"`, + "X-GitHub-Media-Type": "github.v3; format=json" + } + } + ) + .get( + `https://api.github.com/repositories/1/actions/runs?per_page=1&page=2`, + { + body: result2, + headers: { + link: `; rel="prev", ; rel="first"`, + "X-GitHub-Media-Type": "github.v3; format=json" + } + } + ); + + const octokit = new TestOctokit({ + request: { + fetch: mock + } + }); + + return octokit + .paginate({ + method: "GET", + url: "/repos/:owner/:repo/actions/runs", + owner: "octocat", + repo: "hello-world", + per_page: 1 + }) + .then(results => { + expect(results).toStrictEqual([ + ...result1.workflow_runs, + ...result2.workflow_runs + ]); + }); + }); });