Tests: Add gist endpoint missing id param test (#3106)

This commit is contained in:
Alexandr Garbuzov
2023-08-20 10:58:48 +03:00
committed by GitHub
parent 93733caaa6
commit 03b0adc8b7
+21
View File
@@ -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",
),
);
});
});