فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): restore old company audit fixtures through validated backup
davoodmehraban89 committed
Oct 20, 2026 at 08:38 UTC
3affe43ce91457e5f98bc3a6763cd1fa7529d0de
1 file changed
+5
-4
tests/a03-company-scope-immutable-stores.test.mjs
+5
-4
@@ -2,18 +2,18 @@ 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 { AuditService } from '../src/core/AuditService.js';
5
6
// Seed historical fixtures atomically; standalone history writes are forbidden.
8
-const seedHistory = (store, row) => StorageService.transaction(store, tx =>
9
- store === 'audit_events' ? AuditService.restoreHistorical(tx, row) : tx.put(store, row));
7
+const seedHistory = (store, row) => store === 'audit_events'
8
+ ? StorageService.importAll({ app: 'Factor-easyPro', version: 6, data: { audit_events: [row] } })
9
+ : StorageService.transaction(store, tx => tx.put(store, row));
10
import { DataScope } from '../src/core/DataScope.js';
11
import { Auth } from '../src/core/Auth.js';
12
import { CompanyService } from '../src/core/CompanyService.js';
13
14
test('A03: common scoped reads do not leak another company audit history or corrections', async () => {
15
await StorageService.clearAll();
16
- Auth.currentUser = { id: 'staff-one', username: 'one', role: 'user', companyIds: ['c1'] };
16
+ Auth.currentUser = { id: 'manager', username: 'manager', role: 'admin', companyIds: ['c1','c2'] };
17
await StorageService.put('companies', { id: 'c1', name: 'Company One' });
18
await StorageService.put('companies', { id: 'c2', name: 'Company Two' });
19
CompanyService.activeCompanyId = 'c1';
@@ -30,6 +30,7 @@ test('A03: common scoped reads do not leak another company audit history or corr
30
await seedHistory('document_corrections', {
31
id: 'cor-c2', companyId: 'c2', idempotencyKey: 'c2:cor'
32
});
33
+ Auth.currentUser = { id: 'staff-one', username: 'one', role: 'user', companyIds: ['c1'] };
34
assert.deepEqual((await DataScope.list('audit_events')).map(row => row.id), ['event-c1']);
35
assert.deepEqual((await DataScope.list('document_corrections')).map(row => row.id), ['cor-c1']);
36
assert.equal((await DataScope.stamp('audit_events', { eventType: 'journal_posted' })).companyId, 'c1');