From 6d5a8285429b2b4e4f6ba00d9a5a5d8bb49b4d72 Mon Sep 17 00:00:00 2001 From: anuraghazra Date: Sat, 25 Jul 2020 13:29:32 +0530 Subject: [PATCH] chore: added secondary warning message in renderError --- api/index.js | 7 ++++++- src/utils.js | 10 +++++++--- tests/api.test.js | 7 ++++++- tests/utils.test.js | 19 ++++++++++++++++--- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/api/index.js b/api/index.js index 6d18aa6..a17387c 100644 --- a/api/index.js +++ b/api/index.js @@ -33,7 +33,12 @@ module.exports = async (req, res) => { try { stats = await fetchStats(username, parseBoolean(count_private)); } catch (err) { - return res.send(renderError(err.message)); + return res.send( + renderError( + err.message, + "Make sure the provided username is not an organization" + ) + ); } const cacheSeconds = clampValue( diff --git a/src/utils.js b/src/utils.js index 7cb183e..31689cc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,16 +1,20 @@ const axios = require("axios"); const themes = require("../themes"); -const renderError = (message) => { +const renderError = (message, secondaryMessage = "") => { return ` - + Something went wrong! file an issue at https://git.io/JJmN9 - ${message} + + ${message} + ${secondaryMessage} + `; }; diff --git a/tests/api.test.js b/tests/api.test.js index 8c79e70..4811128 100644 --- a/tests/api.test.js +++ b/tests/api.test.js @@ -94,7 +94,12 @@ describe("Test /api/", () => { await api(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 get the query options", async () => { diff --git a/tests/utils.test.js b/tests/utils.test.js index 765fd09..5a6445d 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,3 +1,4 @@ +require("@testing-library/jest-dom"); const { kFormatter, encodeHTML, @@ -6,6 +7,8 @@ const { getCardColors, } = require("../src/utils"); +const { queryByTestId } = require("@testing-library/dom"); + describe("Test utils.js", () => { it("should test kFormatter", () => { expect(kFormatter(1)).toBe(1); @@ -25,9 +28,19 @@ describe("Test utils.js", () => { it("should test renderError", () => { document.body.innerHTML = renderError("Something went wrong"); - expect(document.getElementById("message").textContent).toBe( - "Something went wrong" + expect( + queryByTestId(document.body, "message").children[0] + ).toHaveTextContent(/Something went wrong/gim); + expect(queryByTestId(document.body, "message").children[1]).toBeEmpty(2); + + // Secondary message + document.body.innerHTML = renderError( + "Something went wrong", + "Secondary Message" ); + expect( + queryByTestId(document.body, "message").children[1] + ).toHaveTextContent(/Secondary Message/gim); }); it("should test FlexLayout", () => { @@ -82,7 +95,7 @@ describe("Test utils.js", () => { bgColor: "#fff", }); }); - + it("getCardColors: should fallback to specified theme colors if is not defined", () => { let colors = getCardColors({ theme: "dark",