write a few test jest import { number, object, string } from 'yup'; import {…
- User
write a few test jest import { number, object, string } from 'yup';
import { GENERAL_REQUIRED_ERROR_MESSAGE } from '$ufs-common';
import type { AbsoluteRateType, CalculatedEscrowParameters, SpecialValueIV, } from '$interest-rates/entities/rates';
import { SPECIAL_VALUE_IV2_VALUE_VALIDATION_MESSAGE } from '../../../consts'; import { createSizeSpecialValueValidation } from '../../commons';
type CreateEscrowSpecialValueIV2ValidationProps = { calculatedEscrowParameters: CalculatedEscrowParameters; specialValueIV: SpecialValueIV; };
export const createEscrowSpecialValueIV2Validation = ({ calculatedEscrowParameters, specialValueIV, }: CreateEscrowSpecialValueIV2ValidationProps) => { const { fixedMarginCalculatingKindIv2 } = calculatedEscrowParameters;
return object() .nullable() .shape({ periodRateSubType: object().shape({ id: string(), name: string(), }), value: object() .shape({ absoluteRate: object().shape({ id: string().required(), name: string().required(), }), grossMargin: createSizeSpecialValueValidation({ periodRateSubType: undefined }), netMargin: createSizeSpecialValueValidation({ periodRateSubType: undefined }), eva: createSizeSpecialValueValidation({ periodRateSubType: undefined }), lgd: createSizeSpecialValueValidation({ periodRateSubType: undefined }), rateValue: number() .test('rateValue', GENERAL_REQUIRED_ERROR_MESSAGE, (rateValue, context) => { const { absoluteRate }: { absoluteRate: Labeled<AbsoluteRateType> } = context.parent; if (absoluteRate.id === 'ABSOLUTE_VALUE' && typeof rateValue !== 'number') { return false; } return true; }) .nullable(), }) .test('value', SPECIAL_VALUE_IV2_VALUE_VALIDATION_MESSAGE, () => { if ( specialValueIV?.periodRateType?.id === 'FLOATING' && fixedMarginCalculatingKindIv2.id === 'NOT_APPLICABLE' ) { return false; } return true; }), });};
- Assistant