(res, defaultSurrogateKey = false, minMaxAge = 60 * 60)
| 1 | import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js' |
| 2 | |
| 3 | export function checkCachingHeaders(res, defaultSurrogateKey = false, minMaxAge = 60 * 60) { |
| 4 | expect(res.headers['set-cookie']).toBeUndefined() |
| 5 | expect(res.headers['cache-control']).toContain('public') |
| 6 | const maxAgeSeconds = parseInt(res.headers['cache-control'].match(/max-age=(\d+)/)[1], 10) |
| 7 | // Let's not be too specific in the tests, just as long as it's testing |
| 8 | // that it's a reasonably large number of seconds. |
| 9 | expect(maxAgeSeconds).toBeGreaterThanOrEqual(minMaxAge) |
| 10 | // Because it doesn't have have a unique URL |
| 11 | expect(res.headers['surrogate-key'].split(/\s/g)[0]).toBe( |
| 12 | defaultSurrogateKey ? SURROGATE_ENUMS.DEFAULT : SURROGATE_ENUMS.MANUAL |
| 13 | ) |
| 14 | } |
no outgoing calls
no test coverage detected