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

test(A03): preserve positive history replay via authorized backup and block direct writes

davoodmehraban89 committed Oct 20, 2026 at 08:39 UTC c3a03dfbbb93efd775544ea5fcb8327646ad3e6a
1 file changed +8 -6
tests/a03-direct-append-only-protection.test.mjs
+8 -6
@@ -2,12 +2,16 @@ 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
7 // Seed historical fixtures atomically; standalone history writes are forbidden.
7 -const seedHistory = (store, row) => StorageService.transaction(store, tx => tx.put(store, row));
8 +const seedHistory = (store, row) => store === 'audit_events'
9 + ? StorageService.importAll({ app: 'Factor-easyPro', version: 6, data: { audit_events: [row] } })
10 + : StorageService.transaction(store, tx => tx.put(store, row));
11
12 test('A03: public and transaction writes cannot replace or delete persisted audit events', async () => {
13 await StorageService.clearAll();
14 + Auth.currentUser = { id: 'manager', role: 'admin', username: 'manager' };
15 const event = {
16 id: 'history-native-1', companyId: 'c1', commandKey: 'c1:posted-1',
17 eventType: 'journal_posted', actorId: 'manager', sourceId: 'j1'
@@ -29,11 +33,9 @@ test('A03: public and transaction writes cannot replace or delete persisted audi
33 }), /حذف مستقیم/);
34 assert.deepEqual(await StorageService.get('audit_events', event.id), original);
35 assert.equal((await StorageService.getAll('audit_events')).length, 1);
32 - await StorageService.transaction('audit_events', async tx => {
33 - await tx.putRaw('audit_events', {
34 - id: 'history-native-2', companyId: 'c1',
35 - commandKey: 'c1:posted-2', eventType: 'journal_posted'
36 - });
36 + await seedHistory('audit_events', {
37 + id: 'history-native-2', companyId: 'c1',
38 + commandKey: 'c1:posted-2', eventType: 'journal_posted'
39 });
40 assert.equal((await StorageService.getAll('audit_events')).length, 2);
41 });