/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import assert from 'node:assert/strict'; import test from 'node:test'; import { normalizeCustomAmount } from '../../src/pages/Organization/customRechargeAmount.js'; test('custom recharge accepts positive integers and allows clearing', () => { for (const value of ['1', '5', '9999', '10000', '0005']) { assert.deepEqual(normalizeCustomAmount(value), { value: Number(value), exceeded: false, }); } assert.deepEqual(normalizeCustomAmount(''), { value: null, exceeded: false }); }); test('custom recharge rejects zero, decimals, signs, exponents and special characters', () => { for (const value of [ '0', '000', '-1', '+1', '1.5', '1.0', '1e3', '1E4', 'abc', '1@2', ' 5', '5 ', '1,000', 'Infinity', 'NaN', ]) { assert.equal(normalizeCustomAmount(value), null, value); } }); test('custom recharge clamps oversized input, including huge pasted numbers', () => { for (const value of [ '10001', '99999', '12345678901234567890', '9'.repeat(400), ]) { assert.deepEqual(normalizeCustomAmount(value), { value: 10000, exceeded: true, }); } });