Skip to content

Commit dad87f2

Browse files
committed
tests: add gist endpoint proper cache header test (anuraghazra#3152)
1 parent ea95655 commit dad87f2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/gist.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +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";
7+
import { renderError, CONSTANTS } from "../src/common/utils.js";
88
import gist from "../api/gist.js";
99

1010
const gist_data = {
@@ -170,4 +170,27 @@ describe("Test /api/gist", () => {
170170
renderError("Something went wrong", "Language not found"),
171171
);
172172
});
173+
174+
it("should have proper cache", async () => {
175+
const req = {
176+
query: {
177+
id: "bbfce31e0217a3689c8d961a356cb10d",
178+
},
179+
};
180+
const res = {
181+
setHeader: jest.fn(),
182+
send: jest.fn(),
183+
};
184+
mock.onPost("https://api.github.com/graphql").reply(200, gist_data);
185+
186+
await gist(req, res);
187+
188+
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
189+
expect(res.setHeader).toBeCalledWith(
190+
"Cache-Control",
191+
`max-age=${CONSTANTS.FOUR_HOURS / 2}, s-maxage=${
192+
CONSTANTS.FOUR_HOURS
193+
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
194+
);
195+
});
173196
});

0 commit comments

Comments
 (0)