Repository: anuraghazra/github-readme-stats
Pull request #3111 (2023-08-21 01:40:25)

Tests: Reduce size of Wakatime fetcher test

vercel[bot]: [vc]: #TaAuGfhbYtLTBJeAduzitY7zlw3G0Q8AVWsg1QjcgHQ=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJnaXRodWItcmVhZG1lLXN0YXRzIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2dpdGh1Yi1yZWFkbWUtc3RhdHMtdGVhbS9naXRodWItcmVhZG1lLXN0YXRzLzk1dDN2ckFYSmdGN2F6Sm5tS3hUMlN3WlVQWDIiLCJwcmV2aWV3VXJsIjoiZ2l0aHViLXJlYWRtZS1zdGF0cy1naXQtcmVkdWNlcy02MGU3YzktZ2l0aHViLXJlYWRtZS1zdGF0cy10ZWFtLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifV19
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------ |
| **github-readme-stats** | ✅ Ready ([Inspect](https://vercel.com/github-readme-stats-team/github-readme-stats/95t3vrAXJgF7azJnmKxT2SwZUPX2)) | [Visit Preview](https://github-readme-stats-git-reduces-60e7c9-github-readme-stats-team.vercel.app) | Aug 21, 2023 1:40am |


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3111?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) Report
Patch and project coverage have no change.
> Comparison is base [(`03b0adc`)](https://app.codecov.io/gh/anuraghazra/github-readme-stats/commit/03b0adc8b73904efc8c4600a7330b6c2803b78f8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) 97.78% compared to head [(`66da95c`)](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3111?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) 97.78%.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #3111   +/-   ##
=======================================
  Coverage   97.78%   97.78%           
=======================================
  Files          27       27           
  Lines        5812     5812           
  Branches      508      508           
=======================================
  Hits         5683     5683           
  Misses        127      127           
  Partials        2        2           
```




</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3111?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra).


Patch:
diff --git a/.github/labeler.yml b/.github/labeler.yml
index 9708a97..c8da8cf 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -17,18 +17,21 @@ lang-card:
   - src/fetchers/top-languages-fetcher.js
   - tests/fetchTopLanguages.test.js
   - tests/renderTopLanguagesCard.test.js
+  - tests/top-langs.test.js
 repo-card:
   - api/pin.js
   - src/cards/repo-card.js
   - src/fetchers/repo-fetcher.js
   - tests/fetchRepo.test.js
   - tests/renderRepoCard.test.js
+  - tests/pin.test.js
 stats-card:
   - api/index.js
   - src/cards/stats-card.js
   - src/fetchers/stats-fetcher.js
   - tests/fetchStats.test.js
   - tests/renderStatsCard.test.js
+  - tests/api.test.js
 wakatime-card:
   - api/wakatime.js
   - src/cards/wakatime-card.js
@@ -41,6 +44,7 @@ gist-card:
   - src/fetchers/gist-fetcher.js
   - tests/fetchGist.test.js
   - tests/renderGistCard.test.js
+  - tests/gist.test.js
 ranks: src/calculateRank.js
 ci:
   - .github/workflows/*
diff --git a/src/fetchers/top-languages-fetcher.js b/src/fetchers/top-languages-fetcher.js
index 1f386c1..26e99e6 100644
--- a/src/fetchers/top-languages-fetcher.js
+++ b/src/fetchers/top-languages-fetcher.js
@@ -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") {


Test patch:
diff --git a/tests/fetchTopLanguages.test.js b/tests/fetchTopLanguages.test.js
index 9a48a16..90648c3 100644
--- a/tests/fetchTopLanguages.test.js
+++ b/tests/fetchTopLanguages.test.js
@@ -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.",
+    );
+  });
 });
diff --git a/tests/fetchWakatime.test.js b/tests/fetchWakatime.test.js
index fb33734..1636114 100644
--- a/tests/fetchWakatime.test.js
+++ b/tests/fetchWakatime.test.js
@@ -112,97 +112,7 @@ describe("Wakatime fetcher", () => {
       .reply(200, wakaTimeData);
 
     const repo = await fetchWakatimeStats({ username });
-    expect(repo).toMatchInlineSnapshot(`
-      {
-        "categories": [
-          {
-            "digital": "22:40",
-            "hours": 22,
-            "minutes": 40,
-            "name": "Coding",
-            "percent": 100,
-            "text": "22 hrs 40 mins",
-            "total_seconds": 81643.570077,
-          },
-        ],
-        "daily_average": 16095,
-        "daily_average_including_other_language": 16329,
-        "days_including_holidays": 7,
-        "days_minus_holidays": 5,
-        "editors": [
-          {
-            "digital": "22:40",
-            "hours": 22,
-            "minutes": 40,
-            "name": "VS Code",
-            "percent": 100,
-            "text": "22 hrs 40 mins",
-            "total_seconds": 81643.570077,
-          },
-        ],
-        "holidays": 2,
-        "human_readable_daily_average": "4 hrs 28 mins",
-        "human_readable_daily_average_including_other_language": "4 hrs 32 mins",
-        "human_readable_total": "22 hrs 21 mins",
-        "human_readable_total_including_other_language": "22 hrs 40 mins",
-        "id": "random hash",
-        "is_already_updating": false,
-        "is_coding_activity_visible": true,
-        "is_including_today": false,
-        "is_other_usage_visible": true,
-        "is_stuck": false,
-        "is_up_to_date": true,
-        "languages": [
-          {
-            "digital": "0:19",
-            "hours": 0,
-            "minutes": 19,
-            "name": "Other",
-            "percent": 1.43,
-            "text": "19 mins",
-            "total_seconds": 1170.434361,
-          },
-          {
-            "digital": "0:01",
-            "hours": 0,
-            "minutes": 1,
-            "name": "TypeScript",
-            "percent": 0.1,
-            "text": "1 min",
-            "total_seconds": 83.293809,
-          },
-          {
-            "digital": "0:00",
-            "hours": 0,
-            "minutes": 0,
-            "name": "YAML",
-            "percent": 0.07,
-            "text": "0 secs",
-            "total_seconds": 54.975151,
-          },
-        ],
-        "operating_systems": [
-          {
-            "digital": "22:40",
-            "hours": 22,
-            "minutes": 40,
-            "name": "Mac",
-            "percent": 100,
-            "text": "22 hrs 40 mins",
-            "total_seconds": 81643.570077,
-          },
-        ],
-        "percent_calculated": 100,
-        "range": "last_7_days",
-        "status": "ok",
-        "timeout": 15,
-        "total_seconds": 80473.135716,
-        "total_seconds_including_other_language": 81643.570077,
-        "user_id": "random hash",
-        "username": "anuraghazra",
-        "writes_only": false,
-      }
-    `);
+    expect(repo).toStrictEqual(wakaTimeData.data);
   });
 
   it("should throw error if username param missing", async () => {
diff --git a/tests/top-langs.test.js b/tests/top-langs.test.js
index f0ce0b5..3f4e594 100644
--- a/tests/top-langs.test.js
+++ b/tests/top-langs.test.js
@@ -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 () => {