From 6d024218873db9032726e31c94803e11dac6d72b Mon Sep 17 00:00:00 2001 From: mino323 <86011419+mino323@users.noreply.github.com> Date: Sat, 19 Mar 2022 10:00:29 +0200 Subject: [PATCH 1/2] edits helpers for modules in forms --- helpers/admin/adminHelpers.ts | 4 ++++ helpers/formValidation.tsx | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/helpers/admin/adminHelpers.ts b/helpers/admin/adminHelpers.ts index ff70ad1ff..00a66a1e3 100644 --- a/helpers/admin/adminHelpers.ts +++ b/helpers/admin/adminHelpers.ts @@ -58,6 +58,10 @@ export const makeGraphqlVariable = (options: any, addProp?: any) => { res.id = parseInt(res.id ? res.id + '' : '') } + if (res.hasOwnProperty('lessonId')) { + res.lessonId = parseInt(res.lessonId ? res.lessonId + '' : '') + } + if (addProp) { const keys = Object.keys(addProp) keys.forEach((propertyName: string) => { diff --git a/helpers/formValidation.tsx b/helpers/formValidation.tsx index 43a176033..34ff7630b 100644 --- a/helpers/formValidation.tsx +++ b/helpers/formValidation.tsx @@ -37,6 +37,15 @@ const lessonSchema = Yup.object({ chatUrl: Yup.string() }) +const moduleSchema = Yup.object({ + lessonId: Yup.number() + .required('Required') + .typeError('Numbers only') + .min(0, 'Positive numbers only'), + name: Yup.string(), + content: Yup.string() +}) + const signupValidation = Yup.object({ email: Yup.string().email('Invalid email address').required('Required'), username: Yup.string() @@ -109,5 +118,6 @@ export { loginValidation, passwordValidation, confirmPasswordValidation, - resetPasswordValidation + resetPasswordValidation, + moduleSchema } From 6e8a9c464070415ac9b1159a4ccc45dfd418966e Mon Sep 17 00:00:00 2001 From: mino323 <86011419+mino323@users.noreply.github.com> Date: Sat, 19 Mar 2022 10:31:05 +0200 Subject: [PATCH 2/2] updates admin helper test --- helpers/admin/adminHelpers.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/helpers/admin/adminHelpers.test.js b/helpers/admin/adminHelpers.test.js index 84d943ac1..035cd3737 100644 --- a/helpers/admin/adminHelpers.test.js +++ b/helpers/admin/adminHelpers.test.js @@ -66,20 +66,22 @@ describe('adminHelper function', () => { type: 'DROP_DOWN', value: [{ title: 'dragon' }] }, - { title: 'order', value: '5' } + { title: 'order', value: '5' }, + { title: 'lessonId', value: '1' } ], { pop: 'open' } ) expect(res).toEqual({ - variables: { deem: 'dragon', id: 4, order: 5, pop: 'open' } + variables: { deem: 'dragon', id: 4, order: 5, pop: 'open', lessonId: 1 } }) const res2 = adminHelpers.makeGraphqlVariable([ { title: 'order', value: '' }, - { title: 'id', value: '' } + { title: 'id', value: '' }, + { title: 'lessonId', value: '' } ]) expect(res2).toEqual({ - variables: { order: undefined, id: NaN } + variables: { order: undefined, id: NaN, lessonId: NaN } }) })