Browse Source

Test expired.in returns negative ms for stale cache

pull/7/head
Luke Childs 8 years ago
parent
commit
752bc6f836
  1. 16
      test/expired.in.js

16
test/expired.in.js

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

Loading…
Cancel
Save