Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { createSyntheticIranianIban } from './synthetic-iban.mjs';
4
5 function mod97(iban) {
6 const rearranged = iban.slice(4) + iban.slice(0, 4);
7 let remainder = 0;
8 for (const ch of rearranged) {
9 const sequence = /[0-9]/.test(ch) ? ch : String(ch.charCodeAt(0) - 55);
10 for (const digit of sequence) remainder = (remainder * 10 + Number(digit)) % 97;
11 }
12 return remainder;
13 }
14 test('VM-only source and beneficiary IBANs are exactly 26 characters and checksum-valid', () => {
15 for (const seed of [1, 2]) {
16 const iban = createSyntheticIranianIban(seed);
17 assert.match(iban, /^IR[0-9]{24}$/);
18 assert.equal(iban.length, 26);
19 assert.equal(mod97(iban), 1);
20 }
21 assert.notEqual(createSyntheticIranianIban(1), createSyntheticIranianIban(2));
22 });
23 test('rejects fixture seeds outside the synthetic one-digit range', () => {
24 for (const value of [0, 10, -1, 1.1, NaN]) assert.throws(() => createSyntheticIranianIban(value));
25 });