فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A05): verify native fiscal close stocktake guard and atomic audit
Exercise actual NSIS-installed Tauri AccountingView to block fiscal closure with draft stocktake without changing period or audit, then close after clearing synthetic blocker and assert one actor-scoped period_closed event. Both workflows green: Quality #38946201310 and Windows Native VM #38946201604. No customer data, production finance change or public release.
davoodmehraban89 committed
Oct 16, 2026 at 21:54 UTC
69b23dae7065cf0021b5f31adde433126314e34a
1 file changed
+81
-1
tests/windows-vm-native-functional-matrix.cjs
+81
-1
@@ -221,13 +221,93 @@ async function invoicePrintLayout() {
221
physicalPrinterTest: 'not-covered' };
222
}
223
224
+async function fiscalCloseGuardrails() {
225
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
226
+ const check = (ok, message) => { if (!ok) throw Error(message); };
227
+ const store = FINORA.Storage;
228
+ const company = await FINORA.Company.current();
229
+ check(company?.id && FINORA.Auth.isAdmin(), 'Fiscal close test must use a synthetic admin');
230
+ await FINORA.Router.go('accounting');
231
+ await wait(180);
232
+ const view = window.AccountingView;
233
+ check(view, 'Native accounting view was not mounted');
234
+ await view.switchTab('periods');
235
+ const testName = 'A05 VM-only guarded closing period';
236
+ view.openPeriodModal();
237
+ check(document.getElementById('acPeriodName'), 'Fiscal period creation form missing');
238
+ document.getElementById('acPeriodName').value = testName;
239
+ document.getElementById('acPeriodStart').value = '1404/01/01';
240
+ document.getElementById('acPeriodEnd').value = '1404/12/29';
241
+ await view.savePeriod();
242
+ check(!document.querySelector('.toast-error'), 'Creating isolated fiscal period failed');
243
+ const period = (await store.getAll('fiscal_periods'))
244
+ .find(x => x.companyId === company.id && x.name === testName);
245
+ check(period && period.closed === false, 'Synthetic fiscal period did not persist as open');
246
+ const warehouses = (await store.getAll('warehouses')).filter(x => x.companyId === company.id);
247
+ check(warehouses.length, 'Warehouse prerequisite missing');
248
+ const stocktakeId = 'vm-a05-draft-stocktake';
249
+ await store.put('stocktakes', {
250
+ id: stocktakeId, companyId: company.id,
251
+ warehouseId: warehouses[0].id, status: 'draft'
252
+ });
253
+ const auditCount = (await store.getAll('audit_events'))
254
+ .filter(x => x.companyId === company.id && x.eventType === 'period_closed').length;
255
+ const confirmClose = () => {
256
+ view.closePeriod(period.id);
257
+ const confirm = document.querySelector('.modal-footer [data-action="confirm"]');
258
+ check(confirm, 'Real fiscal closure approval dialog missing');
259
+ confirm.click();
260
+ };
261
+ confirmClose();
262
+ let message = null;
263
+ for (let i = 0; i < 60; i++) {
264
+ message = [...document.querySelectorAll('.toast-error')]
265
+ .find(x => x.textContent.includes('انبارگردانی باز'));
266
+ if (message) break;
267
+ await wait(100);
268
+ }
269
+ check(message, 'Closing with an open stocktake was not rejected visibly');
270
+ check((await store.get('fiscal_periods', period.id))?.closed === false,
271
+ 'Open stocktake allowed fiscal closure');
272
+ check((await store.getAll('audit_events'))
273
+ .filter(x => x.companyId === company.id && x.eventType === 'period_closed').length === auditCount,
274
+ 'Rejected fiscal closing created an audit receipt');
275
+ message.querySelector('.toast-close')?.click();
276
+ check(!document.querySelector('.toast-error'), 'Expected fiscal rejection toast remained');
277
+ await store.delete('stocktakes', stocktakeId);
278
+ confirmClose();
279
+ let closed = null;
280
+ for (let i = 0; i < 70; i++) {
281
+ closed = await store.get('fiscal_periods', period.id);
282
+ if (closed?.closed) break;
283
+ await wait(100);
284
+ }
285
+ check(closed?.closed === true && closed.status === 'closed',
286
+ 'Approved fiscal close was not committed');
287
+ const closureAudits = (await store.getAll('audit_events'))
288
+ .filter(x => x.companyId === company.id &&
289
+ x.eventType === 'period_closed' && x.sourceId === period.id);
290
+ check(closureAudits.length === 1 &&
291
+ closureAudits[0].actorId === FINORA.Auth.current().id,
292
+ 'Successful fiscal closure did not produce exactly one actor-scoped audit');
293
+ check(!document.querySelector('.toast-error') && !document.querySelector('.modal-backdrop'),
294
+ 'Fiscal guardrail test left an unexpected UI error or modal');
295
+ return {
296
+ openStocktakeBlocked: true,
297
+ failedCloseRolledBack: true,
298
+ successfulCloseCommitted: true,
299
+ singleAuditReceipt: true
300
+ };
301
+}
302
+
303
module.exports = async function nativeFunctionalMatrix(cdp) {
304
const phases = [
305
['activate-accounting-and-inventory', activateAccounting],
306
['purchase-and-post-ledger', purchaseInvoice],
307
['partial-sale-and-inventory', saleInvoice],
308
['backup-and-atomic-rejection', nativeBackupRestore],
230
- ['rtl-invoice-print-settings', invoicePrintLayout]
309
+ ['rtl-invoice-print-settings', invoicePrintLayout],
310
+ ['fiscal-close-atomic-guardrails', fiscalCloseGuardrails]
311
];
312
const report = {};
313
for (const [name, fn] of phases) {