UNPKG

1.22 kBJavaScriptView Raw
1import test from 'ava';
2import tk from 'timekeeper';
3import isEqual from 'date-fns/is_equal';
4import expired from '../';
5
6test('throw error if header argument is missing', t => {
7 const err = t.throws(() => expired());
8 t.is(err.message, 'Headers argument is missing');
9});
10
11test('throw error if Date header is missing', t => {
12 const headers = {};
13
14 const err = t.throws(() => expired(headers));
15 t.is(err.message, 'Date header is missing');
16});
17
18test('headers can be passed in as an object', t => {
19 const date = new Date().toUTCString();
20 const headers = {
21 date,
22 age: 0,
23 'cache-control': `public, max-age=0`
24 };
25
26 tk.freeze(date);
27 t.true(isEqual(expired.on(headers), date));
28 tk.reset();
29});
30
31test('headers can be passed in as a string', t => {
32 const date = new Date().toUTCString();
33 const headers = `
34 Date: ${date}
35 Age: 0
36 Cache-Control public, max-age=0`;
37
38 tk.freeze(date);
39 t.true(isEqual(expired.on(headers), date));
40 tk.reset();
41});
42
43test('headers can contain status code', t => {
44 const date = new Date().toUTCString();
45 const headers = `
46 HTTP/1.1 200 OK
47 Date: ${date}
48 Age: 0
49 Cache-Control public, max-age=0`;
50
51 tk.freeze(date);
52 t.true(isEqual(expired.on(headers), date));
53 tk.reset();
54});