All files / src/features/GiveOnboarding/pages/Business/Profile schema.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                  10x                         24x                     4x                                
import { object, string, mixed } from "yup";
import { TinType } from "@features/GiveOnboarding/types/form";
import {
  createPhoneValidator,
  createBusinessDateValidator,
  createTaxIdValidator,
} from "@validation/fields";
import { VALIDATION_MESSAGES } from "@validation/messages";
 
export const businessProfileSchema = object().shape({
  name: string().required(VALIDATION_MESSAGES.REQUIRED),
  DBA: string(),
  businessOpenedAt: createBusinessDateValidator({
    required: true,
    allowFuture: false,
    maxYearsInPast: 500,
    requiredMessage: VALIDATION_MESSAGES.REQUIRED,
  }),
  // tinType: mixed<TinType>().oneOf(["ssn", "ein"]),
  taxIDNumber: string().when("tinType", {
    is: "ein",
    then: () =>
      createTaxIdValidator({
        type: "EIN",
        required: true,
        requiredMessage: VALIDATION_MESSAGES.REQUIRED,
        invalidMessage: "Please enter a valid Tax ID",
        skipUntilTouched: true,
      }),
  }),
  ssn: string().when("tinType", {
    is: "ssn",
    then: () =>
      createTaxIdValidator({
        type: "SSN",
        required: true,
        requiredMessage: VALIDATION_MESSAGES.REQUIRED,
        invalidMessage: "Please enter a valid SSN",
        skipUntilTouched: true,
      }),
  }),
  type: string().required(VALIDATION_MESSAGES.REQUIRED),
  ownershipType: string().required(VALIDATION_MESSAGES.REQUIRED),
  phoneNumber: createPhoneValidator({
    required: true,
    requiredMessage: VALIDATION_MESSAGES.REQUIRED,
    invalidMessage: VALIDATION_MESSAGES.INVALID_PHONE,
  }),
});