1 | import test from 'ava';
|
2 | import subSeconds from 'date-fns/sub_seconds';
|
3 | import addSeconds from 'date-fns/add_seconds';
|
4 | import expired from '../';
|
5 |
|
6 | test('expired is a function', t => {
|
7 | t.is(typeof expired, 'function');
|
8 | });
|
9 |
|
10 | test('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 |
|
20 | test('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 |
|
30 | test('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 | });
|