فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(windows-vm): exercise real installed accounting, purchase, partial sale, backup and RTL print dialog
davoodmehraban89 committed
Oct 16, 2026 at 18:39 UTC
9ca453cacb2d9708c7392f423ada04fccc6ee28d
1 file changed
+240
tests/windows-vm-native-functional-matrix.cjs
new
+240
@@ -0,0 +1,240 @@
1
+'use strict';
2
+// Browser-side functions are stringified and executed in the INSTALLED Tauri
3
+// WebView2. Every write is synthetic and isolated to a disposable CI VM.
4
+const assert = require('node:assert/strict');
5
+
6
+async function activateAccounting() {
7
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
8
+ const check = (value, message) => { if (!value) throw Error(message); };
9
+ check(!document.getElementById('finoraAuthOverlay'), 'admin login must finish');
10
+ await FINORA.Router.go('accounting');
11
+ await wait(220);
12
+ const view = window.AccountingView;
13
+ check(view && document.getElementById('pageContent')?.textContent.includes('حسابداری دوبل'),
14
+ 'actual accounting route missing');
15
+ await view.switchTab('periods');
16
+ if (!view.periods.length) {
17
+ view.openPeriodModal();
18
+ check(document.getElementById('acPeriodName'), 'fiscal period form absent');
19
+ document.getElementById('acPeriodName').value = 'دوره تست ویندوز ۱۴۰۵';
20
+ document.getElementById('acPeriodStart').value = '1405/01/01';
21
+ document.getElementById('acPeriodEnd').value = '1405/12/29';
22
+ await view.savePeriod();
23
+ }
24
+ check(view.periods.length > 0, 'period did not persist');
25
+ await view.switchTab('accounts');
26
+ if (!view.accounts.some(account => account.code === '402')) {
27
+ view.seedChart();
28
+ const confirm = document.querySelector('.modal-footer [data-action="confirm"]');
29
+ check(confirm, 'chart seed approval missing');
30
+ confirm.click();
31
+ for (let i = 0; i < 35 && !view.accounts.some(a => a.code === '402'); i++) await wait(150);
32
+ }
33
+ check(view.accounts.some(account => account.code === '402'), 'default chart missing account 402');
34
+ await view.switchTab('integration');
35
+ if (!document.getElementById('accountingWorkbench')?.textContent.includes('یکپارچه فعال است')) {
36
+ view.activateRetail();
37
+ const confirm = document.querySelector('.modal-footer [data-action="confirm"]');
38
+ check(confirm, 'activation approval missing');
39
+ confirm.click();
40
+ for (let i = 0; i < 35 && !document.getElementById('accountingWorkbench')?.textContent.includes('یکپارچه فعال است'); i++) await wait(150);
41
+ }
42
+ check(document.getElementById('accountingWorkbench')?.textContent.includes('یکپارچه فعال است'),
43
+ 'finance and retail integration not active');
44
+ view.openWarehouse();
45
+ check(document.getElementById('acWhName'), 'warehouse form missing');
46
+ document.getElementById('acWhName').value = 'انبار ماشین مجازی';
47
+ await view.saveWarehouse();
48
+ check((await FINORA.Storage.getAll('warehouses')).some(w => w.name === 'انبار ماشین مجازی'),
49
+ 'warehouse did not persist');
50
+ return { fiscalPeriods: view.periods.length, accountCount: view.accounts.length,
51
+ integration: 'enabled', warehouse: 'created' };
52
+}
53
+
54
+async function purchaseInvoice() {
55
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
56
+ const check = (value, message) => { if (!value) throw Error(message); };
57
+ const c = await window.ContactController.create({ name: 'مشتری آزمایشی ویندوز', role: 'both' });
58
+ const p = await window.ProductController.createProduct({
59
+ name: 'کالای تست ویندوز', code: 'VM-E2E-100',
60
+ trackInventory: true, buyPrice: 100, sellPrice: 200
61
+ });
62
+ await FINORA.Router.go('invoices');
63
+ await wait(300);
64
+ await window.InvoiceFormView.open();
65
+ await wait(180);
66
+ check(document.getElementById('invWarehouse'), 'invoice warehouse selector missing');
67
+ document.getElementById('invKind').value = 'purchase';
68
+ await window.InvoiceFormView._onKindChange();
69
+ document.getElementById('invDate').value = '1405/07/18';
70
+ const contact = document.getElementById('invContactSearch');
71
+ contact.value = c.name;
72
+ window.InvoiceFormView._showContactOptions(true);
73
+ const item = document.querySelector('.contact-option[data-id="' + c.id + '"]');
74
+ check(item, 'contact autocomplete could not select synthetic contact');
75
+ item.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
76
+ const search = document.querySelector('.row-product-search');
77
+ check(search, 'product autocomplete absent');
78
+ search.value = p.code;
79
+ window.InvoiceFormView._showProductOptions(0, true);
80
+ const chosen = document.querySelector('.product-option[data-id="' + p.id + '"]');
81
+ check(chosen, 'product autocomplete selection failed');
82
+ chosen.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
83
+ document.querySelector('.row-qty').value = '10';
84
+ window.InvoiceFormView._onFieldChange(0, 'qty', '10');
85
+ document.querySelector('.row-price').value = '100';
86
+ window.InvoiceFormView._onFieldChange(0, 'price', '100');
87
+ await window.InvoiceFormView._save(false);
88
+ await wait(160);
89
+ const invoice = (await FINORA.Storage.getAll('invoices'))
90
+ .find(x => x.contactId === c.id && x.kind === 'purchase');
91
+ check(invoice?.financePosted, 'purchase financial posting failed');
92
+ check((await FINORA.Storage.getAll('journal_entries'))
93
+ .some(j => j.sourceId === invoice.id && j.status === 'posted'), 'purchase ledger source missing');
94
+ check((await FINORA.Storage.getAll('stock_movements'))
95
+ .some(m => m.refId === invoice.id && m.type === 'in'), 'purchase inventory receipt missing');
96
+ check(!document.querySelector('.modal-backdrop'), 'purchase invoice modal stayed open');
97
+ return { purchaseAmount: invoice.grandTotal, purchasePosted: true, stockReceived: true };
98
+}
99
+
100
+async function saleInvoice() {
101
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
102
+ const check = (value, message) => { if (!value) throw Error(message); };
103
+ await FINORA.Router.go('treasury');
104
+ await wait(200);
105
+ if (!(await FINORA.Storage.getAll('treasury')).some(t => t.recordType === 'account')) {
106
+ await window.TreasuryView.openAccountModal();
107
+ document.getElementById('accName').value = 'صندوق ویندوز';
108
+ document.getElementById('accInitialBalance').value = '0';
109
+ await window.TreasuryView.saveAccount(null);
110
+ }
111
+ const accounts = (await FINORA.Storage.getAll('treasury')).filter(t => t.recordType === 'account');
112
+ check(accounts.some(a => a.ledgerAccountId), 'treasury subledger not mapped');
113
+ const cash = accounts.find(a => a.ledgerAccountId);
114
+ const contact = (await FINORA.Storage.getAll('contacts'))
115
+ .find(x => x.name === 'مشتری آزمایشی ویندوز');
116
+ const product = (await FINORA.Storage.getAll('products'))
117
+ .find(x => x.code === 'VM-E2E-100');
118
+ check(contact && product, 'purchase fixtures missing');
119
+ await FINORA.Router.go('invoices'); await wait(230);
120
+ await window.InvoiceFormView.open(); await wait(170);
121
+ document.getElementById('invKind').value = 'sale';
122
+ await window.InvoiceFormView._onKindChange();
123
+ document.getElementById('invDate').value = '1405/07/18';
124
+ const personSearch = document.getElementById('invContactSearch');
125
+ personSearch.value = contact.name;
126
+ window.InvoiceFormView._showContactOptions(true);
127
+ const personOption = document.querySelector('.contact-option[data-id="' + contact.id + '"]');
128
+ check(personOption, 'sale customer picker failed');
129
+ personOption.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
130
+ const prodSearch = document.querySelector('.row-product-search');
131
+ prodSearch.value = product.code;
132
+ window.InvoiceFormView._showProductOptions(0, true);
133
+ const prodOption = document.querySelector('.product-option[data-id="' + product.id + '"]');
134
+ check(prodOption, 'sale product picker failed');
135
+ prodOption.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
136
+ document.querySelector('.row-qty').value = '3';
137
+ window.InvoiceFormView._onFieldChange(0, 'qty', '3');
138
+ document.querySelector('.row-price').value = '200';
139
+ window.InvoiceFormView._onFieldChange(0, 'price', '200');
140
+ document.getElementById('invPayment').value = 'partial';
141
+ window.InvoiceFormView._onPaymentChange();
142
+ document.getElementById('invPaidAmount').value = '200';
143
+ window.InvoiceFormView._recalc();
144
+ await window.InvoiceFormView._save(false); await wait(160);
145
+ const sale = (await FINORA.Storage.getAll('invoices'))
146
+ .find(i => i.kind === 'sale' && i.contactId === contact.id);
147
+ check(sale?.financePosted, 'sale was not financially posted');
148
+ check(sale.paidAmount === 200 && sale.remaining === 400,
149
+ 'sale partial settlement incorrect: ' + JSON.stringify({ paid: sale.paidAmount, remaining: sale.remaining }));
150
+ const lines = await FINORA.Storage.getAll('journal_lines');
151
+ check(lines.some(l => l.accountId === cash.ledgerAccountId && l.debit === 200),
152
+ 'partial settlement cash journal missing');
153
+ check((await FINORA.Storage.getAll('stock_movements'))
154
+ .some(m => m.refId === sale.id && m.type === 'out'), 'stock issue not posted');
155
+ return { salePaid: 200, saleRemaining: 400, salePosted: true, cashLedger: true };
156
+}
157
+
158
+async function nativeBackupRestore() {
159
+ const check = (value, message) => { if (!value) throw Error(message); };
160
+ const S = FINORA.Storage;
161
+ const company = (await S.getAll('companies'))[0];
162
+ const temporary = await S.put('contacts', {
163
+ id: 'native-vm-backup-roundtrip', companyId: company.id, name: 'فقط آزمون بازگردانی'
164
+ });
165
+ const snapshot = await S.exportAll();
166
+ check(snapshot.version === 7 && snapshot.app === 'Factor-easyPro',
167
+ 'invalid native backup envelope');
168
+ check(snapshot.data.contacts.some(x => x.id === temporary.id),
169
+ 'native backup omitted test contact');
170
+ check(snapshot.data.users.every(u => !('pwHash' in u) && !('pwSalt' in u)),
171
+ 'native backup leaked user password derivation metadata');
172
+ await S.delete('contacts', temporary.id);
173
+ check(!(await S.get('contacts', temporary.id)), 'test contact was not deleted');
174
+ await S.importAll({
175
+ app: snapshot.app, version: snapshot.version,
176
+ data: { contacts: snapshot.data.contacts.filter(c => c.id === temporary.id) }
177
+ });
178
+ check((await S.get('contacts', temporary.id))?.name === 'فقط آزمون بازگردانی',
179
+ 'native backup restore did not recover contact');
180
+
181
+ const sale = (await S.getAll('invoices')).find(i => i.kind === 'sale' && i.financePosted);
182
+ check(sale, 'posted sale missing for restore immutability');
183
+ let denied = false;
184
+ try {
185
+ await S.importAll({
186
+ app: snapshot.app, version: snapshot.version,
187
+ data: {
188
+ contacts: [{id:'should-rollback-native',companyId:company.id,name:'Reject'}],
189
+ invoices: [{...sale,grandTotal:sale.grandTotal+1}]
190
+ }
191
+ });
192
+ } catch (_) { denied = true; }
193
+ check(denied, 'tampered posted sale backup must fail');
194
+ check(!(await S.get('contacts','should-rollback-native')),
195
+ 'rejected full backup wrote a contact anyway');
196
+ check((await S.get('invoices',sale.id)).grandTotal===sale.grandTotal,
197
+ 'tampered posted sale modified the actual financial document');
198
+ return { backupSchema: snapshot.version, credentialsExcluded: true,
199
+ contactRoundtrip: true, tamperedInvoiceRejectedAtomically: true };
200
+}
201
+
202
+async function invoicePrintLayout() {
203
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
204
+ const check = (value, message) => { if (!value) throw Error(message); };
205
+ const sale = (await FINORA.Storage.getAll('invoices'))
206
+ .find(x => x.kind === 'sale' && x.financePosted);
207
+ check(sale, 'posted invoice for print preview missing');
208
+ await FINORA.Router.go('invoices');
209
+ await wait(200);
210
+ await window.InvoicesView.printInvoice(sale.id);
211
+ await wait(320);
212
+ const dialog = document.querySelector('.modal-backdrop');
213
+ check(dialog, 'native print settings dialog did not open');
214
+ const labels = dialog.textContent || '';
215
+ check(labels.includes('قالب چاپ') && labels.includes('A4'),
216
+ 'RTL print template or paper settings missing');
217
+ check(document.documentElement.dir === 'rtl',
218
+ 'document is not marked RTL');
219
+ FINORA.Modal.close();
220
+ return { rtl: true, printSettings: true, templates: true,
221
+ physicalPrinterTest: 'not-covered' };
222
+}
223
+
224
+module.exports = async function nativeFunctionalMatrix(cdp) {
225
+ const phases = [
226
+ ['activate-accounting-and-inventory', activateAccounting],
227
+ ['purchase-and-post-ledger', purchaseInvoice],
228
+ ['partial-sale-and-inventory', saleInvoice],
229
+ ['backup-and-atomic-rejection', nativeBackupRestore],
230
+ ['rtl-invoice-print-settings', invoicePrintLayout]
231
+ ];
232
+ const report = {};
233
+ for (const [name, fn] of phases) {
234
+ const value = await cdp.evaluate('(' + fn.toString() + ')()');
235
+ assert.ok(value && typeof value === 'object', 'invalid native E2E result from ' + name);
236
+ report[name] = value;
237
+ console.log('NATIVE E2E PASSED: ' + name + ': ' + JSON.stringify(value));
238
+ }
239
+ return report;
240
+};