MostOfLuck/frontend-project-12

View on GitHub
frontend/src/validation/signUpSchema.js

Summary

Maintainability
A
0 mins
Test Coverage
import * as Yup from 'yup';

const signupSchema = (
  userNameLength,
  passwordLength,
  requiredField,
  passwordMatching,
) => Yup.object().shape({
  username: Yup
    .string()
    .trim()
    .min(3, userNameLength)
    .max(20, userNameLength)
    .required(requiredField),
  password: Yup
    .string()
    .min(6, passwordLength)
    .trim()
    .required(requiredField),
  passwordConfirmation: Yup
    .string()
    .trim()
    .oneOf([Yup.ref('password')], passwordMatching)
    .required(requiredField),
});

export default signupSchema;