mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2024-12-15 06:04:17 +08:00
Top langs card: Remove unreachable code from fetcher and increase tests coverage (#3126)
This commit is contained in:
parent
51fcae838e
commit
0ac5280ba6
@ -75,12 +75,6 @@ const fetchTopLanguages = async (
|
||||
|
||||
const res = await retryer(fetcher, { login: username });
|
||||
|
||||
if (res.data.errors) {
|
||||
logger.error(res.data.errors);
|
||||
throw Error(res.data.errors[0].message || "Could not fetch user");
|
||||
}
|
||||
|
||||
// Catch GraphQL errors.
|
||||
if (res.data.errors) {
|
||||
logger.error(res.data.errors);
|
||||
if (res.data.errors[0].type === "NOT_FOUND") {
|
||||
|
@ -141,11 +141,31 @@ describe("FetchTopLanguages", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw error", async () => {
|
||||
it("should throw specific error when user not found", async () => {
|
||||
mock.onPost("https://api.github.com/graphql").reply(200, error);
|
||||
|
||||
await expect(fetchTopLanguages("anuraghazra")).rejects.toThrow(
|
||||
"Could not resolve to a User with the login of 'noname'.",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw other errors with their message", async () => {
|
||||
mock.onPost("https://api.github.com/graphql").reply(200, {
|
||||
errors: [{ message: "Some test GraphQL error" }],
|
||||
});
|
||||
|
||||
await expect(fetchTopLanguages("anuraghazra")).rejects.toThrow(
|
||||
"Some test GraphQL error",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw error with specific message when error does not contain message property", async () => {
|
||||
mock.onPost("https://api.github.com/graphql").reply(200, {
|
||||
errors: [{ type: "TEST" }],
|
||||
});
|
||||
|
||||
await expect(fetchTopLanguages("anuraghazra")).rejects.toThrow(
|
||||
"Something went while trying to retrieve the language data using the GraphQL API.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -139,7 +139,12 @@ describe("Test /api/top-langs", () => {
|
||||
await topLangs(req, res);
|
||||
|
||||
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
|
||||
expect(res.send).toBeCalledWith(renderError(error.errors[0].message));
|
||||
expect(res.send).toBeCalledWith(
|
||||
renderError(
|
||||
error.errors[0].message,
|
||||
"Make sure the provided username is not an organization",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("should render error card on incorrect layout input", async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user