1 | 'use strict';
|
2 |
|
3 | const assert = require('assert');
|
4 | const CachePolicy = require('..');
|
5 |
|
6 | describe('Satisfies', function() {
|
7 | it('when URLs match', function() {
|
8 | const policy = new CachePolicy({url:'/',headers:{}}, {status:200,headers:{'cache-control':'max-age=2'}});
|
9 | assert(policy.satisfiesWithoutRevalidation({url:'/',headers:{}}));
|
10 | });
|
11 |
|
12 | it('when expires is present', function() {
|
13 | const policy = new CachePolicy({headers:{}}, {status:302,headers:{'expires':new Date(Date.now()+2000).toGMTString()}});
|
14 | assert(policy.satisfiesWithoutRevalidation({headers:{}}));
|
15 | });
|
16 |
|
17 | it('not when URLs mismatch', function() {
|
18 | const policy = new CachePolicy({url:'/foo',headers:{}}, {status:200,headers:{'cache-control':'max-age=2'}});
|
19 | assert(!policy.satisfiesWithoutRevalidation({url:'/foo?bar',headers:{}}));
|
20 | });
|
21 |
|
22 | it('when methods match', function() {
|
23 | const policy = new CachePolicy({method:'GET',headers:{}}, {status:200,headers:{'cache-control':'max-age=2'}});
|
24 | assert(policy.satisfiesWithoutRevalidation({method:'GET',headers:{}}));
|
25 | });
|
26 |
|
27 | it('not when hosts mismatch', function() {
|
28 | const policy = new CachePolicy({headers:{'host':'foo'}}, {status:200,headers:{'cache-control':'max-age=2'}});
|
29 | assert(policy.satisfiesWithoutRevalidation({headers:{'host':'foo'}}));
|
30 | assert(!policy.satisfiesWithoutRevalidation({headers:{'host':'foofoo'}}));
|
31 | });
|
32 |
|
33 | it('when methods match HEAD', function() {
|
34 | const policy = new CachePolicy({method:'HEAD',headers:{}}, {status:200,headers:{'cache-control':'max-age=2'}});
|
35 | assert(policy.satisfiesWithoutRevalidation({method:'HEAD',headers:{}}));
|
36 | });
|
37 |
|
38 | it('not when methods mismatch', function() {
|
39 | const policy = new CachePolicy({method:'POST',headers:{}}, {status:200,headers:{'cache-control':'max-age=2'}});
|
40 | assert(!policy.satisfiesWithoutRevalidation({method:'GET',headers:{}}));
|
41 | });
|
42 |
|
43 | it('not when methods mismatch HEAD', function() {
|
44 | const policy = new CachePolicy({method:'HEAD',headers:{}}, {status:200,headers:{'cache-control':'max-age=2'}});
|
45 | assert(!policy.satisfiesWithoutRevalidation({method:'GET',headers:{}}));
|
46 | });
|
47 |
|
48 | it('not when proxy revalidating', function() {
|
49 | const policy = new CachePolicy({headers:{}}, {status:200,headers:{'cache-control':'max-age=2, proxy-revalidate '}});
|
50 | assert(!policy.satisfiesWithoutRevalidation({headers:{}}));
|
51 | });
|
52 |
|
53 | it('when not a proxy revalidating', function() {
|
54 | const policy = new CachePolicy({headers:{}}, {status:200,headers:{'cache-control':'max-age=2, proxy-revalidate '}}, {shared:false});
|
55 | assert(policy.satisfiesWithoutRevalidation({headers:{}}));
|
56 | });
|
57 |
|
58 | it('not when no-cache requesting', function() {
|
59 | const policy = new CachePolicy({headers:{}}, {headers:{'cache-control':'max-age=2'}});
|
60 | assert(policy.satisfiesWithoutRevalidation({headers:{'cache-control':'fine'}}));
|
61 | assert(!policy.satisfiesWithoutRevalidation({headers:{'cache-control':'no-cache'}}));
|
62 | assert(!policy.satisfiesWithoutRevalidation({headers:{'pragma':'no-cache'}}));
|
63 | });
|
64 | });
|