Files
monkey-ai-web/test/unit/org-recharge-amount.test.js
T
zhanjunhao 8a48765a46 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

50 lines
1.1 KiB
JavaScript

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,
});
}
});