Skip to content
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

Closed
wants to merge 22 commits into from

Conversation

PierreVasseur
Copy link
Contributor

No description provided.

@PierreVasseur PierreVasseur changed the base branch from acceptance to feat/bump-node February 1, 2024 09:20
@PierreVasseur PierreVasseur linked an issue Feb 2, 2024 that may be closed by this pull request

export function validate({ prefLabelLg1, prefLabelLg2 }) {
const formatValidation = (ZodObject) => (values) => {
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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({
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture d'écran 2024-02-05 150933

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

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

Copy link
Contributor Author

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({
Copy link
Collaborator

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({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@EmmanuelDemey EmmanuelDemey changed the base branch from feat/bump-node to main February 12, 2024 08:12
@EmmanuelDemey EmmanuelDemey changed the base branch from main to feat/bump-node February 12, 2024 08:13
@@ -1,2 +1,2 @@
REACT_APP_API_BASE_HOST = 'https://gestion-metadonnees-api.developpement2.insee.fr'
Copy link
Collaborator

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

Copy link
Contributor Author

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({
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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)

{}
)
};
console.log(fields)
Copy link
Collaborator

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 ?

@@ -0,0 +1,38 @@
export const formatValidation = (ZodObject) => (values) => {
const ZodError = ZodObject.safeParse(values);
console.log(ZodError)
Copy link
Collaborator

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 ?

@EmmanuelDemey
Copy link
Collaborator

Cette PR is outdated, and will be reopened based on the main branch

@PierreVasseur PierreVasseur deleted the feat/use-zod-in-validation branch February 29, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants