89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import { demoDepositProducts } from '../../../constants/mockData';
|
|
import {
|
|
calculateFixedDepositMaturity,
|
|
calculateRecurringDepositMaturity,
|
|
getDepositCanonicalStatus,
|
|
isDepositNearMaturity,
|
|
} from './depositCalculators';
|
|
import {
|
|
validateFixedDepositInput,
|
|
validateRecurringDepositInput,
|
|
} from './depositValidators';
|
|
|
|
describe('deposit calculators', () => {
|
|
it('gives higher maturity for cumulative FD than non-cumulative FD', () => {
|
|
const cumulative = calculateFixedDepositMaturity(100000, 7.1, 12, 'cumulative');
|
|
const nonCumulative = calculateFixedDepositMaturity(
|
|
100000,
|
|
7.1,
|
|
12,
|
|
'non-cumulative',
|
|
);
|
|
|
|
expect(cumulative).toBeGreaterThan(nonCumulative);
|
|
expect(nonCumulative).toBeGreaterThan(100000);
|
|
});
|
|
|
|
it('gives maturity above total contributions for RD', () => {
|
|
const maturity = calculateRecurringDepositMaturity(5000, 6.8, 24);
|
|
|
|
expect(maturity).toBeGreaterThan(5000 * 24);
|
|
});
|
|
});
|
|
|
|
describe('deposit validators', () => {
|
|
const fixedProduct = demoDepositProducts.find((product) => product.kind === 'fd')!;
|
|
const recurringProduct = demoDepositProducts.find((product) => product.kind === 'rd')!;
|
|
|
|
it('rejects fixed deposits below minimum amount', () => {
|
|
const errors = validateFixedDepositInput(
|
|
{
|
|
amount: (fixedProduct.minimumAmount ?? 0) - 1,
|
|
tenureMonths: fixedProduct.defaultTenureMonths,
|
|
interestPayoutType: 'cumulative',
|
|
},
|
|
fixedProduct,
|
|
);
|
|
|
|
expect(errors.amount).toBeDefined();
|
|
});
|
|
|
|
it('rejects recurring deposits below minimum installment', () => {
|
|
const errors = validateRecurringDepositInput(
|
|
{
|
|
monthlyInstallment: (recurringProduct.minimumInstallment ?? 0) - 1,
|
|
tenureMonths: recurringProduct.defaultTenureMonths,
|
|
},
|
|
recurringProduct,
|
|
);
|
|
|
|
expect(errors.monthlyInstallment).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('deposit lifecycle helpers', () => {
|
|
it('marks deposits with past maturity dates as matured', () => {
|
|
const status = getDepositCanonicalStatus(
|
|
{
|
|
status: 'active',
|
|
maturityDate: '2026-04-05T00:00:00.000Z',
|
|
},
|
|
new Date('2026-04-09T00:00:00.000Z'),
|
|
);
|
|
|
|
expect(status).toBe('matured');
|
|
});
|
|
|
|
it('identifies deposits maturing within 7 days', () => {
|
|
const nearMaturity = isDepositNearMaturity(
|
|
{
|
|
status: 'active',
|
|
maturityDate: '2026-04-14T00:00:00.000Z',
|
|
},
|
|
new Date('2026-04-09T00:00:00.000Z'),
|
|
);
|
|
|
|
expect(nearMaturity).toBe(true);
|
|
});
|
|
});
|