From 86f8abc021d31fd0e5f860de333969b2aa5a874a Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Wed, 4 Mar 2020 12:08:54 -0800 Subject: [PATCH] test: flatten response from 2nd page --- test/paginate.test.ts | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) 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 + ]); + }); + }); });