mirror of
https://github.com/System-End/github-readme-stats.git
synced 2026-04-19 16:38:23 +00:00
tests: add gist endpoint proper cache header test (#3152)
This commit is contained in:
parent
20be43939b
commit
1c91d1ac43
1 changed files with 24 additions and 1 deletions
|
|
@ -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 = {
|
||||
|
|
@ -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}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue