MC/website/tests/postbank-credit-model.test.mjs
2026-11-27 23:43:05 +00:00

9 lines
2.4 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import {creditQuote,creditScore} from '../node/postbank-credit-model.mjs';
test('launch grants have exact principal, zero interest and user-selected instalments',()=>{const q=creditQuote({productKey:'grant_start',monthly:'250.00'});assert.equal(q.months,10);assert.equal(q.totalRepayment,'2500.00');assert.equal(q.totalInterest,'0.00');assert.equal(q.schedule.at(-1).balance,'0.00');assert.throws(()=>creditQuote({productKey:'grant_start',monthly:'1.00'}));});
test('fixed effective annual rates amortise to zero with exact minor-unit conservation',()=>{for(const [key,amount,months]of [['personal_loan','10000.00',12],['business_loan','50000.00',24],['civic_loan','10000.00',6],['personal_overdraft','500.00',1]]){const q=creditQuote({productKey:key,amount,months}),minor=s=>BigInt(s.replace('.',''));assert.equal(q.schedule.at(-1).balance,'0.00');assert.equal(q.schedule.reduce((s,r)=>s+minor(r.principal),0n)+minor(q.firstInstalment),minor(amount));assert.equal(minor(q.totalRepayment),minor(amount)+minor(q.totalInterest));}});
test('simulator rejects unsupported products, amounts and terms',()=>{assert.throws(()=>creditQuote({productKey:'personal_loan',amount:1000,months:12}));assert.throws(()=>creditQuote({productKey:'personal_loan',amount:'1000000.00',months:12}));assert.throws(()=>creditQuote({productKey:'civic_loan',amount:'10000.00',months:24}));});
test('new customers start neutral; denials have bounded, recoverable impact and arrears matter',()=>{assert.equal(creditScore().score,600);assert.equal(creditScore({denials:[0]}).score,585);assert.equal(creditScore({denials:[0,0,0,0]}).denialPenalty,45);assert.equal(creditScore({denials:[91]}).denialPenalty,0);assert.ok(creditScore({overdueMinor:100n}).score<600);});
test('five-percent first instalment rounds up to cents and is included once in total repayment',()=>{
const q=creditQuote({productKey:'personal_loan',amount:'1000.01',months:3}),minor=s=>BigInt(s.replace('.',''));assert.equal(q.firstInstalment,'50.01');assert.equal(q.remainingPrincipal,'950.00');assert.equal(q.schedule.reduce((sum,r)=>sum+minor(r.amount),0n)+minor(q.firstInstalment),minor(q.totalRepayment));assert.equal(minor(q.totalRepayment),100001n+minor(q.totalInterest));const zero=creditQuote({productKey:'personal_loan',amount:'1000.00',months:3},{annualBps:0});assert.equal(zero.totalRepayment,'1000.00');assert.equal(zero.totalInterest,'0.00');
});