فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): seed legacy audit via authorized full backup restore
davoodmehraban89 committed
Oct 20, 2026 at 08:38 UTC
ac8cc4e3b748bdba731e4f95efba1ac53ab5e605
1 file changed
+6
-7
tests/a03-append-only-full-restore.test.mjs
+6
-7
@@ -2,14 +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 { AuditService } from '../src/core/AuditService.js';
5
+import { Auth } from '../src/core/Auth.js';
6
7
// 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));
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: full restore refuses to mutate prior audit events and rolls back earlier writes', async () => {
13
await StorageService.clearAll();
14
+ Auth.currentUser = { id: 'manager', role: 'admin', username: 'manager' };
15
const audit = {
16
id: 'audit-history-1', companyId: 'c1',
17
commandKey: 'c1:historic', eventType: 'journal_posted',
@@ -29,10 +31,7 @@ test('A03: full restore refuses to mutate prior audit events and rolls back earl
31
assert.deepEqual(await StorageService.get('audit_events', audit.id), before);
32
33
// Identical replay with shuffled object keys is safe and idempotent.
32
- const replay = { companyId: 'c1', id: before.id, result: before.result,
33
- safeSummary: { lineCount: 2 }, commandKey: before.commandKey,
34
- eventType: before.eventType, actorId: before.actorId, sourceId: before.sourceId,
35
- createdAt: before.createdAt, updatedAt: before.updatedAt };
34
+ const replay = Object.fromEntries(Object.entries(before).reverse());
35
await StorageService.importAll({
36
app: 'Factor-easyPro', version: 7, data: { audit_events: [replay] }
37
});