Skip to content

Commit

Permalink
tests: add gist endpoint proper cache header test (anuraghazra#3152)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 committed Dec 22, 2023
1 parent ea95655 commit dad87f2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/gist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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 { renderError, CONSTANTS } from "../src/common/utils.js";
import gist from "../api/gist.js";

const gist_data = {
Expand Down Expand Up @@ -170,4 +170,27 @@ describe("Test /api/gist", () => {
renderError("Something went wrong", "Language not found"),
);
});

it("should have proper cache", async () => {
const req = {
query: {
id: "bbfce31e0217a3689c8d961a356cb10d",
},
};
const res = {
setHeader: jest.fn(),
send: jest.fn(),
};
mock.onPost("https://api.github.com/graphql").reply(200, gist_data);

await gist(req, res);

expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
expect(res.setHeader).toBeCalledWith(
"Cache-Control",
`max-age=${CONSTANTS.FOUR_HOURS / 2}, s-maxage=${
CONSTANTS.FOUR_HOURS
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
);
});
});

0 comments on commit dad87f2

Please sign in to comment.