Skip to content

Commit 03b0adc

Browse files
authored
Tests: Add gist endpoint missing id param test (#3106)
1 parent 93733ca commit 03b0adc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/gist.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import axios from "axios";
44
import MockAdapter from "axios-mock-adapter";
55
import { expect, it, describe, afterEach } from "@jest/globals";
66
import { renderGistCard } from "../src/cards/gist-card.js";
7+
import { renderError } from "../src/common/utils.js";
78
import gist from "../api/gist.js";
89

910
const gist_data = {
@@ -101,4 +102,24 @@ describe("Test /api/gist", () => {
101102
),
102103
);
103104
});
105+
106+
it("should render error if id is not provided", async () => {
107+
const req = {
108+
query: {},
109+
};
110+
const res = {
111+
setHeader: jest.fn(),
112+
send: jest.fn(),
113+
};
114+
115+
await gist(req, res);
116+
117+
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
118+
expect(res.send).toBeCalledWith(
119+
renderError(
120+
'Missing params "id" make sure you pass the parameters in URL',
121+
"/api/gist?id=GIST_ID",
122+
),
123+
);
124+
});
104125
});

0 commit comments

Comments
 (0)