Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
phase-7-sql-readonly-ux-20261015
ci/public-windows-bridge-probe-20261017
ci/windows-dispatch-bootstrap-20261016
ci/windows-dual-app-lab-20261016
dev/v7-production-failclosed-20261021
feature/reconciliation-guard-20261013
main
phase-1-foundation
phase-1-implementation
phase-2-treasury-core
phase-3-banking-reconciliation
phase-4-operations-enterprise-ux
phase-5-hardening-release
phase-6-production-platform
phase-7-production-infrastructure-bank-golive
phase-7-sql-readonly-ux-20261015
transfer-exe-to-drive-20261006
| 1 | import {afterEach,describe,expect,it,vi} from 'vitest'; |
| 2 | import {mkdtempSync,rmSync} from 'node:fs'; |
| 3 | import {tmpdir} from 'node:os'; |
| 4 | import {join} from 'node:path'; |
| 5 | import {LocalStore} from '../local/local-store'; |
| 6 | import {TreasuryService} from './treasury-service'; |
| 7 | import type {BankAdapter} from '../../domain/bank-adapter'; |
| 8 | |
| 9 | const dirs:string[]=[]; |
| 10 | function newStore(){ |
| 11 | const dir=mkdtempSync(join(tmpdir(),'tf-dispatch-')); |
| 12 | dirs.push(dir); |
| 13 | return new LocalStore(join(dir,'store.json')); |
| 14 | } |
| 15 | afterEach(()=>dirs.splice(0).forEach(d=>rmSync(d,{recursive:true,force:true}))); |
| 16 | |
| 17 | function prepareQueued(store:LocalStore,id:string,amountIrr:number,reference:string,date:string){ |
| 18 | const maker=new TreasuryService(store,{tenantId:'local',userId:'maker',role:'MAKER'}); |
| 19 | maker.createAccount({id:'a1',name:'حساب',iban:'IR062960000000100324200001',bankName:'بانک'}); |
| 20 | maker.createBeneficiary({id:'b1',name:'ذینفع',iban:'IR062960000000100324200001',whitelisted:true}); |
| 21 | maker.createPayment({id,sourceAccountId:'a1',beneficiaryId:'b1',amountIrr,paymentDate:date,clientReference:reference,description:''}); |
| 22 | maker.submitPayment(id); |
| 23 | const checker=new TreasuryService(store,{tenantId:'local',userId:'checker',role:'CHECKER'}); |
| 24 | checker.approvePayment(id); |
| 25 | checker.queuePayment(id); |
| 26 | return checker; |
| 27 | } |
| 28 | |
| 29 | describe('TreasuryService bank dispatch',()=>{ |
| 30 | it('records bank reference and moves queued payment to submitted',async()=>{ |
| 31 | const checker=prepareQueued(newStore(),'p1',1000,'R1','2026-10-06'); |
| 32 | const adapter:BankAdapter={submit:vi.fn().mockResolvedValue({outcome:'ACCEPTED',bankReference:'TRK-1'}),poll:vi.fn()}; |
| 33 | const p=await checker.dispatchPayment('p1',adapter); |
| 34 | expect(p.state).toBe('SUBMITTED'); |
| 35 | expect(p.bankReference).toBe('TRK-1'); |
| 36 | }); |
| 37 | it('marks unknown bank outcome for manual review path',async()=>{ |
| 38 | const checker=prepareQueued(newStore(),'p2',1001,'R2','2026-10-07'); |
| 39 | const adapter:BankAdapter={submit:vi.fn().mockResolvedValue({outcome:'UNKNOWN',bankReference:'TRK-2'}),poll:vi.fn()}; |
| 40 | const p=await checker.dispatchPayment('p2',adapter); |
| 41 | expect(p.state).toBe('UNKNOWN'); |
| 42 | expect(p.bankReference).toBe('TRK-2'); |
| 43 | }); |
| 44 | }); |