tests: return cache tests which were removed in 53e4041 (#4368)

This commit is contained in:
Alexandr Garbuzov authored and GitHub committed 2025-08-24 16:43:02 +03:00
1 parent ff7e1e283c
commit 6b457d04f1
4 files changed
+153 -3

No files matched your search

+24 -1
View File
@@ -4,7 +4,7 @@ import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import topLangs from "../api/top-langs.js";
import { renderTopLanguages } from "../src/cards/top-languages-card.js";
import { renderError } from "../src/common/utils.js";
import { CONSTANTS, renderError } from "../src/common/utils.js";
import { expect, it, describe, afterEach } from "@jest/globals";
const data_langs = {
@@ -208,4 +208,27 @@ describe("Test /api/top-langs", () => {
renderError("Something went wrong", "Locale not found"),
);
});
it("should have proper cache", async () => {
const req = {
query: {
username: "anuraghazra",
},
};
const res = {
setHeader: jest.fn(),
send: jest.fn(),
};
mock.onPost("https://api.github.com/graphql").reply(200, data_langs);
await topLangs(req, res);
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
expect(res.setHeader).toBeCalledWith(
"Cache-Control",
`max-age=${CONSTANTS.TOP_LANGS_CACHE_SECONDS / 2}, s-maxage=${
CONSTANTS.TOP_LANGS_CACHE_SECONDS
}`,
);
});
});