فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A05): prove cheque and settlement mismatch reporting is read-only
davoodmehraban89 committed
Oct 17, 2026 at 00:34 UTC
6ac90e4c069545686cd2eb63ea7415f9e07d35ce
1 file changed
+58
tests/reconciliation.test.mjs
+58
@@ -112,3 +112,61 @@ test('accounting report period filters reject foreign periods and malformed Jala
112
const report=await accounts.financialReports({periodId:p.id,from:'1405/01/01',to:'1405/12/29'});
113
assert.equal(report.postedCount,0);
114
});
115
+
116
+test('A05: reconciliation detects mismatched settlement transaction and duplicate allocation without mutations',()=>{
117
+ const f=fixture();
118
+ f.transactions=[{id:'cash-1',recordType:'transaction',type:'receipt',amount:35,refInvoiceId:'other',
119
+ financePosted:true}];
120
+ f.settlements=[
121
+ {id:'s1',invoiceId:'i1',transactionId:'cash-1',amount:40},
122
+ {id:'s2',invoiceId:'i1',transactionId:'cash-1',amount:35}
123
+ ];
124
+ f.invoices[0].paidAmount=75;f.invoices[0].remaining=25;
125
+ const snapshot=structuredClone(f);
126
+ const report=reconcileFinancialData(f);
127
+ for(const code of [
128
+ 'SETTLEMENT_REFERENCE_MISMATCH','SETTLEMENT_CASH_MISMATCH',
129
+ 'DUPLICATE_SETTLEMENT_TRANSACTION'
130
+ ]) assert.ok(report.issues.some(x=>x.code===code),code);
131
+ assert.deepEqual(f,snapshot,'A05 diagnostic must be read-only');
132
+});
133
+
134
+test('A05: reconciler checks posted cheque lifecycle and its single matched cash entry',()=>{
135
+ const f=fixture();
136
+ f.journals.push(
137
+ {id:'cheque-j1',status:'posted',sourceType:'cheque',sourceId:'ch-1',debit:80,credit:80},
138
+ {id:'cheque-j2',status:'posted',sourceType:'cheque_status',sourceId:'ch-1',debit:80,credit:80}
139
+ );
140
+ f.journalLines.push(
141
+ {id:'c1',journalId:'cheque-j1',accountId:'a103',debit:80,credit:0},
142
+ {id:'c2',journalId:'cheque-j1',accountId:'a201',debit:0,credit:80},
143
+ {id:'c3',journalId:'cheque-j2',accountId:'a103',debit:80,credit:0},
144
+ {id:'c4',journalId:'cheque-j2',accountId:'a201',debit:0,credit:80}
145
+ );
146
+ // No inventory ledger comparison from synthetic cheque-only ledger fixture.
147
+ f.integrated=true;
148
+ f.inventoryBalances[0].value=260;
149
+ f.stockMovements[0].cost=260;
150
+ f.cheques=[{id:'ch-1',financePosted:true,direction:'inbound',
151
+ status:'cleared',amount:80,journalId:'cheque-j1',statusJournalId:'cheque-j2'}];
152
+ f.transactions=[{id:'ct-1',recordType:'transaction',refChequeId:'ch-1',
153
+ type:'receipt',amount:80,journalId:'cheque-j2',financePosted:true}];
154
+ const baseline=reconcileFinancialData(f);
155
+ assert.equal(baseline.issues.length,0,JSON.stringify(baseline.issues));
156
+ assert.equal(baseline.counts.cheques,1);
157
+ const before=structuredClone(f);
158
+ f.transactions[0].amount=90;
159
+ const mismatch=reconcileFinancialData(f);
160
+ assert.ok(mismatch.issues.some(x=>x.code==='CHEQUE_CLEARING_CASH_MISMATCH'));
161
+ assert.equal(f.cheques[0].status,'cleared','read-only checker must never revert cheque status');
162
+ f.transactions[0].amount=80;
163
+ f.transactions.push({...f.transactions[0],id:'ct-dup'});
164
+ const duplicate=reconcileFinancialData(f);
165
+ assert.ok(duplicate.issues.some(x=>x.code==='CHEQUE_CLEARING_CASH_COUNT'));
166
+ f.transactions=f.transactions.slice(0,1);
167
+ f.cheques[0].status='bounced';
168
+ const bounced=reconcileFinancialData(f);
169
+ assert.ok(bounced.issues.some(x=>x.code==='NONCLEARED_CHEQUE_HAS_CASH'));
170
+ assert.equal(before.cheques[0].status,'cleared');
171
+});
172
+