Repository navigation
Expand file tree
/
Copy pathcacheControl.empty-fallback.test.ts
More file actions
59 lines (52 loc) · 2.13 KB
/
Copy pathcacheControl.empty-fallback.test.ts
File metadata and controls
59 lines (52 loc) · 2.13 KB
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
/* eslint-disable @typescript-eslint/no-explicit-any */
import { describe, expect, it } from 'vitest';
import { buildCacheControlHeader } from './cacheControl';
describe('buildCacheControlHeader - Edge Cases & Empty/Missing Inputs Verification', () => {
it('1. falls back to default cache control when options object is completely omitted', () => {
// Calling the function with no arguments should fallback gracefully without throwing
expect(buildCacheControlHeader()).toBe('public, s-maxage=1, stale-while-revalidate=59');
});
it('2. falls back to default cache control when options is an empty object', () => {
expect(buildCacheControlHeader({})).toBe('public, s-maxage=1, stale-while-revalidate=59');
});
it('3. falls back to default cache control when options object is null', () => {
// Casting to any to test JavaScript-level null input resilience
expect(buildCacheControlHeader(null as any)).toBe(
'public, s-maxage=1, stale-while-revalidate=59'
);
});
it('4. falls back to default cache control when options contain only undefined or null values', () => {
expect(
buildCacheControlHeader({
bypass: undefined,
secondsToMidnight: undefined,
isHistoricalYear: undefined,
})
).toBe('public, s-maxage=1, stale-while-revalidate=59');
expect(
buildCacheControlHeader({
bypass: null as any,
secondsToMidnight: null as any,
isHistoricalYear: null as any,
})
).toBe('public, s-maxage=1, stale-while-revalidate=59');
});
it('5. prioritizes bypass=true even if other options are invalid/null/undefined', () => {
expect(
buildCacheControlHeader({
bypass: true,
secondsToMidnight: null as any,
isHistoricalYear: undefined,
})
).toBe('no-cache, no-store, must-revalidate');
});
it('6. prioritizes isHistoricalYear=true when bypass is falsy and secondsToMidnight is null/undefined', () => {
expect(
buildCacheControlHeader({
bypass: false,
secondsToMidnight: undefined,
isHistoricalYear: true,
})
).toBe('public, s-maxage=31536000, immutable');
});
});