test: fix caces

This commit is contained in:
DIYgod
2024-03-31 23:13:22 +08:00
parent f5ced001eb
commit bf4e5dd78f
6 changed files with 17 additions and 32 deletions
+5 -5
View File
@@ -3,7 +3,7 @@ import Parser from 'rss-parser';
import wait from '@/utils/wait';
process.env.CACHE_EXPIRE = '1';
process.env.CACHE_CONTENT_EXPIRE = '3';
process.env.CACHE_CONTENT_EXPIRE = '2';
const parser = new Parser();
@@ -38,7 +38,7 @@ describe('cache', () => {
expect(response3.headers).not.toHaveProperty('rsshub-cache-status');
const parsed3 = await parser.parseString(await response3.text());
await wait(3 * 1000 + 100);
await wait(2 * 1000 + 100);
const response4 = await app.request('/test/cache');
const parsed4 = await parser.parseString(await response4.text());
@@ -51,7 +51,7 @@ describe('cache', () => {
await wait(1 * 1000 + 100);
const response5 = await app.request('/test/refreshCache');
const parsed5 = await parser.parseString(await response5.text());
await wait(2 * 1000 + 100);
await wait(1 * 1000 + 100);
const response6 = await app.request('/test/refreshCache');
const parsed6 = await parser.parseString(await response6.text());
@@ -86,7 +86,7 @@ describe('cache', () => {
expect(response3.headers).not.toHaveProperty('rsshub-cache-status');
const parsed3 = await parser.parseString(await response3.text());
await wait(3 * 1000 + 100);
await wait(2 * 1000 + 100);
const response4 = await app.request('/test/cache');
const parsed4 = await parser.parseString(await response4.text());
@@ -99,7 +99,7 @@ describe('cache', () => {
await wait(1 * 1000 + 100);
const response5 = await app.request('/test/refreshCache');
const parsed5 = await parser.parseString(await response5.text());
await wait(2 * 1000 + 100);
await wait(1 * 1000 + 100);
const response6 = await app.request('/test/refreshCache');
const parsed6 = await parser.parseString(await response6.text());
+7 -23
View File
@@ -1,8 +1,12 @@
import { describe, expect, it, vi } from 'vitest';
import app from '@/app';
import Parser from 'rss-parser';
import { config } from '@/config';
import nock from 'nock';
process.env.OPENAI_API_KEY = 'sk-1234567890';
process.env.OPENAI_API_ENDPOINT = 'https://api.openai.mock/v1';
vi.mock('@/utils/request-rewriter', () => ({ default: null }));
const { config } = await import('@/config');
const { default: app } = await import('@/app');
const parser = new Parser();
@@ -424,26 +428,6 @@ describe('multi parameter', () => {
describe('openai', () => {
it(`chatgpt`, async () => {
vi.resetModules();
process.env.OPENAI_API_KEY = 'sk-1234567890';
const app = (await import('@/app')).default;
const { config } = await import('@/config');
nock(config.openai.endpoint)
.post('/chat/completions')
.reply(() => [
200,
{
choices: [
{
message: {
content: 'Summary of the article.',
},
},
],
},
]);
const responseWithGpt = await app.request('/test/gpt?chatgpt=true');
const responseNormal = await app.request('/test/gpt');
+1 -1
View File
@@ -50,7 +50,7 @@ const summarizeArticle = async (articleText: string) => {
},
});
return response.data.choices[0].message.content;
return response.choices[0].message.content;
};
const getAuthorString = (item) => {
+1 -1
View File
@@ -3,7 +3,7 @@ import { setupServer } from 'msw/node';
import { http, HttpResponse } from 'msw';
const server = setupServer(
http.post(`https://api.openai.com/v1/chat/completions`, () =>
http.post(`https://api.openai.mock/v1/chat/completions`, () =>
HttpResponse.json({
choices: [
{
+2 -2
View File
@@ -5,8 +5,8 @@ import { config } from '@/config';
describe('got', () => {
it('headers', async () => {
const { data } = await got('http://rsshub.test/ua');
expect(data.ua).toBe(config.ua);
const { data } = await got('http://rsshub.test/headers');
expect(data['user-agent']).toBe(config.ua);
});
it('retry', async () => {
+1
View File
@@ -11,5 +11,6 @@ export default defineConfig({
},
testTimeout: 10000,
setupFiles: ['./lib/setup.test.ts'],
exclude: ['./lib/setup.test.ts'],
},
});