File size: 1,554 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/* eslint-env jest */
import { getMaxAge } from 'next/dist/server/image-optimizer'
describe('getMaxAge', () => {
it('should return 0 when no cache-control provided', () => {
expect(getMaxAge(undefined)).toBe(0)
})
it('should return 0 when cache-control is null', () => {
expect(getMaxAge(null)).toBe(0)
})
it('should return 0 when cache-control is empty string', () => {
expect(getMaxAge('')).toBe(0)
})
it('should return 0 when cache-control max-age is not a number', () => {
expect(getMaxAge('max-age=foo')).toBe(0)
})
it('should return 0 when cache-control is no-cache', () => {
expect(getMaxAge('no-cache')).toBe(0)
})
it('should return cache-control max-age lowercase', () => {
expect(getMaxAge('max-age=9999')).toBe(9999)
})
it('should return cache-control MAX-AGE uppercase', () => {
expect(getMaxAge('MAX-AGE=9999')).toBe(9999)
})
it('should return cache-control s-maxage lowercase', () => {
expect(getMaxAge('s-maxage=9999')).toBe(9999)
})
it('should return cache-control S-MAXAGE', () => {
expect(getMaxAge('S-MAXAGE=9999')).toBe(9999)
})
it('should return cache-control s-maxage with spaces', () => {
expect(getMaxAge('public, max-age=5555, s-maxage=9999')).toBe(9999)
})
it('should return cache-control s-maxage without spaces', () => {
expect(getMaxAge('public,s-maxage=9999,max-age=5555')).toBe(9999)
})
it('should return cache-control for a quoted value', () => {
expect(getMaxAge('public, s-maxage="9999", max-age="5555"')).toBe(9999)
})
})
|