All files / src/features/GiveOnboarding/pages/Bank/Connect schema.ts

50% Statements 3/6
100% Branches 0/0
25% Functions 1/4
50% Lines 3/6

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              10x 10x   10x                                                
import * as Yup from "yup";
import {
  createBankAccountValidator,
  createRoutingNumberValidator,
} from "@validation/fields";
import { VALIDATION_MESSAGES } from "@validation/messages";
 
export const getSchema = ({ firstAccount }: { firstAccount: any }) => {
  const hasLast4 = Boolean(firstAccount?.bankDataAux.numberLast4);
 
  return Yup.object({
    type: Yup.string().required(VALIDATION_MESSAGES.REQUIRED),
    // Only enforce when account isn't already approved
 
    name: Yup.string().required(VALIDATION_MESSAGES.REQUIRED),
    accountNumber: Yup.string().when([], {
      is: () => hasLast4,
      then: () => Yup.string(),
      otherwise: () =>
        createBankAccountValidator({
          required: true,
          requiredMessage: VALIDATION_MESSAGES.REQUIRED,
          invalidMessage: VALIDATION_MESSAGES.INVALID_ACCOUNT_NUMBER,
        }),
    }),
    routingNumber: createRoutingNumberValidator({
      required: true,
      requiredMessage: VALIDATION_MESSAGES.REQUIRED,
      invalidMessage: VALIDATION_MESSAGES.INVALID_ROUTING_NUMBER,
    }),
 
    notes: Yup.string(),
  });
};