mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
test: middleware header
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import { describe, expect, it, afterAll } from '@jest/globals';
|
||||
import supertest from 'supertest';
|
||||
|
||||
process.env.NODE_NAME = 'mock';
|
||||
process.env.ALLOW_ORIGIN = 'rsshub.mock';
|
||||
|
||||
const supertest = require('supertest');
|
||||
jest.mock('request-promise-native');
|
||||
const server = require('../../lib/index');
|
||||
const request = supertest(server);
|
||||
const config = require('../../lib/config').value;
|
||||
let etag;
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
delete process.env.NODE_NAME;
|
||||
delete process.env.ALLOW_ORIGIN;
|
||||
@@ -19,18 +13,21 @@ afterAll(() => {
|
||||
|
||||
describe('header', () => {
|
||||
it(`header`, async () => {
|
||||
const request = supertest((await import('@/index')).default);
|
||||
const { config } = await import('@/config');
|
||||
const response = await request.get('/test/1');
|
||||
expect(response.headers['access-control-allow-origin']).toBe('rsshub.mock');
|
||||
expect(response.headers['access-control-allow-methods']).toBe('GET');
|
||||
expect(response.headers['content-type']).toBe('application/xml; charset=utf-8');
|
||||
expect(response.headers['cache-control']).toBe(`public, max-age=${config.cache.routeExpire}`);
|
||||
expect(response.headers['last-modified']).toBe(response.text.match(/<lastBuildDate>(.*)<\/lastBuildDate>/)[1]);
|
||||
expect(response.headers['last-modified']).toBe(response.text.match(/<lastBuildDate>(.*)<\/lastBuildDate>/)?.[1]);
|
||||
expect(response.headers['rsshub-node']).toBe('mock');
|
||||
expect(response.headers.etag).not.toBe(undefined);
|
||||
etag = response.headers.etag;
|
||||
});
|
||||
|
||||
it(`etag`, async () => {
|
||||
const request = supertest((await import('@/index')).default);
|
||||
const response = await request.get('/test/1').set('If-None-Match', etag);
|
||||
expect(response.status).toBe(304);
|
||||
expect(response.text).toBe('');
|
||||
Reference in New Issue
Block a user