Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates formValidation and adminHelpers #1617

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions helpers/admin/adminHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})
})

Expand Down
4 changes: 4 additions & 0 deletions helpers/admin/adminHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const makeGraphqlVariable = (options: any, addProp?: any) => {
res.id = parseInt(res.id ? res.id + '' : '')
}

if (res.hasOwnProperty('lessonId')) {
songz marked this conversation as resolved.
Show resolved Hide resolved
res.lessonId = parseInt(res.lessonId ? res.lessonId + '' : '')
}

if (addProp) {
const keys = Object.keys(addProp)
keys.forEach((propertyName: string) => {
Expand Down
12 changes: 11 additions & 1 deletion helpers/formValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ const lessonSchema = Yup.object({
chatUrl: Yup.string()
})

const moduleSchema = Yup.object({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moduleSchemaValidation to match the file naming pattern of name+vValidation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good idea to keep things consistent.

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()
Expand Down Expand Up @@ -109,5 +118,6 @@ export {
loginValidation,
passwordValidation,
confirmPasswordValidation,
resetPasswordValidation
resetPasswordValidation,
moduleSchema
}