fix(catalog) : M6 — mapping inline des erreurs 422 du formulaire produit
Les operations Post/Patch de Product n'avaient pas collectDenormalizationErrors : un null/type invalide sur une relation (category) levait un 400 qui court-circuitait toute la validation -> aucune violation propertyPath, donc aucune erreur mappee sous les champs (ajout comme modification). - Product : collectDenormalizationErrors: true sur Post + Patch (miroir Client/Supplier/WeighingTicket) -> 422 avec propertyPath au lieu de 400. - useProductForm : on omet la cle 'category' du payload quand aucune categorie n'est choisie (envoyer null casserait la denormalisation IRI et masquerait les autres violations) -> le back renvoie les 6 violations d'un coup, dont le NotNull propre sur category.
This commit is contained in:
@@ -171,6 +171,20 @@ describe('useProductForm', () => {
|
||||
expect(payload.containsMolasses).toBe(false)
|
||||
})
|
||||
|
||||
it('omet `category` du payload quand aucune categorie n\'est choisie', async () => {
|
||||
// Envoyer category:null casserait la denormalisation back (type IRI
|
||||
// attendu) et court-circuiterait les autres violations -> on l'omet.
|
||||
mockPost.mockResolvedValueOnce({ id: 40 })
|
||||
const { form, submit } = useProductForm()
|
||||
fillValidForm(form)
|
||||
form.categoryIri = null
|
||||
|
||||
await submit()
|
||||
|
||||
const payload = mockPost.mock.calls[0][1]
|
||||
expect(payload).not.toHaveProperty('category')
|
||||
})
|
||||
|
||||
it('mappe un 409 doublon de code sur errors.code + toast explicite', async () => {
|
||||
mockPost.mockRejectedValueOnce({ response: { status: 409, _data: {} } })
|
||||
const { form, errors, submit } = useProductForm()
|
||||
|
||||
Reference in New Issue
Block a user