-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathheaders.server.test.ts
More file actions
39 lines (35 loc) · 918 Bytes
/
headers.server.test.ts
File metadata and controls
39 lines (35 loc) · 918 Bytes
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
import { format, parse } from '@tusbar/cache-control'
import { expect, test } from 'vitest'
import { getConservativeCacheControl } from './headers.server.ts'
test('works for basic usecase', () => {
const result = getConservativeCacheControl(
'max-age=3600',
'max-age=1800, s-maxage=600',
'private, max-age=86400',
)
expect(result).toEqual(
format({
maxAge: 1800,
sharedMaxAge: 600,
private: true,
}),
)
})
test('retains boolean directive', () => {
const result = parse(
getConservativeCacheControl('private', 'no-cache,no-store'),
)
expect(result.private).toBe(true)
expect(result.noCache).toBe(true)
expect(result.noStore).toBe(true)
})
test('gets smallest number directive', () => {
const result = parse(
getConservativeCacheControl(
'max-age=10, s-maxage=300',
'max-age=300, s-maxage=600',
),
)
expect(result.maxAge).toBe(10)
expect(result.sharedMaxAge).toBe(300)
})