diff --git a/src/js/applications/codelists/i18n/dictionary.js b/src/js/applications/codelists/i18n/dictionary.js index 0ffd520ab..31d45f237 100644 --- a/src/js/applications/codelists/i18n/dictionary.js +++ b/src/js/applications/codelists/i18n/dictionary.js @@ -264,7 +264,7 @@ const dictionary = { }, validCharactersProperty: { fr: (propertyName) => - `La propriété ${propertyName} possède des caractères invalid.`, + `La propriété ${propertyName} possède des caractères invalides.`, en: (propertyName) => `The property ${propertyName} has invalid characters.`, }, diff --git a/src/js/applications/codelists/utils/index.js b/src/js/applications/codelists/utils/index.js index 41f1140d3..e1d5832c8 100644 --- a/src/js/applications/codelists/utils/index.js +++ b/src/js/applications/codelists/utils/index.js @@ -9,24 +9,48 @@ export const formatLabel = (component) => { }; const CodesList = z.object({ - lastListUriSegment: z.string({ - required_error: D.mandatoryProperty(D.lastListUriSegmentTitle), - }), - lastCodeUriSegment: z.string({ - required_error: D.mandatoryProperty(D.lastCodeUriSegmentTitle), - }), - lastClassUriSegment: z.string({ - required_error: D.mandatoryProperty(D.lastClassUriSegmentTitle), - }), - id: z.string({ required_error: D.mandatoryProperty(D.idTitle) }), - labelLg1: z.string({ required_error: D.mandatoryProperty(D1.labelTitle) }), - labelLg2: z.string({ required_error: D.mandatoryProperty(D2.labelTitle) }), - creator: z.string({ required_error: D.mandatoryProperty(D.creator) }), - disseminationStatus: z.string({ - required_error: D.mandatoryProperty( - MainDictionary.disseminationStatusTitle - ), - }), + lastListUriSegment: z + .string({ + required_error: D.mandatoryProperty(D.lastListUriSegmentTitle), + }) + .trim() + .min(1, { message: D.mandatoryProperty(D.lastListUriSegmentTitle) }), + lastCodeUriSegment: z + .string({ + required_error: D.mandatoryProperty(D.lastCodeUriSegmentTitle), + }) + .trim() + .min(1, { message: D.mandatoryProperty(D.lastCodeUriSegmentTitle) }), + lastClassUriSegment: z + .string({ + required_error: D.mandatoryProperty(D.lastClassUriSegmentTitle), + }) + .trim() + .min(1, { message: D.mandatoryProperty(D.lastClassUriSegmentTitle) }), + id: z + .string({ required_error: D.mandatoryProperty(D.idTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D.idTitle) }), + labelLg1: z + .string({ required_error: D.mandatoryProperty(D1.labelTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.labelTitle) }), + labelLg2: z + .string({ required_error: D.mandatoryProperty(D2.labelTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.labelTitle) }), + creator: z + .string({ required_error: D.mandatoryProperty(D.creator) }) + .min(1, { message: D.mandatoryProperty(D.creator) }), + disseminationStatus: z + .string({ + required_error: D.mandatoryProperty( + MainDictionary.disseminationStatusTitle + ), + }) + .min(1, { + message: D.mandatoryProperty(MainDictionary.disseminationStatusTitle), + }), }); export const validateCodelist = (codelist) => formatValidation(CodesList)(codelist); @@ -36,40 +60,66 @@ const PartialCodesList = z.object({ .string({ required_error: D.mandatoryProperty(D.idTitle), }) + .trim() + .min(1, { message: D.mandatoryProperty(D.idTitle) }) .regex(/^[a-zA-Z0-9_]*$/, D.validCharactersProperty(D1.idTitle)), - parentCode: z.string({ - required_error: D.mandatoryProperty(D.parentCodelist), - }), - labelLg1: z.string({ - required_error: D.mandatoryProperty(D1.labelTitle), - }), - labelLg2: z.string({ - required_error: D.mandatoryProperty(D2.labelTitle), - }), - creator: z.string({ - required_error: D.mandatoryProperty(D.creator), - }), - disseminationStatus: z.string({ - required_error: D.mandatoryProperty( - MainDictionary.disseminationStatusTitle - ), - }), + parentCode: z + .string({ + required_error: D.mandatoryProperty(D.parentCodelist), + }) + .min(1, { message: D.mandatoryProperty(D.parentCodelist) }), + labelLg1: z + .string({ + required_error: D.mandatoryProperty(D1.labelTitle), + }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.labelTitle) }), + labelLg2: z + .string({ + required_error: D.mandatoryProperty(D2.labelTitle), + }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.labelTitle) }), + creator: z + .string({ + required_error: D.mandatoryProperty(D.creator), + }) + .min(1, { message: D.mandatoryProperty(D.creator) }), + disseminationStatus: z + .string({ + required_error: D.mandatoryProperty( + MainDictionary.disseminationStatusTitle + ), + }) + .min(1, { + message: D.mandatoryProperty(MainDictionary.disseminationStatusTitle), + }), }); export const validatePartialCodelist = (codelist) => formatValidation(PartialCodesList)(codelist); const Code = (shouldCheckDuplicate, codes) => z.object({ - code: z.string({ required_error: D.mandatoryProperty(D.idTitle) }).refine( - (value) => { - return !shouldCheckDuplicate || !codes.find((c) => c.code === value); - }, - { - message: D.ErrorDoubleCode, - } - ), - labelLg1: z.string({ required_error: D.mandatoryProperty(D1.labelTitle) }), - labelLg2: z.string({ required_error: D.mandatoryProperty(D2.labelTitle) }), + code: z + .string({ required_error: D.mandatoryProperty(D.idTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D.idTitle) }) + .refine( + (value) => { + return !shouldCheckDuplicate || !codes.find((c) => c.code === value); + }, + { + message: D.ErrorDoubleCode, + } + ), + labelLg1: z + .string({ required_error: D.mandatoryProperty(D1.labelTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.labelTitle) }), + labelLg2: z + .string({ required_error: D.mandatoryProperty(D2.labelTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.labelTitle) }), }); export const validateCode = (code, codes, updateMode) => { diff --git a/src/js/applications/datasets/datasets/edit/validation.js b/src/js/applications/datasets/datasets/edit/validation.js index d5c3760bd..89c0a7c47 100644 --- a/src/js/applications/datasets/datasets/edit/validation.js +++ b/src/js/applications/datasets/datasets/edit/validation.js @@ -5,16 +5,20 @@ import { formatValidation } from '../../../../new-architecture/utils/validation' const Dataset = z.object({ labelLg1: z .string({ required_error: D.mandatoryProperty(D1.title) }) + .trim() .min(1, { message: D.mandatoryProperty(D1.title) }), labelLg2: z .string({ required_error: D.mandatoryProperty(D2.title) }) + .trim() .min(1, { message: D.mandatoryProperty(D2.title) }), altIdentifier: z .string() .regex(/^[a-zA-Z0-9-_]+$/, { message: D.altIdError }) - .optional() - .or(z.literal('')), - creator: z.string({ required_error: D.mandatoryProperty(D1.creatorTitle) }), + .or(z.string().trim().length(0)) + .optional(), + creator: z + .string({ required_error: D.mandatoryProperty(D1.creatorTitle) }) + .min(1, { message: D.mandatoryProperty(D1.creatorTitle) }), contributor: z .string({ required_error: D.mandatoryProperty(D1.contributorTitle), @@ -23,10 +27,14 @@ const Dataset = z.object({ .nonempty({ message: D.mandatoryProperty(D1.contributorTitle), }), - disseminationStatus: z.string({ - required_error: D.mandatoryProperty(D1.disseminationStatusTitle), - }), - idSerie: z.string({ required_error: D.mandatoryProperty(D1.generatedBy) }), + disseminationStatus: z + .string({ + required_error: D.mandatoryProperty(D1.disseminationStatusTitle), + }) + .min(1, { message: D.mandatoryProperty(D1.disseminationStatusTitle) }), + idSerie: z + .string({ required_error: D.mandatoryProperty(D1.generatedBy) }) + .min(1, { message: D.mandatoryProperty(D1.generatedBy) }), }); export const validate = ({ catalogRecord, ...otherFields }) => diff --git a/src/js/applications/datasets/distributions/validation.js b/src/js/applications/datasets/distributions/validation.js index 258198309..b984ea442 100644 --- a/src/js/applications/datasets/distributions/validation.js +++ b/src/js/applications/datasets/distributions/validation.js @@ -3,13 +3,17 @@ import { z } from 'zod'; import { formatValidation } from '../../../new-architecture/utils/validation'; const Distribution = z.object({ + idDataset: z + .string({ required_error: D.mandatoryProperty(D1.datasetTitle) }) + .min(1, { message: D.mandatoryProperty(D1.datasetTitle) }), labelLg1: z .string({ required_error: D.mandatoryProperty(D1.title) }) + .trim() .min(1, { message: D.mandatoryProperty(D1.title) }), labelLg2: z .string({ required_error: D.mandatoryProperty(D2.title) }) + .trim() .min(1, { message: D.mandatoryProperty(D2.title) }), - idDataset: z.string({ required_error: D.mandatoryProperty(D1.datasetTitle) }), }); export const validate = formatValidation(Distribution); diff --git a/src/js/applications/operations/document/edition/validation.js b/src/js/applications/operations/document/edition/validation.js index 62f8876f4..5115e5464 100644 --- a/src/js/applications/operations/document/edition/validation.js +++ b/src/js/applications/operations/document/edition/validation.js @@ -4,9 +4,17 @@ import { z } from 'zod'; import { formatValidation } from '../../../../new-architecture/utils/validation'; const Base = z.object({ - labelLg1: z.string().min(1, { message: D.mandatoryProperty(D1.title) }), - labelLg2: z.string().min(1, { message: D.mandatoryProperty(D2.title) }), - lang: z.string().min(1, { message: D.requiredLang }), + labelLg1: z + .string({ required_error: D.mandatoryProperty(D1.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.title) }), + labelLg2: z + .string({ required_error: D.mandatoryProperty(D2.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.title) }), + lang: z + .string({ required_error: D.requiredLang }) + .min(1, { message: D.requiredLang }), }); const Link = Base.extend({ @@ -29,9 +37,13 @@ const File = z.object({ }); const Document = Base.extend({ - updatedDate: z.string({ - required_error: D.requiredUpdatedDate, - }), + updatedDate: z + .string({ + required_error: D.requiredUpdatedDate, + }) + .min(1, { message: D.requiredUpdatedDate }) + .nullable() + .refine((value) => value !== null, { message: D.requiredUpdatedDate }), files: z.array(File).nonempty({ message: D.requiredFile, }), diff --git a/src/js/applications/operations/families/edition/validation.js b/src/js/applications/operations/families/edition/validation.js index dbd834f7f..72ed074ac 100644 --- a/src/js/applications/operations/families/edition/validation.js +++ b/src/js/applications/operations/families/edition/validation.js @@ -3,8 +3,14 @@ import { z } from 'zod'; import { formatValidation } from '../../../../new-architecture/utils/validation'; const Family = z.object({ - prefLabelLg1: z.string().min(1, { message: D.mandatoryProperty(D1.title) }), - prefLabelLg2: z.string().min(1, { message: D.mandatoryProperty(D2.title) }), + prefLabelLg1: z + .string({ required_error: D.mandatoryProperty(D1.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.title) }), + prefLabelLg2: z + .string({ required_error: D.mandatoryProperty(D2.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.title) }), }); export const validate = formatValidation(Family); diff --git a/src/js/applications/operations/indicators/edition/validation.js b/src/js/applications/operations/indicators/edition/validation.js index 3232fc3d1..747524fbd 100644 --- a/src/js/applications/operations/indicators/edition/validation.js +++ b/src/js/applications/operations/indicators/edition/validation.js @@ -3,8 +3,14 @@ import { z } from 'zod'; import { formatValidation } from '../../../../new-architecture/utils/validation'; const Indicator = z.object({ - prefLabelLg1: z.string().min(1, { message: D.mandatoryProperty(D1.title) }), - prefLabelLg2: z.string().min(1, { message: D.mandatoryProperty(D2.title) }), + prefLabelLg1: z + .string({ required_error: D.mandatoryProperty(D1.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.title) }), + prefLabelLg2: z + .string({ required_error: D.mandatoryProperty(D2.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.title) }), creators: z .string({ required_error: D.mandatoryProperty(D.creatorTitle), diff --git a/src/js/applications/operations/operations/edition/validation.js b/src/js/applications/operations/operations/edition/validation.js index 22f948b57..7afb7e5c2 100644 --- a/src/js/applications/operations/operations/edition/validation.js +++ b/src/js/applications/operations/operations/edition/validation.js @@ -3,8 +3,6 @@ import { z } from 'zod'; import { formatValidation } from '../../../../new-architecture/utils/validation'; const Operation = z.object({ - prefLabelLg1: z.string().min(1, { message: D.mandatoryProperty(D1.title) }), - prefLabelLg2: z.string().min(1, { message: D.mandatoryProperty(D2.title) }), series: z.object( { id: z.string(), @@ -13,6 +11,14 @@ const Operation = z.object({ required_error: D.mandatoryProperty(D1.seriesTitle), } ), + prefLabelLg1: z + .string({ required_error: D.mandatoryProperty(D1.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.title) }), + prefLabelLg2: z + .string({ required_error: D.mandatoryProperty(D2.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.title) }), }); export const validate = formatValidation(Operation); diff --git a/src/js/applications/operations/operations/edition/validation.spec.js b/src/js/applications/operations/operations/edition/validation.spec.js index 37b64168c..3e8a80624 100644 --- a/src/js/applications/operations/operations/edition/validation.spec.js +++ b/src/js/applications/operations/operations/edition/validation.spec.js @@ -1,70 +1,66 @@ import { validate } from './validation'; -describe('validate', function() { - it('should return an error for prefLabelLg1', function() { +describe('validate', function () { + it('should return an error for prefLabelLg1', function () { expect( - validate({ - prefLabelLg1: '', - prefLabelLg2: 'prefLabelLg2', - series: {id: 'i'}, - }) - ).toEqual({ - errorMessage: [ - 'The property Intitulé is required.', - ], + validate({ + prefLabelLg1: '', + prefLabelLg2: 'prefLabelLg2', + series: { id: 'i' }, + }) + ).toEqual({ + errorMessage: ['The property Intitulé is required.'], fields: { prefLabelLg1: 'The property Intitulé is required.', prefLabelLg2: '', - series: '', + series: '', }, }); }); - it('should return an error for prefLabelLg2', function() { + it('should return an error for prefLabelLg2', function () { expect( - validate({ - prefLabelLg1: 'prefLabelLg1', - prefLabelLg2: '', - series: {id: 'i'}, - }) - ).toEqual({ - errorMessage: [ - 'The property Title is required.', - ], + validate({ + prefLabelLg1: 'prefLabelLg1', + prefLabelLg2: '', + series: { id: 'i' }, + }) + ).toEqual({ + errorMessage: ['The property Title is required.'], fields: { prefLabelLg1: '', prefLabelLg2: 'The property Title is required.', - series: '', + series: '', }, }); }); - it('should return an error for series', function() { + it('should return an error for series', function () { expect( - validate({ - prefLabelLg1: 'prefLabelLg1', - prefLabelLg2: 'prefLabelLg2' - }) - ).toEqual({ + validate({ + prefLabelLg1: 'prefLabelLg1', + prefLabelLg2: 'prefLabelLg2', + }) + ).toEqual({ errorMessage: ['The property Séries is required.'], fields: { + series: 'The property Séries is required.', prefLabelLg1: '', prefLabelLg2: '', - series: 'The property Séries is required.' }, }); }); - it('should return no error', function() { + it('should return no error', function () { expect( validate({ - prefLabelLg1: 'prefLabelLg1', - prefLabelLg2: 'prefLabelLg2', - series: {id: 'i'}, - }) + prefLabelLg1: 'prefLabelLg1', + prefLabelLg2: 'prefLabelLg2', + series: { id: 'i' }, + }) ).toEqual({ errorMessage: [], fields: { prefLabelLg1: '', prefLabelLg2: '', - series: '' + series: '', }, }); }); diff --git a/src/js/applications/operations/series/edition/validation.js b/src/js/applications/operations/series/edition/validation.js index 90abdba19..1727acd63 100644 --- a/src/js/applications/operations/series/edition/validation.js +++ b/src/js/applications/operations/series/edition/validation.js @@ -3,16 +3,6 @@ import { z } from 'zod'; import { formatValidation } from '../../../../new-architecture/utils/validation'; let Serie = z.object({ - prefLabelLg1: z.string().min(1, { message: D.mandatoryProperty(D1.title) }), - prefLabelLg2: z.string().min(1, { message: D.mandatoryProperty(D2.title) }), - creators: z - .string({ - required_error: D.mandatoryProperty(D.creatorTitle), - }) - .array() - .nonempty({ - message: D.mandatoryProperty(D.creatorTitle), - }), family: z.object( { id: z.string(), @@ -21,6 +11,22 @@ let Serie = z.object({ required_error: D.mandatoryProperty(D1.familyTitle), } ), + prefLabelLg1: z + .string({ required_error: D.mandatoryProperty(D1.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.title) }), + prefLabelLg2: z + .string({ required_error: D.mandatoryProperty(D2.title) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.title) }), + creators: z + .string({ + required_error: D.mandatoryProperty(D.creatorTitle), + }) + .array() + .nonempty({ + message: D.mandatoryProperty(D.creatorTitle), + }), }); export const listOfExtraMandatoryFields = ( diff --git a/src/js/applications/operations/series/edition/validation.spec.js b/src/js/applications/operations/series/edition/validation.spec.js index 67b59d167..4936419a7 100644 --- a/src/js/applications/operations/series/edition/validation.spec.js +++ b/src/js/applications/operations/series/edition/validation.spec.js @@ -1,20 +1,18 @@ import { validate } from './validation'; -describe('validation', function() { - it('should return an error for prefLabelLg1', function() { +describe('validation', function () { + it('should return an error for prefLabelLg1', function () { expect( validate({ prefLabelLg1: '', prefLabelLg2: 'prefLabelLg2', creators: ['creator'], - family: {id: 'i'}, + family: { id: 'i' }, accrualPeriodicityCode: 'accrualPeriodicityCode', typeCode: 'typeCode', }) ).toEqual({ - errorMessage: [ - 'The property Intitulé is required.', - ], + errorMessage: ['The property Intitulé is required.'], fields: { prefLabelLg1: 'The property Intitulé is required.', prefLabelLg2: '', @@ -25,20 +23,18 @@ describe('validation', function() { }, }); }); - it('should return an error for prefLabelLg2', function() { + it('should return an error for prefLabelLg2', function () { expect( validate({ prefLabelLg1: 'prefLabelLg1', prefLabelLg2: '', creators: ['creator'], - family: {id: 'i'}, + family: { id: 'i' }, accrualPeriodicityCode: 'accrualPeriodicityCode', typeCode: 'typeCode', }) ).toEqual({ - errorMessage: [ - 'The property Title is required.', - ], + errorMessage: ['The property Title is required.'], fields: { prefLabelLg1: '', prefLabelLg2: 'The property Title is required.', @@ -49,7 +45,7 @@ describe('validation', function() { }, }); }); - it('should return an error for prefLabelLg1, prefLabelLg2, family and creators', function() { + it('should return an error for prefLabelLg1, prefLabelLg2, family and creators', function () { expect( validate({ prefLabelLg1: '', @@ -59,27 +55,27 @@ describe('validation', function() { }) ).toEqual({ errorMessage: [ + 'The property Famille is required.', 'The property Intitulé is required.', 'The property Title is required.', 'The property Owner is required.', - 'The property Famille is required.', ], fields: { + family: 'The property Famille is required.', prefLabelLg1: 'The property Intitulé is required.', prefLabelLg2: 'The property Title is required.', creators: 'The property Owner is required.', - family: 'The property Famille is required.', accrualPeriodicityCode: '', typeCode: '', }, }); }); - it('should return no error', function() { + it('should return no error', function () { expect( validate({ prefLabelLg1: 'prefLabelLg2', prefLabelLg2: 'prefLabelLg2', - family: {id: 'i'}, + family: { id: 'i' }, creators: ['creator'], accrualPeriodicityCode: 'accrualPeriodicityCode', typeCode: 'typeCode', diff --git a/src/js/applications/structures/components/edition/validation.js b/src/js/applications/structures/components/edition/validation.js index e4138cdb0..6aad59806 100644 --- a/src/js/applications/structures/components/edition/validation.js +++ b/src/js/applications/structures/components/edition/validation.js @@ -5,12 +5,15 @@ import { formatValidation } from '../../../../new-architecture/utils/validation' const Component = z.object({ identifiant: z .string({ required_error: D.mandatoryProperty(D.idTitle) }) + .trim() .min(1, { message: D.mandatoryProperty(D.idTitle) }), labelLg1: z .string({ required_error: D.mandatoryProperty(D1.labelTitle) }) + .trim() .min(1, { message: D.mandatoryProperty(D1.labelTitle) }), labelLg2: z .string({ required_error: D.mandatoryProperty(D2.labelTitle) }) + .trim() .min(1, { message: D.mandatoryProperty(D2.labelTitle) }), type: z .string({ required_error: D.mandatoryProperty(D.type) }) diff --git a/src/js/applications/structures/edition/validation.js b/src/js/applications/structures/edition/validation.js index f6055e0e9..3ba19dbe0 100644 --- a/src/js/applications/structures/edition/validation.js +++ b/src/js/applications/structures/edition/validation.js @@ -3,9 +3,18 @@ import { z } from 'zod'; import { formatValidation } from '../../../new-architecture/utils/validation'; const Structure = z.object({ - identifiant: z.string().min(1, { message: D.mandatoryProperty(D.idTitle) }), - labelLg1: z.string().min(1, { message: D.mandatoryProperty(D1.labelTitle) }), - labelLg2: z.string().min(1, { message: D.mandatoryProperty(D2.labelTitle) }), + identifiant: z + .string({ required_error: D.mandatoryProperty(D.idTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D.idTitle) }), + labelLg1: z + .string({ required_error: D.mandatoryProperty(D1.labelTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D1.labelTitle) }), + labelLg2: z + .string({ required_error: D.mandatoryProperty(D2.labelTitle) }) + .trim() + .min(1, { message: D.mandatoryProperty(D2.labelTitle) }), }); export const validate = formatValidation(Structure);