فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

main
a02/strict-export-preflight-20261018 audit/a01-readonly-invoice-metadata-20261101 ci/a06-require-trusted-issuer-for-release ci/main-postmerge-phase-a-validation-20261020 ci/phase-a-controlled-public-release design/issue-5-commercial-corrections-adr docs/a01-a02-a05-oct23-verified-evidence docs/a01-cheque-endorsement-evidence-20261022 docs/a01-cheque-event-date-evidence-20261021 docs/a01-explicit-refund-reason-evidence-20261021 docs/a01-refund-auth-status-20261020 docs/a01-refund-trace-evidence-20261020 docs/a02-102-evidence-20261018 docs/a02-pr104-evidence-20261018 docs/a02-pr106-evidence-20261019 docs/a02-pr108-ten-tests-20261019 docs/a02-private-sql-backup-evidence-20261111 docs/a03-merge-status-sync-20261020 docs/a04-software-gate-acceptance-20261020 docs/feature-matrix-20261014 docs/finora-master-execution-playbook docs/four-phase-execution-20261014 docs/four-phase-roadmap-20261014 docs/holoo-lab-stabilization-phase1-20261111 docs/holoo-runtime-schema-audit-20261111 docs/ops-142-governance-5-1-3-20261030 docs/phase-a-a01-a02-a06-a08-verified-evidence-20261023 docs/phase-a-a01-a05-a06-evidence-20261023 docs/phase-a-independent-acceptance-evidence docs/phase-a-pr110-evidence-20261019 docs/project-status-phase-a-20261014 feat/a01-referenced-return-corrections feat/a01-referenced-returns-on-main feat/a02-atomic-opening-ledger-preflight feat/a02-holoo-compatibility-preflight feat/a02-holoo-declared-control-totals feat/a02-holoo-explicit-csv-gate feat/a02-holoo-safe-zip-intake-offline-webview2-20261030 feat/a02-offline-sql-server-provisioning-20261030 feat/a02-opening-balance-dry-run feat/a02-opening-ledger-admin-ui feat/a02-opt-in-isolated-sql-restore-executor-20261030 feat/a02-private-holoo-zip-staging-20261030 feat/a02-safe-isolated-restore-plan-20261030 feat/a02-sql-backup-header-verifyonly-20261030 feat/a03-audit-schema-atomic-events feat/a03-complete-manual-journal-audit feat/a05-cheque-treasury-reconciliation feat/a06-signed-offline-license-activation feat/a08-synthetic-performance-baseline feat/phase-a-accounting-benchmark-return-preview feat/phase-a-ledger-settlement-diagnostics feature/v2-reconciliation-20261013 fix/a01-atomic-confirm-ui-one-shot-20261031 fix/a01-cheque-clearance-explicit-account-20261023 fix/a01-cheque-contractual-due-date-validity-20261023 fix/a01-cheque-endorsement-counterparty-20261022 fix/a01-cheque-event-date-open-period-20261021 fix/a01-cumulative-return-amount-cap fix/a01-explicit-refund-reason-approval-20261021 fix/a01-manager-authorized-customer-refunds-20261020 fix/a01-no-implicit-refund fix/a01-one-shot-confirm-on-atomic-import-20261031 fix/a01-refund-and-overcollection-net-cash fix/a01-refund-correction-trace-20261020 fix/a02-atomic-excel-master-merge-20261031 fix/a02-canonical-mapping-contract-20261018 fix/a02-disable-destructive-excel-replace-20261031 fix/a02-holoo-invoice-line-coverage-20261023 fix/a02-holoo-preflight-required-invoice-lines-20261023 fix/a02-mapping-contract-20261018 fix/a02-opening-preflight-unbalanced-report fix/a02-orphan-mapping-20261018 fix/a02-private-excel-import-session-20261031 fix/a02-strict-export-input-20261019 fix/a03-append-only-full-backup-import fix/a03-append-only-write-guard fix/a03-block-transaction-clear-append-only-20261016 fix/a03-chain-validation-20261020 fix/a03-company-scoped-audit-data-access fix/a03-deny-direct-audit-write-20261019 fix/a03-escaped-expense-list-20261031 fix/a03-escaped-financial-record-ids-20261031 fix/a03-financial-ledger-actions-and-print-20261031 fix/a04-backup-checksum-preflight fix/a04-company-audit-replay-stable-compare fix/a04-company-backup-source-isolation-20261020 fix/a04-full-restore-posted-financial-integrity fix/a04-reject-mixed-company-backup-20261019 fix/a04-replace-immutable-posted-ledger fix/a04-restore-financial-journal-references fix/a04-service-source-company-boundary-20261020 fix/a05-block-inactive-treasury-settlements fix/a05-cheque-cash-evidence-reconciliation-20261023 fix/a05-cheque-ledger-and-bank-reconciliation-20261023 fix/a05-fiscal-close-invariant-gates fix/a06-backup-restore-user-privileges fix/a06-license-user-company-quota-20261023 fix/a06-malformed-trial-state-fail-closed fix/a06-offline-clock-fail-closed-20261019 fix/a07-indexeddb-blocked-startup fix/a07-offline-bundled-assets fix/a07-version-and-startup-banner fix/issue-7-company-backup-isolation fix/p0-deterministic-fractional-invoice-money-20261031 fix/p0-fractional-quantity-input-20261031 fix/p0-fractional-quantity-integrated-20261031 fix/p0-invoice-posting-invariants-20261031 fix/p0-legacy-stock-and-product-inputs-20261031 fix/p0-reports-immutable-cogs-20261101 fix/p0-verified-financial-percent-20261031 fix/p0-zero-discount-report-revenue-20261101 fix/phase-a-backup-app-version fix/phase-a-backup-integrity-checksum fix/phase-a-backup-record-id-validation-20261014 fix/phase-a-backup-version-validation-20261014 fix/phase-a-closure-pack3-20261101 fix/phase-a-entitlement-payload-validation fix/phase-a-gate-exact-evidence-20261019 fix/phase-a-pack4-stock-scope-20261101 fix/phase-a-pack5-integrated-evidence-20261101 fix/phase-a-pack6-atomic-legacy-20261101 fix/phase-a-restore-envelope-and-rollback fix/phase-a-settings-admin-gate fix/print-browser-header-footer-20261014 fix/q01-expense-security-probe-exact-option-20261031 fix/q01-financial-grid-labels-20261031 fix/q01-form-label-association-20261031 fix/q01-native-evidence-integrity-20261030 fix/q01-number-input-persian-decimal-20261031 fix/q01-responsive-dashboard-and-cheque-table-20261031 fix/q01-safe-ui-action-audit-coverage-20261031 fix/q01-visible-desktop-sidebar-and-safe-confirm-20261030 fix/roadmap-metadata-sync-20261014 gate/a03-audit-metadata-validation-20261019 integration/a02-windows-holoo-setup-candidate-20261030 license-server main perf/a07-lazy-load-excel perf/a08-cheque-reconciliation-account-index-20261023 perf/a08-paginated-reports-20261101 phase1-restore-hardening planning/holoo-execution-20261013 planning/roadmap-project-management-20261014 qa/native-click-coverage-audit-20261030 release/v2.0.0 test/a01-native-endorsement-mandatory-20261023 test/a01-native-purchase-return-guardrails test/a01-native-sale-return-financial-guardrails test/a01-safe-integer-boundary-20261019 test/a02-native-opening-dry-run-rejections test/a02-native-positive-opening-ledger test/a04-native-corrupt-fbackup-20261016 test/a04-native-encrypted-company-backup test/a04-native-encrypted-company-backup-main test/a04-native-late-transaction-rollback test/a04-native-windows-backup-recovery test/a04-real-edge-v6-v7-migration test/a04-real-native-interrupted-restore test/a05-native-draft-ledger-and-repeat-close-20261016 test/a05-native-fiscal-close-guardrails test/a07-native-multipage-print-engine test/a07-native-origin-provenance test/a07-native-webview2-offline-routes test/a07-windows-offline-startup-smoke test/a08-installed-webview2-60k-baseline test/a08-native-webview2-heap-metrics test/a08-windows-synthetic-performance-baseline test/github-write-access-20261009 test/native-win-ui-routes-after-finance-backup test/phase-a-combined-a01-a05-a08-final-evidence test/phase-a-combined-native-acceptance-matrix test/phase-a-ledger-invariants-20261014 test/phase-a-native-all-routes-on-merged-lab test/phase-a-native-encrypted-backup test/phase-a-native-finance-backup-matrix test/phase-a-native-ui-and-backup-smoke test/phase-a-windows-native-installer-lab work/a08-dispatch-activation-20261123 work/a08-memory-stability-20261123 work/finance-curated-20261123
mjs 279 lines 15.6 KB
Raw
1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import 'fake-indexeddb/auto';
4 import { StorageService } from '../src/core/StorageService.js';
5 import { Auth } from '../src/core/Auth.js';
6 import { CompanyService } from '../src/core/CompanyService.js';
7 import { DataScope } from '../src/core/DataScope.js';
8 import { SettingsController } from '../src/controllers/SettingsController.js';
9 import { AccountingService as ledger } from '../src/core/AccountingService.js';
10 import {
11 validateAccount, validateFiscalPeriod, validateJournal, validateJournalLines,
12 assertJalaliDate, reversingLines
13 } from '../src/core/AccountingCore.mjs';
14
15 const year = { startDate: '1405/01/01', endDate: '1405/12/29' };
16 const select = companyId => { CompanyService.activeCompanyId = companyId; };
17 const entries = async store => StorageService.getAll(store);
18 const reset = async () => {
19 await StorageService.clearAll();
20 await StorageService.put('companies', { id: 'c1', name: 'Alpha' });
21 await StorageService.put('companies', { id: 'c2', name: 'Beta' });
22 Auth.currentUser = { id: 'test_admin', role: 'admin', username: 'tester' };
23 select('c1');
24 };
25 const setup = async () => {
26 await reset();
27 const period = await ledger.createPeriod({ name: 'سال ۱۴۰۵', ...year });
28 await ledger.seedDefaultChart();
29 const accounts = await ledger.listAccounts();
30 return { period, cash: accounts.find(a => a.code === '101'), sales: accounts.find(a => a.code === '401') };
31 };
32 const balanced = (period, cash, sales, sourceId) => ({
33 periodId: period.id, date: '1405/07/18', description: 'فروش تست',
34 ...(sourceId ? { sourceType: 'test_invoice', sourceId } : {}),
35 lines: [
36 { accountId: cash.id, debit: 10000, credit: 0 },
37 { accountId: sales.id, debit: 0, credit: 10000 }
38 ]
39 });
40
41 test('core: Jalali dates and fiscal period boundaries', () => {
42 assert.equal(assertJalaliDate('1405/07/18'), '1405/07/18');
43 assert.throws(() => assertJalaliDate('1405/07/31'));
44 assert.throws(() => assertJalaliDate('1405/12/30'));
45 assert.equal(assertJalaliDate('1403/12/30'), '1403/12/30');
46 assert.throws(() => assertJalaliDate('1405/7/18'));
47 assert.throws(() => validateFiscalPeriod({ companyId: 'c1', startDate: '1405/10/01', endDate: '1405/01/01' }));
48 assert.throws(() => validateFiscalPeriod({ companyId: 'c1', ...year }, [{ id: 'p', companyId: 'c1', ...year }]));
49 assert.doesNotThrow(() => validateFiscalPeriod({ companyId: 'c2', ...year }, [{ id: 'p', companyId: 'c1', ...year }]));
50 });
51
52 test('core: reject incorrect accounts, posting to parent and amount overflow', () => {
53 const list = [
54 { id: 'root', companyId: 'c1', code: '1', level: 'group', type: 'asset', name: 'assets' },
55 { id: 'general', companyId: 'c1', code: '101', parentCode: '1', level: 'general', type: 'asset', name: 'cash' },
56 { id: 'sub', companyId: 'c1', code: '10101', parentCode: '101', level: 'subsidiary', type: 'asset', name: 'box' }
57 ];
58 assert.throws(() => validateAccount({ ...list[0], id: 'another', parentCode: '101' }, list));
59 assert.throws(() => validateAccount({ id: 'x', companyId: 'c1', code: '10102', parentCode: '101', level: 'subsidiary', type: 'expense', name: 'wrong' }, list));
60 assert.throws(() => validateJournalLines({ companyId: 'c1', lines: [{ accountId: 'general', debit: 10, credit: 0 }] }, list, { requireBalance: false }));
61 assert.throws(() => validateJournalLines({ companyId: 'c1', lines: [{ accountId: 'sub', debit: 9007199254740991, credit: 0 }, { accountId: 'sub', debit: 1, credit: 0 }] }, list));
62 assert.deepEqual(reversingLines([{ accountId: 'x', debit: 4, credit: 0 }, { accountId: 'y', debit: 0, credit: 4 }]).map(l => [l.debit, l.credit]), [[0, 4], [4, 0]]);
63 });
64
65 test('integration: chart seed is idempotent; parent relationships and company isolation', async () => {
66 await reset();
67 assert.equal((await ledger.seedDefaultChart()).added, 19);
68 assert.equal((await ledger.seedDefaultChart()).added, 0);
69 assert.equal((await ledger.listAccounts()).length, 19);
70 await assert.rejects(ledger.addAccount({ code: '101', name: 'duplicate', type: 'asset', level: 'general', parentCode: '1' }));
71 const general = await ledger.addAccount({ code: '107', name: 'دیگر دارایی', type: 'asset', level: 'general', parentCode: '1' });
72 assert.equal(general.companyId, 'c1');
73 select('c2');
74 assert.equal((await ledger.listAccounts()).length, 0);
75 assert.equal((await ledger.seedDefaultChart()).added, 19);
76 });
77
78 test('integration: overlapping periods rejected but same calendar interval is allowed in another company', async () => {
79 await reset();
80 const p = await ledger.createPeriod({ name: 'سال', ...year });
81 assert.ok(p.id);
82 await assert.rejects(ledger.createPeriod({ name: 'همپوشان', startDate: '1405/10/01', endDate: '1406/01/01' }), /هم‌پوشانی/);
83 await ledger.createPeriod({ name: 'بعدی', startDate: '1406/01/01', endDate: '1406/12/29' });
84 select('c2');
85 const separate = await ledger.createPeriod({ name: 'شرکت دوم', ...year });
86 assert.equal(separate.companyId, 'c2');
87 });
88
89 test('integration: posting account cannot gain a child after financial movements', async () => {
90 const { period, cash, sales } = await setup();
91 await ledger.postJournal(balanced(period, cash, sales));
92 await assert.rejects(ledger.addAccount({
93 code: '10101', name: 'صندوق زیرمجموعه', level: 'subsidiary', type: 'asset', parentCode: cash.code
94 }), /گردش مالی/);
95 assert.equal((await ledger.listAccounts()).length, 19);
96 });
97
98 test('integration: atomic posting, balanced trial balance and duplicate-source rejection', async () => {
99 const { period, cash, sales } = await setup();
100 const source = balanced(period, cash, sales, 'inv-42');
101 const posted = await ledger.postJournal(source);
102 assert.equal(posted.status, 'posted');
103 assert.equal((await ledger.getJournal(posted.id)).lines.length, 2);
104 assert.equal((await ledger.listJournals()).length, 1);
105 const trial = await ledger.trialBalance({ periodId: period.id });
106 assert.deepEqual(trial.totals, { debit: 10000, credit: 10000 });
107 assert.equal(trial.rows.length, 2);
108 await assert.rejects(ledger.postJournal(source), /تکرار|ثبت دوباره/);
109 assert.equal((await entries('journal_entries')).length, 1);
110 assert.equal((await entries('journal_lines')).length, 2);
111 });
112
113 test('integration: posting failures roll back all journal tables', async () => {
114 const { period, cash, sales } = await setup();
115 const invalid = balanced(period, cash, sales);
116 invalid.lines[1].credit = 9000;
117 await assert.rejects(ledger.postJournal(invalid), /تراز نیست/);
118 assert.equal((await entries('journal_entries')).length, 0);
119 assert.equal((await entries('journal_lines')).length, 0);
120 invalid.lines[1].credit = 10000;
121 invalid.lines[1].accountId = 'other-company-account';
122 await assert.rejects(ledger.postJournal(invalid), /شرکت دیگر|غیرمجاز/);
123 assert.equal((await entries('journal_entries')).length, 0);
124 });
125
126 test('integration: draft may be unbalanced; posting draft requires balance', async () => {
127 const { period, cash } = await setup();
128 const draft = await ledger.saveDraftJournal({
129 periodId: period.id, date: '1405/04/22',
130 lines: [{ accountId: cash.id, debit: 100, credit: 0 }]
131 });
132 assert.equal(draft.status, 'draft');
133 await assert.rejects(ledger.postDraftJournal(draft.id), /سطرها|تراز نیست|نامعتبر/);
134 assert.equal((await ledger.getJournal(draft.id)).status, 'draft');
135 assert.equal((await ledger.trialBalance()).rows.length, 0);
136 await assert.rejects(ledger.closePeriod(period.id), /پیش‌نویس/);
137 });
138
139 test('integration: editing and finalizing a draft is atomic; failed finalization leaves draft unchanged', async () => {
140 const { period, cash, sales } = await setup();
141 const draft = await ledger.saveDraftJournal({
142 periodId: period.id, date: '1405/07/18',
143 lines: [{ accountId: cash.id, debit: 1000, credit: 0 }]
144 });
145 const invalid = {
146 periodId: period.id, date: '1405/07/19',
147 lines: [{ accountId: cash.id, debit: 2000, credit: 0 }, { accountId: sales.id, debit: 0, credit: 1000 }]
148 };
149 await assert.rejects(ledger.updateDraftJournal(draft.id, invalid, { post: true }), /تراز نیست/);
150 const original = await ledger.getJournal(draft.id);
151 assert.equal(original.status, 'draft');
152 assert.equal(original.date, '1405/07/18');
153 assert.equal(original.lines.length, 1);
154 await ledger.updateDraftJournal(draft.id, { ...invalid, lines: [
155 { accountId: cash.id, debit: 2000, credit: 0 },
156 { accountId: sales.id, debit: 0, credit: 2000 }
157 ] }, { post: true });
158 assert.equal((await ledger.getJournal(draft.id)).status, 'posted');
159 assert.equal((await ledger.getJournal(draft.id)).lines.length, 2);
160 await assert.rejects(ledger.updateDraftJournal(draft.id, invalid), /پیش‌نویس/);
161 assert.equal((await entries('journal_lines')).length, 2);
162 });
163
164 test('integration: reversal is immutable, balanced and cannot be repeated', async () => {
165 const { period, cash, sales } = await setup();
166 const original = await ledger.postJournal(balanced(period, cash, sales));
167 const reversed = await ledger.reverseJournal(original.id, { periodId: period.id, date: '1405/07/19' });
168 assert.equal(reversed.reversalOfId, original.id);
169 assert.equal((await ledger.getJournal(original.id)).reversedById, reversed.id);
170 const rows = (await ledger.getJournal(reversed.id)).lines;
171 assert.deepEqual(rows.map(r => [r.debit, r.credit]), [[0, 10000], [10000, 0]]);
172 assert.deepEqual((await ledger.trialBalance()).totals, { debit: 20000, credit: 20000 });
173 assert.equal((await ledger.trialBalance()).rows.every(r => r.balance === 0), true);
174 await assert.rejects(ledger.reverseJournal(original.id, { periodId: period.id, date: '1405/07/20' }), /قابل برگشت نیست/);
175 assert.equal((await entries('journal_entries')).length, 2);
176 });
177
178 test('integration: draft removal is atomic; posted journals are immutable', async () => {
179 const { period, cash, sales } = await setup();
180 const draft = await ledger.saveDraftJournal({
181 periodId: period.id, date: '1405/07/18',
182 lines: [{ accountId: cash.id, debit: 8000, credit: 0 }]
183 });
184 await ledger.discardDraftJournal(draft.id);
185 assert.equal((await entries('journal_entries')).length, 0);
186 assert.equal((await entries('journal_lines')).length, 0);
187 const posted = await ledger.postJournal(balanced(period, cash, sales));
188 await assert.rejects(ledger.discardDraftJournal(posted.id), /پیش‌نویس/);
189 assert.equal((await entries('journal_entries')).length, 1);
190 });
191
192 test('integration: reversal works when a previously posted account was deactivated', async () => {
193 const { period, cash, sales } = await setup();
194 const posted = await ledger.postJournal(balanced(period, cash, sales));
195 await StorageService.put('account_chart', { ...cash, active: false });
196 await assert.rejects(ledger.postJournal(balanced(period, cash, sales)), /غیرفعال/);
197 const reversed = await ledger.reverseJournal(posted.id, { periodId: period.id, date: '1405/07/20' });
198 assert.equal(reversed.status, 'posted');
199 assert.equal((await ledger.trialBalance()).rows.every(r => r.balance === 0), true);
200 });
201
202 test('integration: closing period prevents posting and reversing; company data cannot cross', async () => {
203 const { period, cash, sales } = await setup();
204 const j = await ledger.postJournal(balanced(period, cash, sales));
205 await ledger.closePeriod(period.id);
206 await assert.rejects(ledger.postJournal(balanced(period, cash, sales)), /بسته/);
207 await assert.rejects(ledger.reverseJournal(j.id, { periodId: period.id, date: '1405/07/19' }), /بسته/);
208 select('c2');
209 assert.equal((await ledger.listJournals()).length, 0);
210 assert.equal((await DataScope.list('journal_entries')).length, 0);
211 await assert.rejects(ledger.getJournal(j.id), /این شرکت/);
212 await assert.rejects(ledger.reverseJournal(j.id, { periodId: period.id, date: '1405/07/19' }), /قابل برگشت نیست/);
213 });
214
215 test('integration: Settings backup contains V2 ledger and restores it atomically', async () => {
216 const { period, cash, sales } = await setup();
217 await ledger.postJournal(balanced(period, cash, sales, 'restore-test'));
218 await StorageService.put('users', { id: 'some-user', username: 'demo', pwHash: 'test-hash', pwSalt: 'test-salt' });
219 await StorageService.put('account_chart', { id: 'foreign-account', companyId: 'c2', code: '1', name: 'Foreign assets', type: 'asset', level: 'group' });
220 const backup = await SettingsController.exportBackup();
221 assert.deepEqual(backup.data.users, [], 'company exports never include global user accounts');
222 assert.equal((await StorageService.get('users', 'some-user')).pwHash, 'test-hash');
223 assert.equal(backup.data.account_chart.length, 19);
224 assert.equal(backup.data.fiscal_periods.length, 1);
225 assert.equal(backup.data.journal_entries.length, 1);
226 assert.equal(backup.data.journal_lines.length, 2);
227 await reset();
228 const first = await SettingsController.importBackup(backup, { mode: 'merge' });
229 assert.ok(first.added >= 17);
230 assert.deepEqual((await ledger.trialBalance()).totals, { debit: 10000, credit: 10000 });
231 const again = await SettingsController.importBackup(backup, { mode: 'merge' });
232 assert.ok(again.skipped >= 17);
233 assert.equal((await ledger.listJournals()).length, 1);
234 });
235
236 test('integration: broken V2 restore rolls back all stores and rejects cross-company ID collisions', async () => {
237 const { period, cash, sales } = await setup();
238 await ledger.postJournal(balanced(period, cash, sales));
239 const backup = await SettingsController.exportBackup();
240 await reset();
241 const broken = structuredClone(backup);
242 broken.data.journal_lines[0].accountId = 'missing-account';
243 await assert.rejects(SettingsController.importBackup(broken), /حساب|ناموجود/);
244 assert.equal((await entries('account_chart')).length, 0);
245 assert.equal((await entries('journal_entries')).length, 0);
246 select('c2');
247 await StorageService.put('account_chart', { id: backup.data.account_chart[0].id,
248 companyId: 'c2', code: '1', name: 'Foreign', type: 'asset', level: 'group' });
249 select('c1');
250 await assert.rejects(SettingsController.importBackup(backup), /شرکت دیگر/);
251 assert.equal((await ledger.listAccounts()).length, 0);
252 assert.equal((await entries('journal_entries')).length, 0);
253 });
254
255 test('integration: backup export and restore preserves accounting records without user credentials', async () => {
256 const { period, cash, sales } = await setup();
257 await ledger.postJournal(balanced(period, cash, sales));
258 const snapshot = await StorageService.exportAll();
259 assert.equal(snapshot.data.journal_entries.length, 1);
260 assert.equal(snapshot.data.journal_lines.length, 2);
261 assert.equal(snapshot.data.account_chart.length, 19);
262 await StorageService.clearAll();
263 await StorageService.importAll(snapshot);
264 select('c1');
265 assert.equal((await ledger.getJournal(snapshot.data.journal_entries[0].id)).lines.length, 2);
266 assert.deepEqual((await ledger.trialBalance()).totals, { debit: 10000, credit: 10000 });
267 });
268
269 test('role security: normal user cannot alter chart, periods, manual journals or restore backup',async()=>{
270 const {period,cash,sales}=await setup();
271 const backup=await SettingsController.exportBackup();
272 Auth.currentUser={id:'limited-user',role:'user',username:'cashier',companyIds:['c1']};
273 await assert.rejects(ledger.addAccount({code:'900',name:'unauthorized',level:'group',type:'asset'}),/مدیر/);
274 await assert.rejects(ledger.createPeriod({name:'unauthorized',...year}),/مدیر/);
275 await assert.rejects(ledger.seedDefaultChart(),/مدیر/);
276 await assert.rejects(ledger.postJournal(balanced(period,cash,sales)),/مدیر/);
277 await assert.rejects(SettingsController.importBackup(backup),/مدیر/);
278 assert.equal((await ledger.listJournals()).length,0);
279 });