فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A01): native installed WebView2 endorsement approval and two-party ledger tracing
davoodmehraban89 committed
Oct 22, 2026 at 23:17 UTC
4a078cbf5345120746a4558ed6a2d3f87334dcc4
1 file changed
+95
tests/windows-vm-native-functional-matrix.cjs
+95
@@ -568,6 +568,100 @@ async function nativeInactiveBankSettlementGuard() {
568
chequeEventDateDifferentFromDueDate:true };
569
}
570
571
+async function nativeChequeThirdPartyEndorsement() {
572
+ const wait=ms=>new Promise(r=>setTimeout(r,ms));
573
+ const check=(ok,msg)=>{if(!ok)throw Error(msg);};
574
+ const db=FINORA.Storage,company=await FINORA.Company.current();
575
+ check(company?.id&&FINORA.Auth.isAdmin(),'A01 endorsement needs synthetic admin');
576
+ const drawer=(await db.getAll('contacts')).find(c=>
577
+ c.companyId===company.id&&c.name==='مشتری آزمایشی ویندوز');
578
+ check(drawer,'Endorsement drawer fixture missing');
579
+ const endorsee={id:'vm-a01-endorsee-contact',companyId:company.id,
580
+ name:'تأمینکننده واگذاری آزمایشی',ownerUserId:FINORA.Auth.current().id};
581
+ await db.put('contacts',endorsee);
582
+ await FINORA.Router.go('cheques');await wait(130);
583
+ const view=window.ChequesView;
584
+ await view.reload();
585
+ await view.openChequeModal();
586
+ check(document.getElementById('chqSayad'),'Real native cheque create form missing');
587
+ document.getElementById('chqDirection').value='inbound';
588
+ document.getElementById('chqContact').value=drawer.id;
589
+ document.getElementById('chqSayad').value='1234567890123490';
590
+ document.getElementById('chqAmount').value='75';
591
+ document.getElementById('chqIssueDate').value='1405/07/18';
592
+ document.getElementById('chqDueDate').value='1405/07/18';
593
+ await view.saveCheque(null);
594
+ const cheque=(await db.getAll('cheques')).find(c=>
595
+ c.companyId===company.id&&c.sayadNumber==='1234567890123490');
596
+ check(cheque?.financePosted&&cheque.status==='pending','Endorsement cheque posting failed');
597
+ await view.changeStatus(cheque.id);
598
+ const status=document.getElementById('newStatus');
599
+ const date=document.getElementById('chqEventDate');
600
+ const endorseeSelect=document.getElementById('chqEndorsee');
601
+ check(status&&date&&endorseeSelect,'Actual endorsement choice missing in native UI');
602
+ status.value='spent';date.value='1405/07/20';
603
+ view._onChequeStatusSelection();
604
+ check(document.getElementById('chqEndorseeGroup').style.display!=='none',
605
+ 'Third-party contact selector was hidden');
606
+ const counts=async()=>({
607
+ journals:(await db.getAll('journal_entries')).length,
608
+ corrections:(await db.getAll('document_corrections')).length,
609
+ audits:(await db.getAll('audit_events')).length
610
+ });
611
+ const before=await counts();
612
+ await view._applyStatusChange(cheque.id);
613
+ check(!document.querySelector('.modal-footer [data-action="confirm"]'),
614
+ 'Endorsement without selected third party opened approval');
615
+ check(JSON.stringify(await counts())===JSON.stringify(before)&&
616
+ (await db.get('cheques',cheque.id)).status==='pending',
617
+ 'Missing endorsee wrote a financial event');
618
+ const warning=[...document.querySelectorAll('.toast-warning')].find(x=>
619
+ x.textContent.includes('دریافتکننده واگذاری'));
620
+ check(warning,'Missing endorsee was not visibly rejected');
621
+ warning.querySelector('.toast-close')?.click();
622
+ endorseeSelect.value=endorsee.id;
623
+ await view._applyStatusChange(cheque.id);
624
+ const confirm=document.querySelector('.modal-backdrop:last-of-type [data-action="confirm"]');
625
+ check(confirm&&confirm.textContent.includes('تأیید و ثبت واگذاری'),
626
+ 'Native endorsement has no separate explicit approval');
627
+ check(JSON.stringify(await counts())===JSON.stringify(before)&&
628
+ (await db.get('cheques',cheque.id)).status==='pending',
629
+ 'Endorsement posted before explicit confirmation');
630
+ confirm.click();
631
+ let endorsed;
632
+ for(let i=0;i<60;i++){
633
+ endorsed=await db.get('cheques',cheque.id);
634
+ if(endorsed.status==='spent')break;
635
+ await wait(100);
636
+ }
637
+ check(endorsed?.status==='spent'&&endorsed.endorseeContactId===endorsee.id&&
638
+ endorsed.endorsementApprovedBy===FINORA.Auth.current().id&&
639
+ endorsed.statusBusinessDate==='1405/07/20',
640
+ 'Native endorsement did not retain selected third party and approval');
641
+ const journal=await db.get('journal_entries',endorsed.statusJournalId);
642
+ const lines=(await db.getAll('journal_lines')).filter(x=>x.journalId===journal?.id);
643
+ const payable=(await db.getAll('account_chart')).find(x=>
644
+ x.companyId===company.id&&x.code==='201');
645
+ const incoming=(await db.getAll('account_chart')).find(x=>
646
+ x.companyId===company.id&&x.code==='105');
647
+ check(journal?.date==='1405/07/20'&&lines.some(l=>
648
+ l.accountId===payable?.id&&l.contactId===endorsee.id&&l.debit===75)&&
649
+ lines.some(l=>l.accountId===incoming?.id&&l.contactId===drawer.id&&l.credit===75),
650
+ 'Endorsement GL was not correctly split between endorsee and drawer');
651
+ const correction=(await db.getAll('document_corrections')).find(x=>
652
+ x.sourceType==='cheque'&&x.sourceId===cheque.id&&x.correctionType==='endorsement');
653
+ check(correction?.endorseeContactId===endorsee.id&&
654
+ correction?.correlationId===journal.id&&correction?.approvedBy===FINORA.Auth.current().id,
655
+ 'Native endorsement lacks append-only trace and actor');
656
+ check(!(await db.getAll('treasury')).some(x=>x.refChequeId===cheque.id),
657
+ 'Endorsement incorrectly created cash settlement');
658
+ check(!document.querySelector('.toast-error')&&!document.querySelector('.modal-backdrop'),
659
+ 'Native endorsement left unexpected error or modal');
660
+ return {missingEndorseeRejected:true,confirmationRequiredBeforeWrite:true,
661
+ endorseeLedgerDimensionCorrect:true,drawerChequeAssetPreserved:true,
662
+ appendOnlyEndorsementCorrelated:true,noPhantomCash:true};
663
+}
664
+
665
async function nativeTreasuryChequeReconciliation() {
666
const wait=ms=>new Promise(resolve=>setTimeout(resolve,ms));
667
const check=(ok,msg)=>{if(!ok)throw Error(msg);};
@@ -1013,6 +1107,7 @@ module.exports = async function nativeFunctionalMatrix(cdp) {
1107
['purchase-and-post-ledger', purchaseInvoice],
1108
['partial-sale-and-inventory', saleInvoice],
1109
['inactive-treasury-cheque-settlement', nativeInactiveBankSettlementGuard],
1110
+ ['cheque-third-party-endorsement', nativeChequeThirdPartyEndorsement],
1111
['treasury-cheque-reconciliation-readonly', nativeTreasuryChequeReconciliation],
1112
['sale-return-immutable-stock-and-ledger', nativeSaleReturnGuardrails],
1113
['purchase-return-and-stock-guardrails', nativePurchaseReturnGuardrails],