diff --git a/tests/gist.test.js b/tests/gist.test.js index a41c44c..b7c3484 100644 --- a/tests/gist.test.js +++ b/tests/gist.test.js @@ -34,6 +34,14 @@ const gist_data = { }, }; +const gist_not_found_data = { + data: { + viewer: { + gist: null, + }, + }, +}; + const mock = new MockAdapter(axios); afterEach(() => { @@ -122,4 +130,24 @@ describe("Test /api/gist", () => { ), ); }); + + it("should render error if gist is not found", async () => { + const req = { + query: { + id: "bbfce31e0217a3689c8d961a356cb10d", + }, + }; + const res = { + setHeader: jest.fn(), + send: jest.fn(), + }; + mock + .onPost("https://api.github.com/graphql") + .reply(200, gist_not_found_data); + + await gist(req, res); + + expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml"); + expect(res.send).toBeCalledWith(renderError("Gist not found")); + }); });