فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A02): verify admin-only opening wizard and preview cannot commit data
davoodmehraban89 committed
Oct 16, 2026 at 16:50 UTC
4c9e3c8ebd47d1266e682753e8528c397ce50573
1 file changed
+62
tests/a02-opening-ledger-view.test.mjs
new
+62
@@ -0,0 +1,62 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import 'fake-indexeddb/auto';
4
+import { AccountingView } from '../src/views/AccountingView.js';
5
+import { Auth } from '../src/core/Auth.js';
6
+import { OpeningBalanceService } from '../src/core/OpeningBalanceService.js';
7
+
8
+test('A02: opening ledger controls are hidden from ordinary users', () => {
9
+ const prev = Auth.currentUser;
10
+ try {
11
+ Auth.currentUser = { id: 'staff', role: 'user' };
12
+ assert.doesNotMatch(AccountingView.renderOpening(), /type="file"/);
13
+ Auth.currentUser = { id: 'admin', role: 'admin' };
14
+ const html = AccountingView.renderOpening();
15
+ assert.match(html, /type="file"/);
16
+ assert.match(html, /کنترل ماندهها و دوره/);
17
+ assert.match(html, /هیچ داده قدیمی را وارد نمیکند/);
18
+ assert.doesNotMatch(html, /ثبت خودکار/);
19
+ } finally {
20
+ Auth.currentUser = prev;
21
+ }
22
+});
23
+
24
+test('A02: JSON preview UI calls only readonly preflight, not commit', async () => {
25
+ const originalUser = Auth.currentUser;
26
+ const oldDocument = globalThis.document;
27
+ const oldPreview = OpeningBalanceService.preview;
28
+ const oldCommit = OpeningBalanceService.commit;
29
+ const file = { size: 75, text: async () => '{"periodId":"period-example","lines":[]}' };
30
+ const host = { innerHTML: '', textContent: '' };
31
+ let preflightCount = 0, committedCount = 0;
32
+ try {
33
+ Auth.currentUser = { id: 'admin', role: 'admin' };
34
+ globalThis.document = {
35
+ getElementById(id) {
36
+ if (id === 'openingFileInput') return { files: [file] };
37
+ if (id === 'openingPreviewReport') return host;
38
+ return null;
39
+ }
40
+ };
41
+ OpeningBalanceService.preview = async draft => {
42
+ preflightCount++;
43
+ assert.equal(draft.periodId, 'period-example');
44
+ return { readiness: 'blocked', journal: { debit: 100, credit: 99 },
45
+ issues: ['UNBALANCED_OPENING_JOURNAL'] };
46
+ };
47
+ OpeningBalanceService.commit = async () => { committedCount++; };
48
+ await AccountingView.previewOpeningFile();
49
+ assert.equal(preflightCount, 1);
50
+ assert.equal(committedCount, 0);
51
+ assert.match(host.innerHTML, /UNBALANCED_OPENING_JOURNAL/);
52
+ assert.match(host.innerHTML, /disabled/);
53
+ assert.equal(AccountingView._openingReview.readiness, 'blocked');
54
+ } finally {
55
+ Auth.currentUser = originalUser;
56
+ globalThis.document = oldDocument;
57
+ OpeningBalanceService.preview = oldPreview;
58
+ OpeningBalanceService.commit = oldCommit;
59
+ AccountingView._openingCandidate = null;
60
+ AccountingView._openingReview = null;
61
+ }
62
+});