feat: add four new student modules (rotation, skill-video, exam-prep, academic) with backend APIs and frontend pages; add exam-prep question history with DB persistence
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
AuthorizationError,
|
||||
ErrorKind,
|
||||
GenerationError,
|
||||
SystemError,
|
||||
ValidationError,
|
||||
} from './index';
|
||||
|
||||
describe('错误基类与分类', () => {
|
||||
it('ValidationError 归类为 VALIDATION 且 missingFields 列出缺失字段', () => {
|
||||
const e = ValidationError.missingFields(['type', 'title']);
|
||||
expect(e.kind).toBe(ErrorKind.Validation);
|
||||
expect(e.code).toBe('VALIDATION.MISSING_FIELDS');
|
||||
expect(e.details?.missingFields).toEqual(['type', 'title']);
|
||||
});
|
||||
|
||||
it('ValidationError.invalidFields 列出无效字段', () => {
|
||||
const e = ValidationError.invalidFields(['occurredAt']);
|
||||
expect(e.kind).toBe(ErrorKind.Validation);
|
||||
expect(e.details?.invalidFields).toEqual(['occurredAt']);
|
||||
});
|
||||
|
||||
it('GenerationError 区分失败/超时/信息不足', () => {
|
||||
expect(GenerationError.failed().kind).toBe(ErrorKind.Generation);
|
||||
expect(GenerationError.timedOut(30000).details?.limitMs).toBe(30000);
|
||||
const insufficient = GenerationError.insufficientContent(['正文内容']);
|
||||
expect(insufficient.details?.missingCategories).toEqual(['正文内容']);
|
||||
});
|
||||
|
||||
it('AuthorizationError 归类为 AUTHORIZATION', () => {
|
||||
expect(AuthorizationError.accessDenied('profile').kind).toBe(
|
||||
ErrorKind.Authorization,
|
||||
);
|
||||
expect(AuthorizationError.missingConsent('research').details?.purpose).toBe(
|
||||
'research',
|
||||
);
|
||||
});
|
||||
|
||||
it('SystemError 归类为 SYSTEM', () => {
|
||||
expect(SystemError.internal().kind).toBe(ErrorKind.System);
|
||||
expect(
|
||||
SystemError.dependencyUnavailable('PubMed').details?.dependency,
|
||||
).toBe('PubMed');
|
||||
});
|
||||
|
||||
it('toJSON 输出包含 kind/code/message/details', () => {
|
||||
const json = ValidationError.missingFields(['title']).toJSON();
|
||||
expect(json).toEqual({
|
||||
kind: ErrorKind.Validation,
|
||||
code: 'VALIDATION.MISSING_FIELDS',
|
||||
message: expect.any(String),
|
||||
details: { missingFields: ['title'] },
|
||||
});
|
||||
});
|
||||
|
||||
it('details 为不可变(冻结)副本', () => {
|
||||
const e = ValidationError.missingFields(['a']);
|
||||
expect(Object.isFrozen(e.details)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user