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

test(A05): isolate cheque approval journal baseline from valid transfer

davoodmehraban89 committed Nov 1, 2026 at 11:24 UTC aafc0ff1d2b603f8ec5c8616a19e7bbd35bba93f
2 files changed +27 -1
tests/windows-vm-native-functional-matrix-contract.test.mjs new
+18
@@ -0,0 +1,18 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { readFileSync } from 'node:fs';
4 +
5 +test('A05 cheque approval compares against a journal baseline taken after the valid transfer',()=>{
6 + const source=readFileSync(new URL('./windows-vm-native-functional-matrix.cjs',import.meta.url),'utf8');
7 + const scenario=source.indexOf('async function nativeInactiveBankSettlementGuard');
8 + const transfer=source.lastIndexOf("await tv._saveTransaction('transfer');");
9 + const approval=source.indexOf('const journalCountBeforeApproval=',transfer);
10 + const apply=source.indexOf('await cv._applyStatusChange(cheque.id);',approval);
11 + const check=source.indexOf("'Cheque cleared before approval'",apply);
12 + assert.ok(scenario>=0&&transfer>scenario&&approval>transfer&&apply>approval&&check>apply,
13 + 'Cheque approval journal baseline must be captured after the valid transfer and before confirmation');
14 + assert.match(source.slice(approval,check),/journalCountBeforeApproval/);
15 + assert.match(source.slice(approval,check),/chequeSettlementsBeforeApproval/);
16 + assert.doesNotMatch(source.slice(apply,check),/length===journalCount\)/,
17 + 'Cheque approval must not compare against the pre-transfer journal count');
18 +});
tests/windows-vm-native-functional-matrix.cjs
+9 -1
@@ -893,12 +893,20 @@ async function nativeInactiveBankSettlementGuard() {
893 check([...selected.options].some(x=>x.value===secondary.id),
894 'Actual secondary bank not selectable in clearing UI');
895 selected.value=secondary.id; // bank other than the default
896 + // The successful transfer above intentionally added a journal entry. Take
897 + // a fresh baseline immediately before cheque approval, and scope the cash
898 + // assertion to this cheque so unrelated valid postings cannot fail it.
899 + const journalCountBeforeApproval=(await db.getAll('journal_entries')).length;
900 + const chequeSettlementsBeforeApproval=(await db.getAll('treasury')).filter(t=>
901 + t.refChequeId===cheque.id).length;
902 await cv._applyStatusChange(cheque.id);
903 const approve=document.querySelector('.modal-backdrop:last-of-type [data-action="confirm"]');
904 check(approve&&approve.textContent.includes('تأیید و ثبت وصول'),
905 'Actual bank clearance missing explicit secondary confirmation');
906 check((await db.get('cheques',cheque.id)).status==='pending'&&
901 - (await db.getAll('journal_entries')).length===journalCount,
907 + (await db.getAll('journal_entries')).length===journalCountBeforeApproval&&
908 + (await db.getAll('treasury')).filter(t=>t.refChequeId===cheque.id).length===
909 + chequeSettlementsBeforeApproval,
910 'Cheque cleared before approval');
911 approve.click();
912 let cleared;