From 3c05f650c53aa417ed0615d502c7fe0f9ede895b Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov Date: Sun, 20 Aug 2023 10:58:48 +0300 Subject: [PATCH] Tests: Add gist endpoint missing id param test (#3106) --- tests/gist.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/gist.test.js b/tests/gist.test.js index 985ad6c4d8207..a41c44cbb74c9 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", + ), + ); + }); });