فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): seed immutable fixtures transactionally in a03-direct-append-only-protection.test.mjs
davoodmehraban89 committed
Oct 19, 2026 at 11:29 UTC
3ebae1e7e56b9c23692793b4d91ba8a94fcaafca
1 file changed
+5
-2
tests/a03-direct-append-only-protection.test.mjs
+5
-2
@@ -3,13 +3,16 @@ import assert from 'node:assert/strict';
3
import 'fake-indexeddb/auto';
4
import { StorageService } from '../src/core/StorageService.js';
5
6
+// Seed historical fixtures atomically; standalone history writes are forbidden.
7
+const seedHistory = (store, row) => StorageService.transaction(store, tx => tx.put(store, row));
8
+
9
test('A03: public and transaction writes cannot replace or delete persisted audit events', async () => {
10
await StorageService.clearAll();
11
const event = {
12
id: 'history-native-1', companyId: 'c1', commandKey: 'c1:posted-1',
13
eventType: 'journal_posted', actorId: 'manager', sourceId: 'j1'
14
};
12
- await StorageService.put('audit_events', event);
15
+ await seedHistory('audit_events', event);
16
const original = structuredClone(await StorageService.get('audit_events', event.id));
17
await assert.rejects(StorageService.put('audit_events',
18
{ ...original, eventType: 'period_closed' }));
@@ -39,7 +42,7 @@ test('A03: document correction history refuses replay writes and deletion', asyn
42
await StorageService.clearAll();
43
const correction = { id: 'fix-1', companyId: 'c1',
44
idempotencyKey: 'c1:return-1', sourceId: 'invoice-1' };
42
- await StorageService.put('document_corrections', correction);
45
+ await seedHistory('document_corrections', correction);
46
const saved = structuredClone(await StorageService.get('document_corrections', correction.id));
47
await assert.rejects(StorageService.put('document_corrections',
48
{ ...saved, sourceId: 'tampered-invoice' }));