修改-试卷总分设置项

This commit is contained in:
2025-12-26 18:39:17 +08:00
parent 7b52abfea3
commit 42fcb71bae
5 changed files with 538 additions and 371 deletions

View File

@@ -213,6 +213,61 @@ test('管理员任务分页统计接口返回结构正确', async () => {
assert.equal(firstGenerate.json?.success, true);
assert.ok(Array.isArray(firstGenerate.json?.data?.questions));
const countSubjectId = randomUUID();
await run(
`INSERT INTO exam_subjects (id, name, type_ratios, category_ratios, total_score, duration_minutes)
VALUES (?, ?, ?, ?, ?, ?)`,
[
countSubjectId,
'题量科目',
JSON.stringify({ single: 2, multiple: 1, judgment: 1, text: 0 }),
JSON.stringify({ 通用: 4 }),
40,
60,
],
);
await run(
`INSERT INTO questions (id, content, type, options, answer, score, category)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[randomUUID(), '题量-单选1', 'single', JSON.stringify(['A', 'B', 'C', 'D']), 'A', 10, '通用'],
);
await run(
`INSERT INTO questions (id, content, type, options, answer, score, category)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[randomUUID(), '题量-单选2', 'single', JSON.stringify(['A', 'B', 'C', 'D']), 'B', 10, '通用'],
);
await run(
`INSERT INTO questions (id, content, type, options, answer, score, category)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[randomUUID(), '题量-多选1', 'multiple', JSON.stringify(['A', 'B', 'C', 'D']), JSON.stringify(['A', 'B']), 10, '通用'],
);
await run(
`INSERT INTO questions (id, content, type, options, answer, score, category)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[randomUUID(), '题量-判断1', 'judgment', null, 'A', 10, '通用'],
);
const countGenerate = await jsonFetch(baseUrl, '/api/quiz/generate', {
method: 'POST',
body: { userId: userA.id, subjectId: countSubjectId },
});
assert.equal(countGenerate.status, 200);
assert.equal(countGenerate.json?.success, true);
assert.equal(countGenerate.json?.data?.timeLimit, 60);
assert.equal(countGenerate.json?.data?.totalScore, 40);
assert.ok(Array.isArray(countGenerate.json?.data?.questions));
assert.equal(countGenerate.json?.data?.questions?.length, 4);
const byType = (countGenerate.json?.data?.questions as any[]).reduce((acc, q) => {
acc[q.type] = (acc[q.type] || 0) + 1;
return acc;
}, {} as Record<string, number>);
assert.equal(byType.single, 2);
assert.equal(byType.multiple, 1);
assert.equal(byType.judgment, 1);
assert.equal(byType.text || 0, 0);
await run(
`INSERT INTO quiz_records (id, user_id, subject_id, task_id, total_score, correct_count, total_count, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,