Skip to content

Commit

Permalink
Tests: Add gist endpoint missing id param test (anuraghazra#3106)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 authored and jacobbexten committed Nov 6, 2024
1 parent 94fa30f commit 3c05f65
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/gist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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",
),
);
});
});

0 comments on commit 3c05f65

Please sign in to comment.