1 | import test from 'ava';
|
2 | import tk from 'timekeeper';
|
3 | import isEqual from 'date-fns/is_equal';
|
4 | import expired from '../';
|
5 |
|
6 | test('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 |
|
11 | test('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 |
|
18 | test('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 |
|
31 | test('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 |
|
43 | test('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 | });
|