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
+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');