添加后端集成测试套件

- 实现 82 个集成测试用例覆盖所有 API 端点
- 使用真实数据库连接,无 mock 逻辑
- 修复 PUT 请求只更新提供字段的逻辑
- 配置 Vitest 串行执行避免测试竞态

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuangandClaude Sonnet 4.5 committed 2026-02-05 15:23:37 +08:00
1 parent 6df528f187
commit 697430feed
18 files changed
+4333 -8

No files matched your search

+8 -1
View File
@@ -70,9 +70,16 @@ export async function channelRoutes(app: FastifyInstance): Promise<void> {
throw new NotFoundError('推送渠道不存在');
}
// 构建更新数据对象,只包含提供的字段
const updateData: any = {};
if (name !== undefined) updateData.name = name;
if (type !== undefined) updateData.type = type;
if (config !== undefined) updateData.config = config;
if (enabled !== undefined) updateData.enabled = enabled;
const channel = await prisma.channel.update({
where: { id: parseInt(id) },
data: { name, type, config, enabled },
data: updateData,
});
successResponse(reply, channel, '推送渠道更新成功');
+9 -1
View File
@@ -63,9 +63,17 @@ export async function llmConfigRoutes(app: FastifyInstance): Promise<void> {
throw new NotFoundError('LLM 配置不存在');
}
// 构建更新数据对象,只包含提供的字段
const updateData: any = {};
if (name !== undefined) updateData.name = name;
if (baseUrl !== undefined) updateData.baseUrl = baseUrl;
if (model !== undefined) updateData.model = model;
if (apiKey !== undefined) updateData.apiKey = apiKey;
if (enabled !== undefined) updateData.enabled = enabled;
const config = await prisma.llmConfig.update({
where: { id: parseInt(id) },
data: { name, baseUrl, model, apiKey, enabled },
data: updateData,
});
successResponse(reply, config, 'LLM 配置更新成功');
+9 -1
View File
@@ -70,9 +70,17 @@ export async function sourceRoutes(app: FastifyInstance): Promise<void> {
throw new NotFoundError('数据源不存在');
}
// 构建更新数据对象,只包含提供的字段
const updateData: any = {};
if (name !== undefined) updateData.name = name;
if (type !== undefined) updateData.type = type;
if (config !== undefined) updateData.config = config;
if (cronExpression !== undefined) updateData.cronExpression = cronExpression;
if (enabled !== undefined) updateData.enabled = enabled;
const source = await prisma.source.update({
where: { id: parseInt(id) },
data: { name, type, config, cronExpression, enabled },
data: updateData,
});
successResponse(reply, source, '数据源更新成功');
+10 -1
View File
@@ -118,9 +118,18 @@ export async function topicRoutes(app: FastifyInstance): Promise<void> {
throw new NotFoundError('主题不存在');
}
// 构建更新数据对象,只包含提供的字段
const updateData: any = {};
if (name !== undefined) updateData.name = name;
if (description !== undefined) updateData.description = description;
if (processMode !== undefined) updateData.processMode = processMode;
if (llmConfigId !== undefined) updateData.llmConfigId = llmConfigId;
if (scheduleConfig !== undefined) updateData.scheduleConfig = scheduleConfig;
if (enabled !== undefined) updateData.enabled = enabled;
const topic = await prisma.topic.update({
where: { id: parseInt(id) },
data: { name, description, processMode, llmConfigId, scheduleConfig, enabled },
data: updateData,
});
// 更新数据源关联