فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A02): post a balanced opening via native UI and block duplicate confirmation
davoodmehraban89 committed
Oct 16, 2026 at 23:01 UTC
99008c0903fa819ee177fa86e1b195605773122a
1 file changed
+84
tests/windows-vm-native-functional-matrix.cjs
+84
@@ -51,6 +51,89 @@ async function activateAccounting() {
51
integration: 'enabled', warehouse: 'created' };
52
}
53
54
+async function nativePositiveOpeningLedger() {
55
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
56
+ const check = (value, message) => { if (!value) throw Error(message); };
57
+ const store = FINORA.Storage;
58
+ const company = await FINORA.Company.current();
59
+ check(company?.id && FINORA.Auth.isAdmin(), 'Native A02 posting needs synthetic administrator');
60
+ const period = (await store.getAll('fiscal_periods'))
61
+ .find(x => x.companyId === company.id && x.closed === false);
62
+ const accounts = (await store.getAll('account_chart'))
63
+ .filter(x => x.companyId === company.id && x.postable !== false);
64
+ const receivable = accounts.find(x => x.code === '102');
65
+ const equity = accounts.find(x => x.code === '301');
66
+ check(period && receivable && equity, 'Synthetic opening prerequisites missing');
67
+ const person = await window.ContactController.create({
68
+ name: 'شخص افتتاحیه ساختگی ویندوز', role: 'customer'
69
+ });
70
+ const candidate = {
71
+ periodId: period.id, openingDate: period.startDate,
72
+ lines: [
73
+ { accountId: receivable.id, role: 'receivable', debit: 300, credit: 0 },
74
+ { accountId: equity.id, role: 'equity', debit: 0, credit: 300 }
75
+ ],
76
+ contacts: [{ contactId: person.id, receivable: 300, payable: 0 }],
77
+ stock: [], cash: []
78
+ };
79
+ await FINORA.Router.go('accounting');
80
+ await wait(160);
81
+ const view = window.AccountingView;
82
+ await view.switchTab('opening');
83
+ const attach = () => {
84
+ const input = document.getElementById('openingFileInput');
85
+ check(input, 'A02 native JSON picker missing');
86
+ const file = new File([JSON.stringify(candidate)], 'vm-a02-opening.json',
87
+ { type: 'application/json' });
88
+ Object.defineProperty(input, 'files', { configurable: true, value: [file] });
89
+ };
90
+ attach();
91
+ await view.previewOpeningFile();
92
+ check(view._openingReview?.readiness === 'ready-for-review' &&
93
+ view._openingReview?.writePerformed === false &&
94
+ view._openingReview?.issues.length === 0,
95
+ 'Balanced synthetic opening was not ready without writes');
96
+ const priorPosted = (await store.getAll('journal_entries'))
97
+ .filter(x => x.companyId === company.id && x.sourceType === 'opening_balance');
98
+ check(priorPosted.length === 0, 'Preview unexpectedly posted an opening journal');
99
+ view.confirmOpeningPosting();
100
+ const confirmation = document.querySelector('.modal-footer [data-action="confirm"]');
101
+ check(confirmation, 'Opening posting explicit approval was not displayed');
102
+ confirmation.click();
103
+ let opening = null;
104
+ for (let i = 0; i < 80; i++) {
105
+ opening = (await store.getAll('journal_entries')).find(x =>
106
+ x.companyId === company.id && x.sourceType === 'opening_balance' &&
107
+ x.sourceId === period.id && x.status === 'posted');
108
+ if (opening) break;
109
+ await wait(100);
110
+ }
111
+ check(opening && opening.debit === 300 && opening.credit === 300,
112
+ 'Confirmed synthetic opening was not posted as balanced ledger');
113
+ const lines = (await store.getAll('journal_lines')).filter(x => x.journalId === opening.id);
114
+ check(lines.length === 2 && lines.reduce((n, x) => n + x.debit, 0) === 300 &&
115
+ lines.reduce((n, x) => n + x.credit, 0) === 300,
116
+ 'Opening journal lines do not match the dry-run');
117
+ const receipt = (await store.getAll('audit_events')).filter(x =>
118
+ x.companyId === company.id && x.eventType === 'opening_posted' && x.sourceId === opening.id);
119
+ check(receipt.length === 1 && receipt[0].actorId === FINORA.Auth.current().id,
120
+ 'Opening journal missing unique actor-linked audit receipt');
121
+ await view.switchTab('opening');
122
+ attach();
123
+ await view.previewOpeningFile();
124
+ check(view._openingReview?.readiness === 'blocked' &&
125
+ view._openingReview?.issues.includes('EXISTING_POSTED_JOURNALS') &&
126
+ document.querySelector('#openingPreviewReport button[disabled]'),
127
+ 'A02 second posting attempt not disabled in native UI');
128
+ check((await store.getAll('journal_entries')).filter(x =>
129
+ x.companyId === company.id && x.sourceType === 'opening_balance').length === 1,
130
+ 'Repeated opening preview created another posted journal');
131
+ await view.switchTab('journals');
132
+ check(!document.querySelector('.toast-error'), 'Native opening workflow displayed unexpected error');
133
+ return { dryRunFirst: true, postedBalancedOpening: true,
134
+ actorAuditedOnce: true, repeatPostingBlocked: true };
135
+}
136
+
137
async function purchaseInvoice() {
138
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
139
const check = (value, message) => { if (!value) throw Error(message); };
@@ -475,6 +558,7 @@ async function openingDryRunWithExistingActivity() {
558
module.exports = async function nativeFunctionalMatrix(cdp) {
559
const phases = [
560
['activate-accounting-and-inventory', activateAccounting],
561
+ ['positive-opening-ledger-and-idempotency', nativePositiveOpeningLedger],
562
['purchase-and-post-ledger', purchaseInvoice],
563
['partial-sale-and-inventory', saleInvoice],
564
['sale-return-immutable-stock-and-ledger', nativeSaleReturnGuardrails],