فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A05): read-only bank routing and endorsement contact reconciliation diagnostics

davoodmehraban89 committed Oct 23, 2026 at 02:36 UTC 0b4c397614eb427071b42eab1662fd2f6fbfb02a
1 file changed +70
tests/reconciliation.test.mjs
+70
@@ -170,3 +170,73 @@ test('A05: reconciler checks posted cheque lifecycle and its single matched cash
170 assert.equal(before.cheques[0].status,'cleared');
171 });
172
173 +function chequeControlFixture(){
174 + const f=fixture();
175 + f.accounts.push({id:'a105',code:'105'}, {id:'a102',code:'102'},
176 + {id:'cash-mapped',code:'101002',parentCode:'101'});
177 + f.journals.push(
178 + {id:'ch-origin',status:'posted',sourceType:'cheque',sourceId:'ch',debit:80,credit:80},
179 + {id:'ch-status',status:'posted',sourceType:'cheque_status',sourceId:'ch',debit:80,credit:80});
180 + f.journalLines.push(
181 + {id:'ch1',journalId:'ch-origin',accountId:'a105',contactId:'drawer',debit:80,credit:0},
182 + {id:'ch2',journalId:'ch-origin',accountId:'a102',contactId:'drawer',debit:0,credit:80},
183 + {id:'ch3',journalId:'ch-status',accountId:'cash-mapped',contactId:'drawer',debit:80,credit:0},
184 + {id:'ch4',journalId:'ch-status',accountId:'a105',contactId:'drawer',debit:0,credit:80}
185 + );
186 + f.cheques=[{id:'ch',financePosted:true,direction:'inbound',contactId:'drawer',
187 + status:'cleared',amount:80,journalId:'ch-origin',statusJournalId:'ch-status',
188 + clearingAccountId:'bank-selected'}];
189 + f.transactions=[
190 + {id:'bank-selected',recordType:'account',ledgerAccountId:'cash-mapped'},
191 + {id:'bank-default',recordType:'account',ledgerAccountId:'a102'},
192 + {id:'ch-cash',recordType:'transaction',refChequeId:'ch',
193 + type:'receipt',amount:80,financePosted:true,
194 + journalId:'ch-status',toAccountId:'bank-selected'}
195 + ];
196 + return f;
197 +}
198 +
199 +test('A05: approved cheque bank must match treasury account and GL leaf without mutations',()=>{
200 + const f=chequeControlFixture();
201 + assert.equal(reconcileFinancialData(f).counts.issues,0);
202 + const base=structuredClone(f);
203 + f.transactions[2].toAccountId='bank-default';
204 + let report=reconcileFinancialData(f);
205 + assert.ok(report.issues.some(x=>x.code==='CHEQUE_CLEARING_ACCOUNT_MISMATCH'));
206 + f.transactions[2].toAccountId='bank-selected';
207 + f.journalLines.find(x=>x.id==='ch3').accountId='a102';
208 + report=reconcileFinancialData(f);
209 + assert.ok(report.issues.some(x=>x.code==='CHEQUE_CLEARING_LEDGER_MISMATCH'));
210 + f.journalLines.find(x=>x.id==='ch3').accountId='cash-mapped';
211 + f.transactions=f.transactions.filter(x=>x.id!=='bank-selected');
212 + report=reconcileFinancialData(f);
213 + assert.ok(report.issues.some(x=>x.code==='CHEQUE_CLEARING_ACCOUNT_MISSING'));
214 + f.transactions=base.transactions;
215 + delete f.cheques[0].clearingAccountId;
216 + assert.equal(reconcileFinancialData(f).counts.issues,0,
217 + 'Historical cleared cheque without account evidence should not be retroactively forged');
218 + assert.equal(base.cheques[0].clearingAccountId,'bank-selected');
219 +});
220 +
221 +test('A05: endorsed cheque reconciliation validates drawer and endorsee GL dimensions',()=>{
222 + const f=chequeControlFixture();
223 + f.cheques[0].status='spent';
224 + f.cheques[0].endorseeContactId='supplier-2';
225 + delete f.cheques[0].clearingAccountId;
226 + f.transactions=[];
227 + const debit=f.journalLines.find(x=>x.id==='ch3');
228 + debit.accountId='a201';debit.contactId='supplier-2';
229 + assert.equal(reconcileFinancialData(f).counts.issues,0);
230 + const before=structuredClone(f);
231 + debit.contactId='drawer';
232 + let report=reconcileFinancialData(f);
233 + assert.ok(report.issues.some(x=>x.code==='CHEQUE_ENDORSEMENT_GL_MISMATCH'));
234 + debit.contactId='supplier-2';
235 + f.cheques[0].endorseeContactId='drawer';
236 + report=reconcileFinancialData(f);
237 + assert.ok(report.issues.some(x=>x.code==='CHEQUE_ENDORSEE_INVALID'));
238 + f.cheques[0].endorseeContactId='supplier-2';
239 + assert.equal(reconcileFinancialData(f).counts.issues,0);
240 + assert.equal(before.cheques[0].endorseeContactId,'supplier-2',
241 + 'Read-only checker must not mutate original references');
242 +});