test(service): CardService et schémas de validation
This commit is contained in:
1 parent
12670b7134
commit
e4aa5f4b3b
2 files changed
+154
No files matched your search
@@ -0,0 +1,39 @@
|
||||
// @vitest-environment node
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createCardSchema, updateCardSchema } from './card-schemas'
|
||||
|
||||
describe('createCardSchema', () => {
|
||||
it('accepte une entrée valide et normalise les champs', () => {
|
||||
const result = createCardSchema.parse({
|
||||
question: ' Question ? ',
|
||||
response: 'Réponse',
|
||||
theme: ' javascript ',
|
||||
tags: ['scope'],
|
||||
})
|
||||
expect(result.question).toBe('Question ?')
|
||||
expect(result.theme).toBe('javascript')
|
||||
})
|
||||
|
||||
it('accepte une entrée sans tags', () => {
|
||||
expect(createCardSchema.parse({ question: 'Q', response: 'R', theme: 'git' }).tags).toBeUndefined()
|
||||
})
|
||||
|
||||
it('rejette une question vide', () => {
|
||||
expect(() => createCardSchema.parse({ question: ' ', response: 'R', theme: 'git' })).toThrow()
|
||||
})
|
||||
|
||||
it('rejette un thème manquant', () => {
|
||||
expect(() => createCardSchema.parse({ question: 'Q', response: 'R' })).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateCardSchema', () => {
|
||||
it('accepte une mise à jour partielle', () => {
|
||||
const result = updateCardSchema.parse({ response: 'Nouvelle réponse' })
|
||||
expect(result).toEqual({ response: 'Nouvelle réponse' })
|
||||
})
|
||||
|
||||
it('rejette un champ vide lors d une mise à jour', () => {
|
||||
expect(() => updateCardSchema.parse({ theme: '' })).toThrow()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user