|
@ -1,6 +1,6 @@ |
|
|
import test from 'ava'; |
|
|
import test from 'ava'; |
|
|
import tk from 'timekeeper'; |
|
|
import tk from 'timekeeper'; |
|
|
import subSeconds from 'date-fns/sub_seconds'; |
|
|
import addSeconds from 'date-fns/add_seconds'; |
|
|
import expired from '../'; |
|
|
import expired from '../'; |
|
|
|
|
|
|
|
|
test('expired.in is a function', t => { |
|
|
test('expired.in is a function', t => { |
|
@ -38,14 +38,14 @@ test('expired.in returns zero ms for instantly stale cache', t => { |
|
|
|
|
|
|
|
|
test('expired.in returns negative ms for stale cache', t => { |
|
|
test('expired.in returns negative ms for stale cache', t => { |
|
|
const date = new Date().toUTCString(); |
|
|
const date = new Date().toUTCString(); |
|
|
const dateOffset = 600; |
|
|
const dateOffset = -600; |
|
|
const maxAge = 300; |
|
|
const maxAge = 300; |
|
|
const headers = { |
|
|
const headers = { |
|
|
date: subSeconds(date, dateOffset).toUTCString(), |
|
|
date: addSeconds(date, dateOffset).toUTCString(), |
|
|
age: 0, |
|
|
age: 0, |
|
|
'cache-control': `public, max-age=${maxAge}` |
|
|
'cache-control': `public, max-age=${maxAge}` |
|
|
}; |
|
|
}; |
|
|
const expiredIn = (maxAge - dateOffset) * 1000; |
|
|
const expiredIn = (maxAge + dateOffset) * 1000; |
|
|
|
|
|
|
|
|
tk.freeze(date); |
|
|
tk.freeze(date); |
|
|
t.is(expired.in(headers), expiredIn); |
|
|
t.is(expired.in(headers), expiredIn); |
|
|