-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/use zod in validation #562
Conversation
app/src/js/applications/operations/families/edition/validation.js
Outdated
Show resolved
Hide resolved
|
||
export function validate({ prefLabelLg1, prefLabelLg2 }) { | ||
const formatValidation = (ZodObject) => (values) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peux tu mettre cette fonction dans un fichier spécifique au niveau global du module app ? dans un fichier utils/validation.js par exemple ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
@@ -2,7 +2,7 @@ import { validate } from './validation'; | |||
|
|||
describe('validation', function() { | |||
it('should return an error for prefLabelLg1', function() { | |||
expect(validate({ prefLabelLg2: 'prefLabelLg2' })).toEqual({ | |||
expect(validate({ prefLabelLg1: '', prefLabelLg2: 'prefLabelLg2' })).toEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que tu dois gérer un TU dans le cas ou ce n'est pas défini et le cas ou c'est une chaine vide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je crois que le cas où ce n'est pas défini n'arrive jamais
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
les champs sont par défaut des listes vides avant même de passer par la validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
et j'ai vérifié, ça a l'air impossible d'écraser cette valeur :
- si on ne touche pas au champ => onChange non déclenché donc la valeur empty string est conservée
- si on touche au champ => n'importe quel input est converti en string (même vide) donc pas de undefined et le test fonctionne bien sur un objet string
@@ -11,7 +11,7 @@ describe('validation', function() { | |||
}); | |||
}); | |||
it('should return an error for prefLabelLg2', function() { | |||
expect(validate({ prefLabelLg1: 'prefLabelLg1' })).toEqual({ | |||
expect(validate({ prefLabelLg1: 'prefLabelLg1', prefLabelLg2: '' })).toEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
@@ -20,7 +20,7 @@ describe('validation', function() { | |||
}); | |||
}); | |||
it('should return an error for prefLabelLg1 and prefLabelLg2', function() { | |||
expect(validate({ })).toEqual({ | |||
expect(validate({ prefLabelLg1: '', prefLabelLg2: '' })).toEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
@@ -1,2 +1,2 @@ | |||
REACT_APP_API_BASE_HOST = 'https://gestion-metadonnees-api.developpement2.insee.fr' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peux tu éviter de comiter ce fichier à chaque fois ? garde la valeur par defaut http://localhost:6969 de mémoire
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes pardon
errorMessage, | ||
}; | ||
} | ||
const Serie = z.object({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty ne gère pas la propriété listOfExtraMandatoryFields. C'est voulu ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En fait elle contient juste les propriétés typeCode et accrualPeriodicityCode que je gère individuellement.
Je n'ai juste pas compris l'utilité de listOfExtraMandatoryFields (mais je l'ai gardée car on exporte isMandatoryField qui en dépend)
app/src/js/utils/validation.js
Outdated
{} | ||
) | ||
}; | ||
console.log(fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peux tu supprimer ce console.log ?
app/src/js/utils/validation.js
Outdated
@@ -0,0 +1,38 @@ | |||
export const formatValidation = (ZodObject) => (values) => { | |||
const ZodError = ZodObject.safeParse(values); | |||
console.log(ZodError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peux tu supprimer ce console.log ?
Cette PR is outdated, and will be reopened based on the main branch |
No description provided.