From 9a76a227105296eb45162495e9ca7a83f2d6077d Mon Sep 17 00:00:00 2001 From: Fredrik Bolmsten Date: Fri, 7 Nov 2025 14:25:06 +0100 Subject: [PATCH 1/2] removed unused user attributes --- packages/validation/src/User/index.ts | 85 --------------------------- 1 file changed, 85 deletions(-) diff --git a/packages/validation/src/User/index.ts b/packages/validation/src/User/index.ts index b1a6a4d..e298d0b 100644 --- a/packages/validation/src/User/index.ts +++ b/packages/validation/src/User/index.ts @@ -28,7 +28,6 @@ export const createUserValidationSchema = Yup.object().shape({ firstname: Yup.string().required().min(2).max(50), preferredname: Yup.string().notRequired().max(50), lastname: Yup.string().required().min(2).max(50), - gender: Yup.string().required(), user_title: Yup.string().required(), email: Yup.string().email().required(), password: passwordValidationSchema, @@ -41,75 +40,16 @@ export const createUserValidationSchema = Yup.object().shape({ ), }) .notRequired(), - birthdate: Yup.date() - .min(new Date(1900, 1, 1), 'You are not that old') - .test('DOB', 'You must be at least 18 years old', (value) => { - // to keep the current behavior after @types/yup upgrade: - // if value is `null` or `undefined` return true explicitly - // because new Date(null | undefined) evaluates to `Invalid date` - // which return NaN for getFullYear() - // and Number - NaN < 18 evaluates to false - if (!value) { - return true; - } - - const dateOfBirth = new Date(value); - const dateNow = new Date(); - - if (dateNow.getFullYear() - dateOfBirth.getFullYear() < 18) { - return false; - } else { - return true; - } - }) - .required('Please specify your birth date'), institutionId: Yup.number().required(), - department: Yup.string().min(2).max(50).required(), - position: Yup.string().min(2).max(50).required(), - telephone: Yup.string() - .min(2) - .max(30) - .matches(phoneRegExp, 'telephone number is not valid') - .required(), }); export const updateUserValidationSchema = Yup.object().shape({ firstname: Yup.string().min(2).max(50).required(), preferredname: Yup.string().notRequired().max(50), lastname: Yup.string().min(2).max(50).required(), - gender: Yup.string().required(), user_title: Yup.string().required(), email: Yup.string().email().required(), - birthdate: Yup.date() - .min(new Date(1900, 1, 1), 'You are not that old') - .test('DOB', 'You must be at least 18 years old', (value) => { - // to keep the current behavior after @types/yup upgrade: - // if value is `null` or `undefined` return true explicitly - // because new Date(null | undefined) evaluates to `Invalid date` - // which return NaN for getFullYear() - // and Number - NaN < 18 evaluates to false - if (!value) { - return true; - } - - const dateOfBirth = new Date(value); - const dateNow = new Date(); - - if (dateNow.getFullYear() - dateOfBirth.getFullYear() < 18) { - return false; - } else { - return true; - } - }) - .required('Please specify your birth date'), institutionId: Yup.number().required(), - department: Yup.string().min(2).max(50).required(), - position: Yup.string().min(2).max(50).required(), - telephone: Yup.string() - .min(2) - .max(30) - .matches(phoneRegExp, 'telephone number is not valid') - .required(), }); export const updateUserValidationBackendSchema = Yup.object().shape({ @@ -117,34 +57,9 @@ export const updateUserValidationBackendSchema = Yup.object().shape({ firstname: Yup.string().min(2).max(50).notRequired(), preferredname: Yup.string().notRequired().max(50), lastname: Yup.string().min(2).max(50).notRequired(), - gender: Yup.string().notRequired(), user_title: Yup.string().notRequired(), email: Yup.string().email().notRequired(), - birthdate: Yup.date() - .min(new Date(1900, 1, 1), 'You are not that old') - .test('DOB', 'You must be at least 18 years old', (value) => { - if (!value) { - return true; - } - - const dateOfBirth = new Date(value); - const dateNow = new Date(); - - if (dateNow.getFullYear() - dateOfBirth.getFullYear() < 18) { - return false; - } else { - return true; - } - }) - .notRequired(), institutionId: Yup.number().notRequired(), - department: Yup.string().min(2).max(50).notRequired(), - position: Yup.string().min(2).max(50).notRequired(), - telephone: Yup.string() - .min(2) - .max(30) - .matches(phoneRegExp, 'telephone number is not valid') - .notRequired(), }); export const updateUserRolesValidationSchema = Yup.object().shape({ From 28a8b931a3573990776c861dd99f93177367ac56 Mon Sep 17 00:00:00 2001 From: Fredrik Bolmsten Date: Fri, 7 Nov 2025 14:33:24 +0100 Subject: [PATCH 2/2] remove test for birthdate --- package-lock.json | 4 +-- packages/validation/src/Review/index.ts | 3 +- packages/validation/src/User/index.spec.ts | 38 ---------------------- 3 files changed, 3 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1f7a7a3..5654a47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18788,7 +18788,7 @@ }, "packages/message-broker": { "name": "@user-office-software/duo-message-broker", - "version": "1.7.0", + "version": "1.8.0", "license": "ISC", "dependencies": { "@types/amqplib": "^0.10.1", @@ -33099,4 +33099,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/validation/src/Review/index.ts b/packages/validation/src/Review/index.ts index 50f1331..0746d39 100644 --- a/packages/validation/src/Review/index.ts +++ b/packages/validation/src/Review/index.ts @@ -22,8 +22,7 @@ const proposalFapReviewCommentValidationSchema = () => { export const proposalGradeValidationSchema = Yup.object().shape({ comment: proposalFapReviewCommentValidationSchema(), - grade: Yup.string() - .required(), + grade: Yup.string().required(), }); export const proposalTechnicalReviewValidationSchema = Yup.object().shape({ diff --git a/packages/validation/src/User/index.spec.ts b/packages/validation/src/User/index.spec.ts index 2b55805..61c04f5 100644 --- a/packages/validation/src/User/index.spec.ts +++ b/packages/validation/src/User/index.spec.ts @@ -139,65 +139,27 @@ describe('User validation schemas', () => { const validData = { firstname: 'John', lastname: 'Doe', - gender: 'male', user_title: 'Mr', email: 'john.doe@example.com', password: 'Password123', confirmPassword: 'Password123', - birthdate: new Date(1990, 1, 1), institutionId: 1, - department: 'Research', - position: 'Researcher', - telephone: '+1234567890', }; await expect( UserValidation.createUserValidationSchema.validate(validData) ).resolves.toMatchObject(validData); }); - it('should fail when user is under 18', async () => { - const today = new Date(); - const underageDate = new Date( - today.getFullYear() - 17, - today.getMonth(), - today.getDate() - ); - - const invalidData = { - firstname: 'John', - lastname: 'Doe', - gender: 'male', - user_title: 'Mr', - email: 'john.doe@example.com', - password: 'Password123', - confirmPassword: 'Password123', - birthdate: underageDate, - institutionId: 1, - department: 'Research', - position: 'Researcher', - telephone: '+1234567890', - }; - - await expect( - UserValidation.createUserValidationSchema.validate(invalidData) - ).rejects.toThrow('You must be at least 18 years old'); - }); - it('should validate with optional preferredname', async () => { const validData = { firstname: 'John', lastname: 'Doe', preferredname: 'Johnny', - gender: 'male', user_title: 'Mr', email: 'john.doe@example.com', password: 'Password123', confirmPassword: 'Password123', - birthdate: new Date(1990, 1, 1), institutionId: 1, - department: 'Research', - position: 'Researcher', - telephone: '+1234567890', }; await expect(