Files
RSSHub/test/middleware/header.js
Rongrong e1ee28267e fix(core): RequestInProgressError cache age (#9850)
* fix(core): RequestInProgressError cache age

Signed-off-by: Rongrong <i@rong.moe>

* fix: ci test

Signed-off-by: Rongrong <i@rong.moe>
2022-05-30 17:30:41 +08:00

40 lines
1.4 KiB
JavaScript

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;
});
describe('header', () => {
it(`header`, async () => {
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['rsshub-node']).toBe('mock');
expect(response.headers.etag).not.toBe(undefined);
etag = response.headers.etag;
});
it(`etag`, async () => {
const response = await request.get('/test/1').set('If-None-Match', etag);
expect(response.status).toBe(304);
expect(response.text).toBe('');
expect(response.headers['last-modified']).toBe(undefined);
});
});