0fe04d4d99
- Сервисы: testAttemptService, testAccess, document import/gen/extract, LLM, assignment, aiEditor - Конфиг: devAuthor, featureFlags; messages/ru; интеграция V.9 (skip без БД) - API/роуты: app, auth, server; Dockerfile и env example - Фронт: TestAttempt, TestAttemptReview, AttemptReviewBlock, стили, правки App/api/login/vite - compose и README; смоук-тесты расширены Закрывает отсутствие модулей в origin после клона. Made-with: Cursor
64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
parseJsonFromLlmText,
|
|
validateAndNormalizeDraft,
|
|
} from './documentGenService.js';
|
|
|
|
test('parseJsonFromLlmText: чистый JSON', () => {
|
|
const o = parseJsonFromLlmText('{"title":"T","questions":[{"text":"Q","options":[{"text":"a","isCorrect":true},{"text":"b","isCorrect":false}]}]}');
|
|
assert.equal(o.title, 'T');
|
|
assert.equal(o.questions.length, 1);
|
|
});
|
|
|
|
test('parseJsonFromLlmText: JSON в markdown-заборе', () => {
|
|
const raw = '```json\n{"title":"X","questions":[{"text":"1","options":[{"text":"+","isCorrect":true},{"text":"-","isCorrect":false}]}]}\n```';
|
|
const o = parseJsonFromLlmText(raw);
|
|
assert.equal(o.title, 'X');
|
|
});
|
|
|
|
test('parseJsonFromLlmText: невалидный JSON — ошибка', () => {
|
|
assert.throws(
|
|
() => parseJsonFromLlmText('not json'),
|
|
/JSON/i
|
|
);
|
|
});
|
|
|
|
test('validateAndNormalizeDraft: валидный черновик', () => {
|
|
const d = validateAndNormalizeDraft({
|
|
title: ' Экзамен ',
|
|
description: ' оп ',
|
|
questions: [
|
|
{
|
|
text: '2+2?',
|
|
hasMultipleAnswers: false,
|
|
options: [
|
|
{ text: '4', isCorrect: true },
|
|
{ text: '5', isCorrect: false },
|
|
],
|
|
},
|
|
],
|
|
});
|
|
assert.equal(d.title, 'Экзамен');
|
|
assert.equal(d.description, 'оп');
|
|
assert.equal(d.questions[0].options.length, 2);
|
|
});
|
|
|
|
test('validateAndNormalizeDraft: нет title', () => {
|
|
assert.throws(
|
|
() =>
|
|
validateAndNormalizeDraft({
|
|
questions: [
|
|
{
|
|
text: 'Q',
|
|
options: [
|
|
{ text: 'a', isCorrect: true },
|
|
{ text: 'b', isCorrect: false },
|
|
],
|
|
},
|
|
],
|
|
}),
|
|
/title/i
|
|
);
|
|
});
|