Repository: anuraghazra/github-readme-stats
Pull request #3106 (2023-08-20 03:35:43)

Tests: Add gist endpoint missing id param test

vercel[bot]: [vc]: #TTBSnRnIc9ltJM0iHxYl2YIeifxJUNiyzAhemi14DWg=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJnaXRodWItcmVhZG1lLXN0YXRzIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2dpdGh1Yi1yZWFkbWUtc3RhdHMtdGVhbS9naXRodWItcmVhZG1lLXN0YXRzL0NXaXczWm5TcURtVGVaZ1ZqdzNtR2JxdE1zRzkiLCJwcmV2aWV3VXJsIjoiZ2l0aHViLXJlYWRtZS1zdGF0cy1naXQtZ2lzdGVuZC1hYzkzZTAtZ2l0aHViLXJlYWRtZS1zdGF0cy10ZWFtLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiUEVORElORyJ9XX0=
**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** | 🔄 Building ([Inspect](https://vercel.com/github-readme-stats-team/github-readme-stats/CWiw3ZnSqDmTeZgVjw3mGbqtMsG9)) | [Visit Preview](https://github-readme-stats-git-gistend-ac93e0-github-readme-stats-team.vercel.app) | Aug 20, 2023 3:35am |


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3106?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) Report
Patch coverage has no change and project coverage change: **`+0.05%`** :tada:
> Comparison is base [(`32001d9`)](https://app.codecov.io/gh/anuraghazra/github-readme-stats/commit/32001d9a455d1e467e8ab41a03df33f4499cbade?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) 97.67% compared to head [(`e437bbe`)](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3106?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra) 97.72%.

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


```diff
@@            Coverage Diff             @@
##           master    #3106      +/-   ##
==========================================
+ Coverage   97.67%   97.72%   +0.05%     
==========================================
  Files          27       27              
  Lines        5811     5811              
  Branches      501      505       +4     
==========================================
+ Hits         5676     5679       +3     
+ Misses        133      130       -3     
  Partials        2        2              
```


[see 1 file with indirect coverage changes](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3106/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Anurag+Hazra)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/anuraghazra/github-readme-stats/pull/3106?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/readme.md b/readme.md
index caffaca..ada6af1 100644
--- a/readme.md
+++ b/readme.md
@@ -282,7 +282,7 @@ You can use [GitHub's new media feature](https://github.blog/changelog/2022-05-1
 
 ### Customization
 
-You can customize the appearance of your `Stats Card` or `Repo Card` however you wish with URL parameters.
+You can customize the appearance of all your cards however you wish with URL parameters.
 
 #### Common Options
 
diff --git a/src/fetchers/gist-fetcher.js b/src/fetchers/gist-fetcher.js
index 8e1eb75..9ede43f 100644
--- a/src/fetchers/gist-fetcher.js
+++ b/src/fetchers/gist-fetcher.js
@@ -60,6 +60,7 @@ const fetchGist = async (id) => {
   if (!id) throw new MissingParamError(["id"], "/api/gist?id=GIST_ID");
   const res = await retryer(fetcher, { gistName: id });
   if (res.data.errors) throw new Error(res.data.errors[0].message);
+  if (!res.data.data.viewer.gist) throw new Error("Gist not found");
   const data = res.data.data.viewer.gist;
   return {
     name: data.files[Object.keys(data.files)[0]].name,


Test patch:
diff --git a/tests/fetchGist.test.js b/tests/fetchGist.test.js
index da045b0..13c29a8 100644
--- a/tests/fetchGist.test.js
+++ b/tests/fetchGist.test.js
@@ -25,12 +25,41 @@ const gist_data = {
             },
             size: 85858,
           },
+          {
+            name: "territories.txt",
+            language: {
+              name: "Text",
+            },
+            size: 87858,
+          },
+          {
+            name: "countries_spanish.json",
+            language: {
+              name: "JSON",
+            },
+            size: 85858,
+          },
+          {
+            name: "territories_spanish.txt",
+            language: {
+              name: "Text",
+            },
+            size: 87858,
+          },
         ],
       },
     },
   },
 };
 
+const gist_not_found_data = {
+  data: {
+    viewer: {
+      gist: null,
+    },
+  },
+};
+
 const gist_errors_data = {
   errors: [
     {
@@ -56,12 +85,22 @@ describe("Test fetchGist", () => {
       nameWithOwner: "Yizack/countries.json",
       description:
         "List of countries and territories in English and Spanish: name, continent, capital, dial code, country codes, TLD, and area in sq km. Lista de países y territorios en Inglés y Español: nombre, continente, capital, código de teléfono, códigos de país, dominio y área en km cuadrados. Updated 2023",
-      language: "JSON",
+      language: "Text",
       starsCount: 33,
       forksCount: 11,
     });
   });
 
+  it("should throw correct error if gist not found", async () => {
+    mock
+      .onPost("https://api.github.com/graphql")
+      .reply(200, gist_not_found_data);
+
+    await expect(fetchGist("bbfce31e0217a3689c8d961a356cb10d")).rejects.toThrow(
+      "Gist not found",
+    );
+  });
+
   it("should throw error if reaponse contains them", async () => {
     mock.onPost("https://api.github.com/graphql").reply(200, gist_errors_data);
 
diff --git a/tests/gist.test.js b/tests/gist.test.js
index 985ad6c..a41c44c 100644
--- a/tests/gist.test.js
+++ b/tests/gist.test.js
@@ -4,6 +4,7 @@ import axios from "axios";
 import MockAdapter from "axios-mock-adapter";
 import { expect, it, describe, afterEach } from "@jest/globals";
 import { renderGistCard } from "../src/cards/gist-card.js";
+import { renderError } from "../src/common/utils.js";
 import gist from "../api/gist.js";
 
 const gist_data = {
@@ -101,4 +102,24 @@ describe("Test /api/gist", () => {
       ),
     );
   });
+
+  it("should render error if id is not provided", async () => {
+    const req = {
+      query: {},
+    };
+    const res = {
+      setHeader: jest.fn(),
+      send: jest.fn(),
+    };
+
+    await gist(req, res);
+
+    expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
+    expect(res.send).toBeCalledWith(
+      renderError(
+        'Missing params "id" make sure you pass the parameters in URL',
+        "/api/gist?id=GIST_ID",
+      ),
+    );
+  });
 });