fix
This commit is contained in:
@@ -135,7 +135,7 @@ describe('quizQuestionsSchema', () => {
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('rejects a missing or unknown difficulty', () => {
|
||||
it('falls back to medium for a missing or unknown difficulty', () => {
|
||||
const base = {
|
||||
id: 'q',
|
||||
question: 'q',
|
||||
@@ -144,10 +144,12 @@ describe('quizQuestionsSchema', () => {
|
||||
correctIndex: 0,
|
||||
explanation: 'because',
|
||||
};
|
||||
expect(() => quizQuestionsSchema.parse({ questions: [base] })).toThrow();
|
||||
expect(() =>
|
||||
quizQuestionsSchema.parse({ questions: [{ ...base, difficulty: 'trivial' }] }),
|
||||
).toThrow();
|
||||
// Missing difficulty should default to 'medium'
|
||||
const parsed1 = quizQuestionsSchema.parse({ questions: [base] });
|
||||
expect(parsed1.questions[0].difficulty).toBe('medium');
|
||||
// Unknown difficulty should also default to 'medium'
|
||||
const parsed2 = quizQuestionsSchema.parse({ questions: [{ ...base, difficulty: 'trivial' }] });
|
||||
expect(parsed2.questions[0].difficulty).toBe('medium');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user