diff --git a/package.json b/package.json index 8cead469d..d41861f90 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "react-hook-form": "^7.49.2", "react-router-dom": "^6.21.0", "react-swipeable-views": "^0.14.0", - "zod": "^3.22.4" + "zod": "^3.23.8" }, "scripts": { "dev": "vite", diff --git a/src/utils/schemas.test.js b/src/utils/schemas.test.js index 9c991aefc..eb0a83de4 100644 --- a/src/utils/schemas.test.js +++ b/src/utils/schemas.test.js @@ -1,6 +1,76 @@ +import { + communicationMediumEnum, + communicationReasonEnum, + communicationTypeEnum, +} from 'utils/enum/CommunicationEnums'; import { describe, it } from 'vitest'; -import { userSchema } from './schemas'; +import { communicationSchema, recipientSchema, userSchema } from './schemas'; + describe('schemas', () => { + describe('recipientSchema', () => { + test.each([ + [{}, false], + [{ title: 'MISS' }, false], + [{ title: 'MISS', firstName: 'firstName' }, false], + [{ title: 'MISS', firstName: 'firstName', lastName: 'lastName' }, false], + [ + { title: 'MISS', firstName: 'firstName', lastName: 'lastName', postCode: 'postCode' }, + false, + ], + [ + { + title: 'MISS', + firstName: 'firstName', + lastName: 'lastName', + postCode: 'postCode', + cityName: 'cityName', + }, + true, + ], + ])('expect %o validity -> %s', (data, isValid) => { + const expectation = expect(() => recipientSchema.parse({ ...data })); + if (isValid) { + expectation.not.toThrow(); + } else { + expectation.toThrow(); + } + }); + }); + + describe('communicationSchema', () => { + test.each([ + [{}, false], + [ + { + medium: communicationMediumEnum.MEDIUM_MAIL.type, + }, + false, + ], + [ + { + medium: communicationMediumEnum.MEDIUM_MAIL.type, + type: communicationTypeEnum.COMMUNICATION_NOTICE.type, + }, + false, + ], + [ + { + medium: communicationMediumEnum.MEDIUM_MAIL.type, + type: communicationTypeEnum.COMMUNICATION_NOTICE.type, + reason: communicationReasonEnum.UNREACHABLE.type, + }, + true, + ], + ])('expect %o validity -> %s', (data, isValid) => { + const expectation = expect(() => communicationSchema.parse({ ...data })); + if (isValid) { + expectation.not.toThrow(); + } else { + expectation.toThrow(); + } + }); + }); + describe('userSchema', () => { const validUser = { title: 'MISTER', diff --git a/yarn.lock b/yarn.lock index 93fd05196..631ca23ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6366,7 +6366,7 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -zod@^3.22.4: - version "3.22.4" - resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" - integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg== +zod@^3.23.8: + version "3.23.8" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d" + integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==