31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { CoauthorQuestionSchema, StoredCoauthorQuestionSchema } from './coauthor-question'
|
|
|
|
describe('coauthor question validation', () => {
|
|
it('accepts three useful, distinct answers', () => {
|
|
expect(CoauthorQuestionSchema.parse({
|
|
question: 'How will the party enter the sealed archive?',
|
|
options: ['Negotiate with its keeper', 'Search for a maintenance route', 'Force the main gate'],
|
|
})).toMatchObject({ options: ['Negotiate with its keeper', 'Search for a maintenance route', 'Force the main gate'] })
|
|
expect(CoauthorQuestionSchema.toJSONSchema()).toMatchObject({
|
|
type: 'object',
|
|
properties: { options: { type: 'array', minItems: 3, maxItems: 3 } },
|
|
})
|
|
})
|
|
|
|
it('rejects malformed JSON fragments and a repeated question', () => {
|
|
expect(() => CoauthorQuestionSchema.parse({
|
|
question: 'Как персонажи собираются решить проблему отсутствия наличных денег?',
|
|
options: [':', 'question', 'Как персонажи собираются решить проблему отсутствия наличных денег?'],
|
|
})).toThrow()
|
|
})
|
|
|
|
it('applies the same quality checks to a stored question', () => {
|
|
expect(() => StoredCoauthorQuestionSchema.parse({
|
|
id: 'question-2',
|
|
label: 'What makes the signal dangerous?',
|
|
options: ['The signal is alive', 'The signal is alive', 'Nobody knows yet'],
|
|
})).toThrow()
|
|
})
|
|
})
|