Skip to content

Commit

Permalink
test: flatten response from 2nd page
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Mar 4, 2020
1 parent da61cff commit 86f8abc
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/paginate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<https://api.github.com/repositories/1/actions/runs?per_page=1&page=2>; 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: `<https://api.github.com/repos/octocat/hello-world/actions/runs?per_page=1>; rel="prev", <https://api.github.com/repos/octocat/hello-world/actions/secrets?per_page=1>; 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
]);
});
});
});

0 comments on commit 86f8abc

Please sign in to comment.