fix(commercial) : ne sauter que les blocs contact/RIB totalement vides (bloc partiel sans nom -> 422 inline, ERP-110)
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m49s
Pull Request — Quality gate / Frontend (lint + Vitest + build) (pull_request) Successful in 1m16s

This commit is contained in:
Matthieu
2026-06-04 12:01:14 +02:00
parent 41d391eebf
commit f407c3d46a
4 changed files with 131 additions and 12 deletions
@@ -7,11 +7,27 @@ import {
hasAtLeastOneValidContact,
isBankRequiredForPaymentType,
isBillingEmailRequired,
isBlankRow,
isContactBlank,
isContactNamed,
isRibBlank,
isRibRequiredForPaymentType,
type ContactDraft,
type ContactFillableDraft,
} from '../clientFormRules'
/** Bloc contact totalement vide (amorce par defaut). */
function blankContact(): ContactFillableDraft {
return {
firstName: null,
lastName: null,
jobTitle: null,
phonePrimary: null,
phoneSecondary: null,
email: null,
}
}
describe('buildClientFormTabKeys (gating onglet Comptabilite + onglets edit-only)', () => {
it('inclut l onglet accounting si l utilisateur a accounting.view', () => {
expect(buildClientFormTabKeys(true)).toContain('accounting')
@@ -59,6 +75,49 @@ describe('isContactNamed (RG-1.05)', () => {
})
})
describe('isBlankRow (primitive : toutes les valeurs vides)', () => {
it('vrai si toutes les valeurs sont nulles / vides / espaces', () => {
expect(isBlankRow([null, undefined, '', ' '])).toBe(true)
expect(isBlankRow([])).toBe(true)
})
it('faux des qu une valeur porte un caractere non-espace', () => {
expect(isBlankRow([null, 'x', ''])).toBe(false)
})
})
describe('isRibBlank (bloc RIB totalement vide vs partiellement rempli)', () => {
it('vrai si label / bic / iban sont tous vides', () => {
expect(isRibBlank({ label: null, bic: null, iban: null })).toBe(true)
expect(isRibBlank({ label: ' ', bic: '', iban: null })).toBe(true)
})
it('faux si un IBAN seul est saisi (bloc a soumettre -> 422 NotBlank inline)', () => {
expect(isRibBlank({ label: null, bic: null, iban: 'FR1420041010050500013M02606' })).toBe(false)
})
it('faux si seul le libelle est saisi', () => {
expect(isRibBlank({ label: 'Compte courant', bic: null, iban: null })).toBe(false)
})
})
describe('isContactBlank (bloc totalement vide vs partiellement rempli)', () => {
it('vrai si aucun champ saisissable n est rempli', () => {
expect(isContactBlank(blankContact())).toBe(true)
expect(isContactBlank({ ...blankContact(), firstName: ' ', email: '' })).toBe(true)
})
it('faux si un email seul est saisi (bloc a soumettre -> 422 RG-1.05 inline)', () => {
expect(isContactBlank({ ...blankContact(), email: 'jean@acme.fr' })).toBe(false)
})
it('faux si seul un telephone, une fonction ou un nom est saisi', () => {
expect(isContactBlank({ ...blankContact(), phonePrimary: '0612345678' })).toBe(false)
expect(isContactBlank({ ...blankContact(), jobTitle: 'Directeur' })).toBe(false)
expect(isContactBlank({ ...blankContact(), firstName: 'Alice' })).toBe(false)
})
})
describe('hasAtLeastOneValidContact (RG-1.14)', () => {
it('faux sur une liste vide', () => {
expect(hasAtLeastOneValidContact([])).toBe(false)