From 56b007ff26f5c5a8b6e4481ba726a132c7373d94 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov Date: Wed, 20 Sep 2023 16:29:45 +0300 Subject: [PATCH] tests: add pin endpoint proper cache header test (#3260) --- tests/pin.test.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/pin.test.js b/tests/pin.test.js index dec6a24718a77..0dcb5aa9768fd 100644 --- a/tests/pin.test.js +++ b/tests/pin.test.js @@ -4,7 +4,7 @@ import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import pin from "../api/pin.js"; import { renderRepoCard } from "../src/cards/repo-card.js"; -import { renderError } from "../src/common/utils.js"; +import { renderError, CONSTANTS } from "../src/common/utils.js"; import { expect, it, describe, afterEach } from "@jest/globals"; const data_repo = { @@ -199,4 +199,28 @@ describe("Test /api/pin", () => { ), ); }); + + it("should have proper cache", async () => { + const req = { + query: { + username: "anuraghazra", + repo: "convoychat", + }, + }; + const res = { + setHeader: jest.fn(), + send: jest.fn(), + }; + mock.onPost("https://api.github.com/graphql").reply(200, data_user); + + await pin(req, res); + + expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml"); + expect(res.setHeader).toBeCalledWith( + "Cache-Control", + `max-age=${CONSTANTS.SIX_HOURS / 2}, s-maxage=${ + CONSTANTS.SIX_HOURS + }, stale-while-revalidate=${CONSTANTS.ONE_DAY}`, + ); + }); });