File tree 1 file changed +24
-1
lines changed 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import axios from "axios";
4
4
import MockAdapter from "axios-mock-adapter" ;
5
5
import { expect , it , describe , afterEach } from "@jest/globals" ;
6
6
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" ;
8
8
import gist from "../api/gist.js" ;
9
9
10
10
const gist_data = {
@@ -170,4 +170,27 @@ describe("Test /api/gist", () => {
170
170
renderError ( "Something went wrong" , "Language not found" ) ,
171
171
) ;
172
172
} ) ;
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
+ } ) ;
173
196
} ) ;
You can’t perform that action at this time.
0 commit comments