فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test: distinguish optional zero opening balance from required positive transaction amount
davoodmehraban89 committed
Oct 31, 2026 at 21:40 UTC
258c24ea40d371097b6fac5f7530b4d4bb49833a
1 file changed
+7
-2
tests/financial-controller-money-boundaries.test.mjs
+7
-2
@@ -4,6 +4,7 @@ import 'fake-indexeddb/auto';
4
import { StorageService } from '../src/core/StorageService.js';
5
import { Auth } from '../src/core/Auth.js';
6
import { CompanyService } from '../src/core/CompanyService.js';
7
+globalThis.window ??= globalThis;
8
9
const company='financial-controller-money-company';
10
async function setup(){
@@ -17,14 +18,18 @@ const rows=store=>StorageService.getByCompany(store,company);
18
test('treasury account and transaction controller reject malformed, fractional and unsafe rial amounts before writes',async()=>{
19
await setup();
20
const {TreasuryController}=await import('../src/controllers/TreasuryController.js');
20
- for(const invalid of [-1,1.5,Infinity,NaN,Number.MAX_SAFE_INTEGER+1,'bad','1.2','1e2',null,true,{}]){
21
+ const optionalInvalid=[-1,1.5,Infinity,NaN,Number.MAX_SAFE_INTEGER+1,'bad','1.2','1e2',true,{}];
22
+ const requiredInvalid=[...optionalInvalid,null];
23
+ for(const invalid of optionalInvalid){
24
await assert.rejects(TreasuryController.createAccount({name:'Rejected',initialBalance:invalid}),/نامعتبر|صحیح/);
25
assert.deepEqual(await rows('treasury'),[]);
26
}
27
const account=await TreasuryController.createAccount({name:'Synthetic cash',initialBalance:0});
25
- for(const invalid of [-1,1.5,Infinity,NaN,Number.MAX_SAFE_INTEGER+1,'bad','1.2','1e2',null,true,{}]){
28
+ for(const invalid of optionalInvalid){
29
await assert.rejects(TreasuryController.updateAccount(account.id,{name:'Synthetic cash',initialBalance:invalid}),/نامعتبر|صحیح/);
30
assert.equal((await StorageService.get('treasury',account.id)).initialBalance,0);
31
+ }
32
+ for(const invalid of requiredInvalid){
33
await assert.rejects(TreasuryController.createTransaction({type:'receipt',toAccountId:account.id,amount:invalid}),/نامعتبر|صحیح/);
34
assert.equal((await rows('treasury')).filter(x=>x.recordType==='transaction').length,0);
35
}