UNPKG

897 BJavaScriptView Raw
1import test from 'ava';
2import subSeconds from 'date-fns/sub_seconds';
3import addSeconds from 'date-fns/add_seconds';
4import expired from '../';
5
6test('expired is a function', t => {
7 t.is(typeof expired, 'function');
8});
9
10test('expired returns false for valid cache', t => {
11 const headers = {
12 date: new Date().toUTCString(),
13 age: 0,
14 'cache-control': 'public, max-age=300'
15 };
16
17 t.false(expired(headers));
18});
19
20test('expired returns true for stale cache', t => {
21 const headers = {
22 date: subSeconds(new Date(), 500).toUTCString(),
23 age: 0,
24 'cache-control': 'public, max-age=300'
25 };
26
27 t.true(expired(headers));
28});
29
30test('expired accepts currentDate argument', t => {
31 const date = new Date();
32 const headers = {
33 date: date.toUTCString(),
34 age: 0,
35 'cache-control': 'public, max-age=300'
36 };
37
38 t.false(expired(headers, date));
39 t.true(expired(headers, addSeconds(date, 500)));
40});