-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdn.test.js
More file actions
41 lines (36 loc) · 1.12 KB
/
cdn.test.js
File metadata and controls
41 lines (36 loc) · 1.12 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
const CDN = require('./cdn.js');
describe('CDN Tests', () => {
const cdn = new CDN({
dir: './cdn/',
extension: '.cdn.json',
ttl: 3600,
});
test('Constructor', () => {
expect(cdn.dir).toBe('./cdn/');
expect(cdn.extension).toBe('.cdn.json');
expect(cdn.ttl).toBe(3600);
});
async function cmsdata() { // Example fetching and caching CMS data
if (cdn.valid('cms')) return cdn.get('cms'); // Return cached CMS data if valid
try {
console.log('Writing...')
cdn.cache('cms', { 1: 2 }); // Cache the CMS data
return { 1: 2 };
} catch {
try {
return cdn.get('cms'); // Retrieve cached CMS data
} catch {
console.error('Failed to fetch CMS data and no cached data found.');
return null;
};
};
};
test('Cache', async () => {
var cms = await cmsdata();
expect(cms).toEqual({ 1: 2 });
});
test('Get', async () => {
var cms = await cmsdata();
expect(cms).toEqual({ 1: 2 });
});
});