All files / src/utils bankAccountUtils.ts

58.33% Statements 7/12
41.66% Branches 5/12
100% Functions 1/1
66.66% Lines 6/9

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                      53x           2x   2x   2x                 2x 2x    
import { VALIDATION_MESSAGES } from "@validation/messages";
import { BANK_ACCOUNT_NUMBER_REGEX } from "@validation/regex";
import { UseFormSetError } from "react-hook-form";
 
type ValidateBANumberFunctionParam = {
  accountNumber: string | undefined;
  defaultAccountNumber: string | undefined;
  setError?: UseFormSetError<any>;
  isForceError?: React.MutableRefObject<boolean>;
};
 
export const getValidBankAccountNumber = ({
  defaultAccountNumber,
  accountNumber,
  setError,
  isForceError,
}: ValidateBANumberFunctionParam): { number?: string } | undefined => {
  const isSameBA = accountNumber === defaultAccountNumber;
 
  Iif (isSameBA) return;
 
  Iif (!isSameBA && !accountNumber?.match(BANK_ACCOUNT_NUMBER_REGEX)) {
    if (isForceError) isForceError.current = true;
    setError &&
      setError("accountNumber", {
        message: VALIDATION_MESSAGES.INVALID_ACCOUNT_NUMBER,
      });
    return;
  }
 
  Eif (isForceError) isForceError.current = false;
  return { number: accountNumber };
};