Skip to content

Commit

Permalink
Feat/validation codelist (#404) (#510)
Browse files Browse the repository at this point in the history
* feat: make contributor editable for a structure #362

* Particla Code List identifier should contain only a-zA-Z0-9_ #382
  • Loading branch information
EmmanuelDemey authored Nov 21, 2023
1 parent 8a6d4bc commit 132c305
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/codelists/src/i18n/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ const dictionary = {
fr: propertyName => `La propriété <strong>${propertyName}</strong> est obligatoire.`,
en: propertyName => `The property <strong>${propertyName}</strong> is required.`
},
validCharactersProperty: {
fr: propertyName => `La propriété <strong>${propertyName}</strong> possède des caractères invalid.`,
en: propertyName => `The property <strong>${propertyName}</strong> has invalid characters.`
},
errors: {
GlobalClientSideErrorBloc: {
fr: 'Vous avez des erreurs dans ce formulaire.',
Expand Down
4 changes: 4 additions & 0 deletions packages/codelists/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ export const validatePartialCodelist = (codelist) => {
if(!codelist.id){
errorMessage.push(D.mandatoryProperty(D.idTitle));
fields.id = D.mandatoryProperty(D.idTitle);
} else if(!/^[a-zA-Z0-9_]*$/.test(codelist.id)){
errorMessage.push(D.validCharactersProperty(D1.idTitle));
fields.id = D.validCharactersProperty(D1.idTitle);
}


if(!codelist.parentCode){
errorMessage.push(D.mandatoryProperty(D.parentCodelist));
fields.parentCode = D.mandatoryProperty(D.parentCodelist);
Expand Down
34 changes: 34 additions & 0 deletions packages/codelists/src/utils/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { validatePartialCodelist } from './index';

describe('validatePartialCodelist', () => {
it('should return no error', () => {
expect(validatePartialCodelist({
id: 'id',
parentCode: 'parentCode',
labelLg1: 'labelLg1',
labelLg2: 'labelLg2',
creator: 'creator',
disseminationStatus: 'disseminationStatus',
})).toEqual({
errorMessage: [],
fields: {}
})
})
it('should return the error if the labelLg1 and labelLg2 contain unacceptable characters', () => {
expect(validatePartialCodelist({
id: 'i d',
parentCode: 'parentCode',
labelLg1: 'labelLg1',
labelLg2: 'labelLg2',
creator: 'creator',
disseminationStatus: 'disseminationStatus',
})).toEqual({
errorMessage: [
'The property <strong>Identifiant</strong> has invalid characters.'
],
fields: {
id: 'The property <strong>Identifiant</strong> has invalid characters.'
}
})
})
})

0 comments on commit 132c305

Please sign in to comment.