-
Notifications
You must be signed in to change notification settings - Fork 2k
/
cacheControlExtension.test.ts
63 lines (51 loc) 路 2.07 KB
/
cacheControlExtension.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { ResponsePath } from 'graphql';
import { CacheControlExtension, CacheScope } from '../';
describe('CacheControlExtension', () => {
let cacheControlExtension: CacheControlExtension;
beforeEach(() => {
cacheControlExtension = new CacheControlExtension();
});
describe('computeOverallCachePolicy', () => {
const responsePath: ResponsePath = {
key: 'test',
prev: undefined,
};
const responseSubPath: ResponsePath = {
key: 'subTest',
prev: responsePath,
};
it('returns undefined without cache hints', () => {
const cachePolicy = cacheControlExtension.computeOverallCachePolicy();
expect(cachePolicy).toBeUndefined();
});
it('returns lowest max age value', () => {
cacheControlExtension.addHint(responsePath, { maxAge: 10 });
cacheControlExtension.addHint(responseSubPath, { maxAge: 20 });
const cachePolicy = cacheControlExtension.computeOverallCachePolicy();
expect(cachePolicy).toHaveProperty('maxAge', 10);
});
it('returns undefined if any cache hint has a maxAge of 0', () => {
cacheControlExtension.addHint(responsePath, { maxAge: 120 });
cacheControlExtension.addHint(responseSubPath, { maxAge: 0 });
const cachePolicy = cacheControlExtension.computeOverallCachePolicy();
expect(cachePolicy).toBeUndefined();
});
it('returns PUBLIC scope by default', () => {
cacheControlExtension.addHint(responsePath, { maxAge: 10 });
const cachePolicy = cacheControlExtension.computeOverallCachePolicy();
expect(cachePolicy).toHaveProperty('scope', CacheScope.Public);
});
it('returns PRIVATE scope if any cache hint has PRIVATE scope', () => {
cacheControlExtension.addHint(responsePath, {
maxAge: 10,
scope: CacheScope.Public,
});
cacheControlExtension.addHint(responseSubPath, {
maxAge: 10,
scope: CacheScope.Private,
});
const cachePolicy = cacheControlExtension.computeOverallCachePolicy();
expect(cachePolicy).toHaveProperty('scope', CacheScope.Private);
});
});
});