Skip to content

Commit

Permalink
add test for two pages
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPierro committed Oct 8, 2022
1 parent a4b2347 commit 3741157
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/top-langs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,60 @@ const data_langs = {
},
};

const firstPage = {
data: {
user: {
repositories: {
nodes: [
{
languages: {
edges: [{ size: 150, node: { color: "#0f0", name: "HTML" } }],
},
},
{
languages: {
edges: [{ size: 100, node: { color: "#0f0", name: "HTML" } }],
},
},
],
pageInfo: {
hasNextPage: true,
cursor: "cursor",
},
},
},
},
};

const secondPage = {
data: {
user: {
repositories: {
nodes: [
{
languages: {
edges: [
{ size: 100, node: { color: "#0ff", name: "javascript" } },
],
},
},
{
languages: {
edges: [
{ size: 100, node: { color: "#0ff", name: "javascript" } },
],
},
},
],
pageInfo: {
hasNextPage: false,
cursor: "cursor",
},
},
},
},
};

const error = {
errors: [
{
Expand Down Expand Up @@ -94,6 +148,29 @@ describe("Test /api/top-langs", () => {
expect(res.send).toBeCalledWith(renderTopLanguages(langs));
});

it("should test the request with two pages", async () => {
const req = {
query: {
username: "anuraghazra",
},
};
const res = {
setHeader: jest.fn(),
send: jest.fn(),
};

mock
.onPost("https://api.github.com/graphql")
.replyOnce(200, firstPage)
.onPost("https://api.github.com/graphql")
.replyOnce(200, secondPage);

await topLangs(req, res);

expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
expect(res.send).toBeCalledWith(renderTopLanguages(langs));
});

it("should work with the query options", async () => {
const req = {
query: {
Expand Down

0 comments on commit 3741157

Please sign in to comment.