File size: 1,724 Bytes
bf48b89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { afterAll, afterEach, describe, expect, it } from 'vitest';

import wait from '@/utils/wait';

process.env.NODE_NAME = 'mock';
process.env.ALLOW_ORIGIN = 'rsshub.mock';

let etag;

afterEach(async () => {
    await wait(1000);
});

afterAll(() => {
    delete process.env.NODE_NAME;
    delete process.env.ALLOW_ORIGIN;
});

describe('header', () => {
    it(`header`, async () => {
        const app = (await import('@/app')).default;
        const { config } = await import('@/config');
        const response = await app.request('/test/1');
        expect(response.headers.get('access-control-allow-origin')).toBe('rsshub.mock');
        expect(response.headers.get('access-control-allow-methods')).toBe('GET');
        expect(response.headers.get('content-type')).toBe('application/xml; charset=utf-8');
        expect(response.headers.get('cache-control')).toBe(`public, max-age=${config.cache.routeExpire}`);
        expect(response.headers.get('last-modified')).toBe((await response.text()).match(/<lastBuildDate>(.*)<\/lastBuildDate>/)?.[1]);
        expect(response.headers.get('rsshub-node')).toBe('mock');
        expect(response.headers.get('etag')).not.toBe(undefined);
        etag = response.headers.get('etag');
        expect(response.headers.get('x-rsshub-route')).toBe('/test/:id/:params?');
    });

    it(`etag`, async () => {
        const app = (await import('@/app')).default;
        const response = await app.request('/test/1', {
            headers: {
                'If-None-Match': etag,
            },
        });
        expect(response.status).toBe(304);
        expect(await response.text()).toBe('');
        expect(response.headers.get('last-modified')).toBe(null);
    });
});