@@ -168,6 +168,40 @@ describe("Test /api/", () => {
168168 ) ;
169169 } ) ;
170170
171+ it ( "should have proper cache" , async ( ) => {
172+ const { req, res } = faker ( { } , data_stats ) ;
173+
174+ await api ( req , res ) ;
175+
176+ expect ( res . setHeader . mock . calls ) . toEqual ( [
177+ [ "Content-Type" , "image/svg+xml" ] ,
178+ [
179+ "Cache-Control" ,
180+ `max-age=${ CONSTANTS . CARD_CACHE_SECONDS } , s-maxage=${
181+ CONSTANTS . CARD_CACHE_SECONDS
182+ } , stale-while-revalidate=${ CONSTANTS . ONE_DAY } `,
183+ ] ,
184+ ] ) ;
185+ } ) ;
186+
187+ it ( "should set proper cache" , async ( ) => {
188+ const cache_seconds = CONSTANTS . TWELVE_HOURS ;
189+ const { req, res } = faker ( { cache_seconds } , data_stats ) ;
190+ await api ( req , res ) ;
191+
192+ expect ( res . setHeader . mock . calls ) . toEqual ( [
193+ [ "Content-Type" , "image/svg+xml" ] ,
194+ [
195+ "Cache-Control" ,
196+ `max-age=${
197+ cache_seconds
198+ } , s-maxage=${ cache_seconds } , stale-while-revalidate=${
199+ CONSTANTS . ONE_DAY
200+ } `,
201+ ] ,
202+ ] ) ;
203+ } ) ;
204+
171205 it ( "should set shorter cache when error" , async ( ) => {
172206 const { req, res } = faker ( { } , error ) ;
173207 await api ( req , res ) ;
@@ -183,6 +217,54 @@ describe("Test /api/", () => {
183217 ] ) ;
184218 } ) ;
185219
220+ it ( "should set proper cache with clamped values" , async ( ) => {
221+ {
222+ let { req, res } = faker ( { cache_seconds : 200000 } , data_stats ) ;
223+ await api ( req , res ) ;
224+
225+ expect ( res . setHeader . mock . calls ) . toEqual ( [
226+ [ "Content-Type" , "image/svg+xml" ] ,
227+ [
228+ "Cache-Control" ,
229+ `max-age=${ CONSTANTS . TWO_DAY } , s-maxage=${
230+ CONSTANTS . TWO_DAY
231+ } , stale-while-revalidate=${ CONSTANTS . ONE_DAY } `,
232+ ] ,
233+ ] ) ;
234+ }
235+
236+ // note i'm using block scoped vars
237+ {
238+ let { req, res } = faker ( { cache_seconds : 0 } , data_stats ) ;
239+ await api ( req , res ) ;
240+
241+ expect ( res . setHeader . mock . calls ) . toEqual ( [
242+ [ "Content-Type" , "image/svg+xml" ] ,
243+ [
244+ "Cache-Control" ,
245+ `max-age=${ CONSTANTS . ONE_DAY } , s-maxage=${
246+ CONSTANTS . ONE_DAY
247+ } , stale-while-revalidate=${ CONSTANTS . ONE_DAY } `,
248+ ] ,
249+ ] ) ;
250+ }
251+
252+ {
253+ let { req, res } = faker ( { cache_seconds : - 10000 } , data_stats ) ;
254+ await api ( req , res ) ;
255+
256+ expect ( res . setHeader . mock . calls ) . toEqual ( [
257+ [ "Content-Type" , "image/svg+xml" ] ,
258+ [
259+ "Cache-Control" ,
260+ `max-age=${ CONSTANTS . TWELVE_HOURS } , s-maxage=${
261+ CONSTANTS . TWELVE_HOURS
262+ } , stale-while-revalidate=${ CONSTANTS . ONE_DAY } `,
263+ ] ,
264+ ] ) ;
265+ }
266+ } ) ;
267+
186268 it ( "should allow changing ring_color" , async ( ) => {
187269 const { req, res } = faker (
188270 {
0 commit comments